* (C) 2015 Xamarin
*/
-#include <mono/utils/networking.h>
+#include <config.h>
#include <glib.h>
#ifdef HAVE_NETDB_H
#include <ifaddrs.h>
#endif
+#include <mono/utils/networking.h>
+#include <mono/utils/mono-threads-coop.h>
+
static void*
get_address_from_sockaddr (struct sockaddr *sa)
{
struct addrinfo hints, *res = NULL, *info;
MonoAddressEntry *cur = NULL, *prev = NULL;
MonoAddressInfo *addr_info;
+ int ret;
memset (&hints, 0, sizeof (struct addrinfo));
*result = NULL;
hints.ai_flags = AI_ADDRCONFIG;
#endif
sprintf (service_name, "%d", port);
- if (getaddrinfo (hostname, service_name, &hints, &info))
+
+ MONO_ENTER_GC_SAFE;
+ ret = getaddrinfo (hostname, service_name, &hints, &info);
+ MONO_EXIT_GC_SAFE;
+
+ if (ret)
return 1; /* FIXME propagate the error */
res = info;
while (res) {
cur = g_new0 (MonoAddressEntry, 1);
- if (prev)
- prev->next = cur;
- else
- addr_info->entries = cur;
-
cur->family = res->ai_family;
cur->socktype = res->ai_socktype;
cur->protocol = res->ai_protocol;
cur->address_len = sizeof (struct in6_addr);
cur->address.v6 = ((struct sockaddr_in6*)res->ai_addr)->sin6_addr;
} else {
- g_error ("Cannot handle address family %d", cur->family);
+ g_warning ("Cannot handle address family %d", cur->family);
+ res = res->ai_next;
+ g_free (cur);
+ continue;
}
if (res->ai_canonname)
cur->canonical_name = g_strdup (res->ai_canonname);
+ if (prev)
+ prev->next = cur;
+ else
+ addr_info->entries = cur;
+
prev = cur;
res = res->ai_next;
}
memset (&ifc, 0, sizeof (ifc));
ifc.ifc_len = IFCONF_BUFF_SIZE;
- ifc.ifc_buf = g_malloc (IFCONF_BUFF_SIZE); /* We can't have such huge buffers on the stack. */
+ ifc.ifc_buf = (char *)g_malloc (IFCONF_BUFF_SIZE); /* We can't have such huge buffers on the stack. */
if (ioctl (fd, SIOCGIFCONF, &ifc) < 0)
goto done;
++if_count;
}
- result_ptr = result = g_malloc (if_count * mono_address_size_for_family (family));
+ result = (char *)g_malloc (if_count * mono_address_size_for_family (family));
+ result_ptr = (char *)result;
FOREACH_IFR (ifr, ifc) {
if (ifr->ifr_name [0] == '\0')
continue;
}
#endif
+
+#ifndef _WIN32
+// These are already defined in networking-windows.c for Windows
+void
+mono_networking_init (void)
+{
+ //nothing really
+}
+
+void
+mono_networking_shutdown (void)
+{
+ //nothing really
+}
+#endif