On Tuesday 13 November 2007 20:00, Denys Vlasenko wrote:
> On Monday 12 November 2007 04:50, Russell Senior wrote:
> > I am subscribed to too many mailing lists already. I just want to
> > report a bug. Can you please forward this to the list and CC me on
> > replies? Thanks, I appreciate your understanding.
>
> It's actually pretty simple:
>
...
>
> We just use the first result from getaddrinfo(). We can walk down
> result->ai_next and examine alternative addresses. From practical
> point of view, it's of course possible to check whether there is
> a IPv4 address and return that, and otherwise return first one.
>
> However, it's arbitrary. Who says that IPv4 is "better" than IPv6?
> On the same grounds I may complain when a host have two different
> IP addresses (and getaddrinfo() returns both), but it so happens that
> first one turns out to be blocked whereas second works.
> But programs don't know that and they are using first one, and failing.
>
> What shall I do?
After some thinking it occurred to me that such hack can be
introduced, it only needs to be framed by #if <config option> / #endif
Please try attached patch - does it make you happier?
--
vda
diff -d -urpN busybox.0/libbb/xconnect.c busybox.1/libbb/xconnect.c
--- busybox.0/libbb/xconnect.c 2007-11-13 11:13:34.000000000 -0700
+++ busybox.1/libbb/xconnect.c 2007-11-14 03:03:46.000000000 -0700
@@ -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);
diff -d -urpN busybox.0/networking/Config.in busybox.1/networking/Config.in
--- busybox.0/networking/Config.in 2007-11-13 11:13:29.000000000 -0700
+++ busybox.1/networking/Config.in 2007-11-14 03:05:27.000000000 -0700
@@ -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
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox