--- wdblib.pl-20071007 2007-10-07 23:53:51.000000000 +0900 +++ wdblib.pl 2008-05-11 08:45:11.000000000 +0900 @@ -142,6 +142,8 @@ require 'jcode.pl'; require 'wdb.ph'; +use Socket; +use Socket6; # &Initialize(); # $a = "2000/01/02 03:04:05"; @@ -3486,6 +3488,7 @@ local( $readlines ) = 0; local( $readbufsize ) = 1024*4; local($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst); + local( @res, $family, $saddr, $canonname ); print DEBUGOUT "DownloadHTTP():\n" if ($DEBUG); @@ -3539,25 +3542,26 @@ $gettime = time; - if ( $server =~ /^(\d{1,3})[.](\d{1,3})[.](\d{1,3})[.](\d{1,3})$/ ) { - $thataddr = pack( 'C4', $1, $2, $3, $4 ); - } else { - ( $name, $aliases, $type, $len, $thataddr ) = gethostbyname( $server ); - } - - $that = pack( $SOCKADDR, $AF_INET, $port, $thataddr ); - ( $name, $aliases, $proto ) = getprotobyname( 'tcp' ); - eval { $SIG{'ALRM'} = 'timeout'; sub timeout { die "timeout"; } eval { alarm( $HTTP_TIMEOUT_G ); }; - if ( !socket( S, $AF_INET, $SOCK_STREAM, $proto ) ) { - die "socket error"; + @res = getaddrinfo( $server, $port, AF_UNSPEC, SOCK_STREAM ); + $family = -1; + while (scalar (@res) >= 5) { + ( $family, $SOCK_STREAM, $proto, $saddr, $canonname, @res ) = @res; + ( $host, $port ) = getnameinfo( $saddr, NI_NUMERICHOST | NI_NUMERICSERV ); + print DEBUGOUT "Trying to connect $host port $port...\n" if ($DEBUG); + socket( S, $family, $SOCK_STREAM, $proto ) || next; + connect (S, $saddr) && last; + close( S ); + $family = -1; } - if ( !connect( S, $that ) ) { + if ($family != -1) { + print DEBUGOUT "connected to $host port $port\n" if ($DEBUG); + } else { die "connect error"; }