Hi,

Right now wget code looks like this:

#ifdef ENABLE_IPV6
int     ip_default_family = AF_INET6;
#else
int     ip_default_family = AF_INET;
#endif

and then
./connect.c:  sock = socket (ip_default_family, SOCK_STREAM, 0);


This assumes that binary compiled with ipv6 support is always used on IPv6 
capable host which is not true in many, many cases. Such binary on ipv4 only 
host will cause:

[EMAIL PROTECTED] src]$ LC_ALL=C ./wget wp.pl
--21:48:37--  http://wp.pl/
           => `index.html'
Resolving wp.pl... 212.77.100.101
Connecting to wp.pl[212.77.100.101]:80... failed: Address family not supported 
by protocol.
Retrying.

--21:48:38--  http://wp.pl/
  (try: 2) => `index.html'
Connecting to wp.pl[212.77.100.101]:80... failed: Address family not supported 
by protocol.
Retrying.

--21:48:40--  http://wp.pl/
  (try: 3) => `index.html'
Connecting to wp.pl[212.77.100.101]:80... failed: Address family not supported 
by protocol.
Retrying.


Applications that use getaddrinfo() shouldn't even bother to know which family 
they use. Just should do

getaddrinfo("host", ..., &res0);
for (res = res0; res; res=res->ai_next) {
  s = socket(res->ai_family, res->ai_socktype, res->ai_protocol)
  if (s<0)
    continue
  if ((connect(s, res->ai_addr, res->ai_addrlen) <0 ) {
     close(s)
     continue)
  }
  break
}

This pseudo-code should show the idea. 


The best thing IMO is to use getaddrinfo for resolving + struct addrinfo 
(linked list) for storing data about host.x.y.com. For systems without 
getaddrinfo ipv4 only replacements should be provided - see openssh portable 
how it's done there.

The whole idea of getaddrinfo/getnameinfo is to get family independent 
functions. They even work for AF_UNIX on some systems (like on linux+glibc).

Anyway for now workaround is something like this in main():

#ifdef ENABLE_IPV6
s = socket(AF_INET6, SOCK_STREAM, 0);
if (s < 0 && (errno == EAFNOSUPPORT))
   ip_default_family = AF_INET;
close(s);
#endif

-- 
Arkadiusz Miśkiewicz    CS at FoE, Wroclaw University of Technology
arekm.pld-linux.org AM2-6BONE, 1024/3DB19BBD, arekm(at)ircnet, PLD/Linux

Reply via email to