Introduce FEATURE_PREFER_IPV4_ADDRESS. If selected, we have:
authorDenis Vlasenko <vda.linux@googlemail.com>
Wed, 14 Nov 2007 10:18:33 +0000 (10:18 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Wed, 14 Nov 2007 10:18:33 +0000 (10:18 -0000)
function                                             old     new   delta
str2sockaddr                                         328     344     +16

libbb/xconnect.c
networking/Config.in

index cb5ac2c8ec00324c5a71f13fb80612e5bf673f15..91c12f4d3c009bfd173c22dedac4f162cd80d1ad 100644 (file)
@@ -125,6 +125,7 @@ USE_FEATURE_IPV6(sa_family_t af,)
        int rc;
        len_and_sockaddr *r = NULL;
        struct addrinfo *result = NULL;
+       struct addrinfo *used_res;
        const char *org_host = host; /* only for error msg */
        const char *cp;
        struct addrinfo hint;
@@ -169,9 +170,21 @@ USE_FEATURE_IPV6(sa_family_t af,)
                        xfunc_die();
                goto ret;
        }
-       r = xmalloc(offsetof(len_and_sockaddr, sa) + result->ai_addrlen);
-       r->len = result->ai_addrlen;
-       memcpy(&r->sa, result->ai_addr, result->ai_addrlen);
+       used_res = result;
+#if ENABLE_FEATURE_PREFER_IPV4_ADDRESS
+       while (1) {
+               if (used_res->ai_family == AF_INET)
+                       break;
+               used_res = used_res->ai_next;
+               if (!used_res) {
+                       used_res = result;
+                       break;
+               }
+       }
+#endif
+       r = xmalloc(offsetof(len_and_sockaddr, sa) + used_res->ai_addrlen);
+       r->len = used_res->ai_addrlen;
+       memcpy(&r->sa, used_res->ai_addr, used_res->ai_addrlen);
        set_nport(r, htons(port));
  ret:
        freeaddrinfo(result);
index b5b4597c41e58b7fa86a4ee89b057e14455f21ba..b50aacf9f9d41ae62914cf8d4000b825e316b00e 100644 (file)
@@ -12,6 +12,21 @@ config FEATURE_IPV6
          Enable IPv6 support in busybox.
          This adds IPv6 support in the networking applets.
 
+config FEATURE_PREFER_IPV4_ADDRESS
+       bool "Preferentially use IPv4 addresses from DNS queries"
+       default y
+       depends on FEATURE_IPV6
+       help
+         Use IPv4 address of network host if it has one.
+
+         If this option is off, the first returned address will be used.
+         This may cause problems when your DNS server is IPv6-capable and
+         is returning IPv6 host addresses too. If IPv6 address
+         precedes IPv4 one in DNS reply, busybox network applets
+         (e.g. wget) will use IPv6 address. On an IPv6-incapable host
+         or network applets will fail to connect to the host
+         using IPv6 address.
+
 config VERBOSE_RESOLUTION_ERRORS
        bool "Verbose resolution errors"
        default n