- fix cli arg parse
[oweals/gnunet.git] / src / util / gnunet-service-resolver.c
index c8d51077047ff5abedc9284606d71dabb6ab9f0a..0392e0bf1c4b3c0f61e98f62c72b07ee7d1730b1 100644 (file)
@@ -274,13 +274,24 @@ getaddrinfo_resolve (struct GNUNET_SERVER_TransmitContext *tc,
   struct addrinfo *result;
   struct addrinfo *pos;
 
+#ifdef WINDOWS
+  /* Due to a bug, getaddrinfo will not return a mix of different families */
+  if (AF_UNSPEC == af)
+  {
+    int ret1;
+    int ret2;
+    ret1 = getaddrinfo_resolve (tc, hostname, AF_INET);
+    ret2 = getaddrinfo_resolve (tc, hostname, AF_INET6);
+    if ((ret1 == GNUNET_OK) || (ret2 == GNUNET_OK))
+      return GNUNET_OK;
+    if ((ret1 == GNUNET_SYSERR) || (ret2 == GNUNET_SYSERR))
+      return GNUNET_SYSERR;
+    return GNUNET_NO;
+  }
+#endif
+
   memset (&hints, 0, sizeof (struct addrinfo));
-// FIXME in PlibC
-#ifndef MINGW
   hints.ai_family = af;
-#else
-  hints.ai_family = AF_INET;
-#endif
   hints.ai_socktype = SOCK_STREAM;      /* go for TCP */
 
   if (0 != (s = getaddrinfo (hostname, NULL, &hints, &result)))
@@ -291,10 +302,9 @@ getaddrinfo_resolve (struct GNUNET_SERVER_TransmitContext *tc,
                  AF_INET) ? "IPv4" : ((af == AF_INET6) ? "IPv6" : "any"),
                 gai_strerror (s));
     if ((s == EAI_BADFLAGS) || (s == EAI_MEMORY)
-#ifndef MINGW
+#ifndef WINDOWS
         || (s == EAI_SYSTEM)
 #else
-        // FIXME NILS
         || 1
 #endif
         )
@@ -303,8 +313,7 @@ getaddrinfo_resolve (struct GNUNET_SERVER_TransmitContext *tc,
   }
   if (result == NULL)
     return GNUNET_SYSERR;
-  pos = result;
-  while (pos != NULL)
+  for (pos = result; pos != NULL; pos = pos->ai_next)
   {
     switch (pos->ai_family)
     {
@@ -324,7 +333,6 @@ getaddrinfo_resolve (struct GNUNET_SERVER_TransmitContext *tc,
       /* unsupported, skip */
       break;
     }
-    pos = pos->ai_next;
   }
   freeaddrinfo (result);
   return GNUNET_OK;
@@ -341,6 +349,11 @@ gethostbyname2_resolve (struct GNUNET_SERVER_TransmitContext *tc,
   int ret1;
   int ret2;
 
+#ifdef WINDOWS
+  /* gethostbyname2() in plibc is a compat dummy that calls gethostbyname(). */
+  return GNUNET_NO;
+#endif
+
   if (af == AF_UNSPEC)
   {
     ret1 = gethostbyname2_resolve (tc, hostname, AF_INET);