Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / utils / networking-missing.c
1 /**
2  * \file
3  * Implements missing standard socket functions.
4  *
5  * Author:
6  *      Rodrigo Kumpera (kumpera@gmail.com)
7  *
8  * (C) 2015 Xamarin
9  */
10
11 #include <mono/utils/networking.h>
12 #include <mono/utils/mono-compiler.h>
13 #include <glib.h>
14
15 #ifdef HAVE_NETDB_H
16 #include <netdb.h>
17 #endif
18
19 //wasm does have inet_pton even though autoconf fails to find
20 #if !defined (HAVE_INET_PTON) && !defined (HOST_WASM)
21
22 int
23 inet_pton (int family, const char *address, void *inaddrp)
24 {
25         if (family == AF_INET) {
26 #ifdef HAVE_INET_ATON
27                 struct in_addr inaddr;
28                 
29                 if (!inet_aton (address, &inaddr))
30                         return 0;
31                 
32                 memcpy (inaddrp, &inaddr, sizeof (struct in_addr));
33                 return 1;
34 #else
35                 /* assume the system has inet_addr(), if it doesn't
36                    have that we're pretty much screwed... */
37                 guint32 inaddr;
38                 
39                 if (!strcmp (address, "255.255.255.255")) {
40                         /* special-case hack */
41                         inaddr = 0xffffffff;
42                 } else {
43                         inaddr = inet_addr (address);
44 #ifndef INADDR_NONE
45 #define INADDR_NONE ((in_addr_t) -1)
46 #endif
47                         if (inaddr == INADDR_NONE)
48                                 return 0;
49                 }
50                 
51                 memcpy (inaddrp, &inaddr, sizeof (guint32));
52                 return 1;
53 #endif /* HAVE_INET_ATON */
54         }
55         
56         return -1;
57 }
58
59 #else /* !HAVE_INET_PTON */
60
61 MONO_EMPTY_SOURCE_FILE (networking_missing);
62 #endif /* !HAVE_INET_PTON */