OSDN Git Service

utils/net.c: Fix for AI_ADDRCONFIG unsupported
authorShoichi Tamuki <tamuki@linet.gr.jp>
Wed, 21 May 2008 15:52:13 +0000 (15:52 +0000)
committerShoichi Tamuki <tamuki@linet.gr.jp>
Wed, 21 May 2008 15:52:13 +0000 (15:52 +0000)
ChangeLog
utils/net.c

index d297cca..4d98975 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2008-05-22  TAMUKI Shoichi <tamuki@linet.gr.jp>
+
+       * utils/net.c: Fix for AI_ADDRCONFIG unsupported
+
 2008-05-21  Yair K. <cesium2@gmail.com>
 
        * interface/server_c.c, libarc/url_ftp.c, libarc/url_http.c,
index 6ead354..0765cbb 100644 (file)
@@ -74,11 +74,23 @@ SOCKET open_socket(char *host, unsigned short port)
     memset(&hints, 0, sizeof(struct addrinfo));
     hints.ai_family = AF_UNSPEC;
     hints.ai_socktype = SOCK_STREAM;
+#ifdef AI_ADDRCONFIG
+    /* By default, only look up addresses using address types for
+     * which a local interface is configured (i.e. no IPv6 if no IPv6
+     * interfaces. */
     hints.ai_flags = AI_ADDRCONFIG;
+#endif
 
     snprintf(service, sizeof(service), "%d", port);
 
     s = getaddrinfo(host, service, &hints, &result);
+#ifdef AI_ADDRCONFIG
+    if (s == EAI_BADFLAGS) {
+        /* Retry with no flags if AI_ADDRCONFIG was rejected. */
+        hints.ai_flags = 0;
+        s = getaddrinfo(host, service, &hints, &result);
+    }
+#endif
 
     if (s)
         return (SOCKET)-1;