Merge pull request #5248 from alexrp/profiler-api
[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 #ifndef HAVE_INET_PTON
20
21 int
22 inet_pton (int family, const char *address, void *inaddrp)
23 {
24         if (family == AF_INET) {
25 #ifdef HAVE_INET_ATON
26                 struct in_addr inaddr;
27                 
28                 if (!inet_aton (address, &inaddr))
29                         return 0;
30                 
31                 memcpy (inaddrp, &inaddr, sizeof (struct in_addr));
32                 return 1;
33 #else
34                 /* assume the system has inet_addr(), if it doesn't
35                    have that we're pretty much screwed... */
36                 guint32 inaddr;
37                 
38                 if (!strcmp (address, "255.255.255.255")) {
39                         /* special-case hack */
40                         inaddr = 0xffffffff;
41                 } else {
42                         inaddr = inet_addr (address);
43 #ifndef INADDR_NONE
44 #define INADDR_NONE ((in_addr_t) -1)
45 #endif
46                         if (inaddr == INADDR_NONE)
47                                 return 0;
48                 }
49                 
50                 memcpy (inaddrp, &inaddr, sizeof (guint32));
51                 return 1;
52 #endif /* HAVE_INET_ATON */
53         }
54         
55         return -1;
56 }
57
58 #else /* !HAVE_INET_PTON */
59
60 MONO_EMPTY_SOURCE_FILE (networking_missing);
61 #endif /* !HAVE_INET_PTON */