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