2 * networking-fallbacks.c: Fallback networking code that rely on old BSD apis or whatever else is available.
5 * Rodrigo Kumpera (kumpera@gmail.com)
10 #include <mono/utils/networking.h>
17 #if !defined (HAVE_GETADDRINFO)
19 #if defined (HAVE_GETHOSTBYNAME) || defined (HAVE_GETHOSTBYNAME2)
22 add_hostent (MonoAddressInfo
*info
, int flags
, struct hostent
*h
)
24 MonoAddressEntry
*cur
, *prev
= info
->entries
;
31 info
->aliases
= g_strdupv (h
->h_aliases
);
33 while (h
->h_addr_list
[idx
]) {
34 cur
= g_new0 (MonoAddressEntry
, 1);
40 if (flags
& MONO_HINT_CANONICAL_NAME
&& h
->h_name
)
41 cur
->canonical_name
= g_strdup (h
->h_name
);
43 cur
->family
= h
->h_addrtype
;
44 cur
->socktype
= SOCK_STREAM
;
45 cur
->protocol
= 0; /* Zero means the default stream protocol */
46 cur
->address_len
= h
->h_length
;
47 memcpy (&cur
->address
, h
->h_addr_list
[idx
], h
->h_length
);
55 mono_get_address_info (const char *hostname
, int port
, int flags
, MonoAddressInfo
**result
)
57 MonoAddressInfo
*addr_info
;
58 addr_info
= g_new0 (MonoAddressInfo
, 1);
60 #ifdef HAVE_GETHOSTBYNAME2
61 if (flags
& MONO_HINT_IPV6
|| flags
& MONO_HINT_UNSPECIFIED
)
62 add_hostent (addr_info
, flags
, gethostbyname2 (hostname
, AF_INET6
));
63 if (flags
& MONO_HINT_IPV4
|| flags
& MONO_HINT_UNSPECIFIED
)
64 add_hostent (addr_info
, flags
, gethostbyname2 (hostname
, AF_INET
));
66 add_hostent (addr_info
, flags
, gethostbyname (hostname
))
69 if (!addr_info
->entries
) {
71 mono_free_address_info (addr_info
);
79 #endif /* defined (HAVE_GETHOSTBYNAME) || defined (HAVE_GETHOSTBYNAME2) */
81 #endif /* !defined (HAVE_GETADDRINFO) */