Skip Menu |

This queue is for tickets about the IO-Socket-IP CPAN distribution.

Report information
The Basics
Id: 78525
Status: resolved
Priority: 0/
Queue: IO-Socket-IP

People
Owner: Nobody in particular
Requestors: AVKHOZOV [...] cpan.org
Cc: avkhozov [...] gmail.com
AdminCc:

Bug Information
Severity: Important
Broken in: 0.16
Fixed in: 0.17



CC: avkhozov [...] gmail.com
Hello! I'm trying to create a listen socket for ipv6 with IO::Socket::IP in the following way: and@google:~$ cat t.pl #!/usr/bin/perl use IO::Socket::IP; IO::Socket::IP->new( Family => AF_INET6, LocalHost => '::1', LocalService => '12345', Listen => 1, ) or die "Cannot create socket - $@\n"; But I get the following error: and@google:~$ perl t.pl Cannot create socket - Name or service not known and@google:~$ I have been investigated this problem and found the source of a problem in getaddrinfo function in glibc. It returns an error if flag AI_ADDRCONFIG is set. I use the following test: and@google:~$ cat 1.pl #!/usr/bin/perl -w use Socket; my ($err, @res) = Socket::getaddrinfo('::1', '12345', { family => AF_INET6, protocol => Socket::IPPROTO_TCP, socktype => SOCK_STREAM, flags => Socket::AI_ADDRCONFIG() }); warn $err if ($err); and@google:~$ perl 1.pl Name or service not known at 1.pl line 11. and@google:~$ If remove this flags, that is all work fine. Some info about my library versions: and@google:~$ perl -MSocket -le 'print $Socket::VERSION' 2.002 and@google:~$ perl -MIO::Socket::IP -le 'print $IO::Socket::IP::VERSION' 0.16 and@google:~$ perl -v This is perl 5, version 12, subversion 4 (v5.12.4) built for x86_64-linux-gnu-thread-multi (with 45 registered patches, see perl -V for more detail) ... and@google:~$ apt-cache show libc6 | egrep -i "^(version|provides)" Version: 2.13-20ubuntu5 Provides: glibc-2.13-1 Version: 2.13-20ubuntu5.1 Provides: glibc-2.13-1 and@google:~$ uname -a Linux google 3.0.0-23-generic #38-Ubuntu SMP Fri Jul 6 14:43:30 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux and@google:~$ May be do not use AI_ADDRCONFIG as a default flag while create a socket? ($hints{flags} = ( $arg->{GetAddrInfoFlags} || 0 ) | $AI_ADDRCONFIG;) Very uncomfortable use PeerAddrInfo in new method.
On Mon Jul 23 03:53:57 2012, AVKHOZOV wrote: Show quoted text
> I have been investigated this problem and found the source of a > problem in getaddrinfo function in glibc. It returns an error if flag > AI_ADDRCONFIG is set. I use the following test: > > > and@google:~$ cat 1.pl > #!/usr/bin/perl -w > > use Socket; > > my ($err, @res) = Socket::getaddrinfo('::1', '12345', { > family => AF_INET6, > protocol => Socket::IPPROTO_TCP, > socktype => SOCK_STREAM, > flags => Socket::AI_ADDRCONFIG() > }); > warn $err if ($err); > and@google:~$ perl 1.pl > Name or service not known at 1.pl line 11.
I'm afraid I'm not able to reproduce it from here: $ cat 1.pl #!/usr/bin/perl -w use Socket; my ($err, @res) = Socket::getaddrinfo('::1', '12345', { family => AF_INET6, protocol => Socket::IPPROTO_TCP, socktype => SOCK_STREAM, flags => Socket::AI_ADDRCONFIG() }); warn $err if ($err); use Data::Dump 'pp'; print '@res=', pp(@res), "\n"; $ perl 1.pl @res={ addr => pack("H*","0a003039000000000000000000000000000000000000000100000000"), canonname => undef, family => 10, protocol => 6, socktype => 1, } Show quoted text
> and@google:~$ perl -MSocket -le 'print $Socket::VERSION' > 2.002
2.002 Show quoted text
> and@google:~$ perl -v > > This is perl 5, version 12, subversion 4 (v5.12.4) built for x86_64- > linux-gnu-thread-multi > (with 45 registered patches, see perl -V for more detail) > ...
$ perl -v This is perl 5, version 14, subversion 2 (v5.14.2) built for x86_64- linux-gnu-thread-multi (with 61 registered patches, see perl -V for more detail) ... Show quoted text
> and@google:~$ apt-cache show libc6 | egrep -i "^(version|provides)" > Version: 2.13-20ubuntu5 > Provides: glibc-2.13-1 > Version: 2.13-20ubuntu5.1 > Provides: glibc-2.13-1
Ah; apt-cache only shows what is available, not what's installed. But for me this is: $ dpkg -l libc6 ... ii libc6:amd64 2.13-33 Embedded GNU C Library: Shared libraries I wonder though, what your IPv4 and IPv6 address lists look like. I have: $ ip -4 addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN inet 127.0.0.1/8 scope host lo 2: wired: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc pfifo_fast state UP qlen 1000 inet 192.168.42.2/24 brd 192.168.42.255 scope global wired inet 81.187.167.226/28 scope global wired inet 81.187.167.235/32 scope global wired inet 225.0.0.1/24 scope global wired $ ip -6 addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: wired: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qlen 1000 inet6 2001:8b0:3f7::2/112 scope global valid_lft forever preferred_lft forever inet6 fe80::52e5:49ff:fe55:a368/64 scope link valid_lft forever preferred_lft forever Show quoted text
> May be do not use AI_ADDRCONFIG as a default flag while create a > socket? ($hints{flags} = ( $arg->{GetAddrInfoFlags} || 0 ) | > $AI_ADDRCONFIG;)
Ahyes, perhaps that's a point - only add the flag if none supplied; but don't add it to the flags already given. I'll do that. -- Paul Evans
On Mon Jul 23 03:53:57 2012, AVKHOZOV wrote: Show quoted text
> May be do not use AI_ADDRCONFIG as a default flag while create a > socket? ($hints{flags} = ( $arg->{GetAddrInfoFlags} || 0 ) | > $AI_ADDRCONFIG;)
See attached patch. If you pass GetAddrInfoFlags => 0 explicitly, it won't set the AI_ADDRCONFIG flag any more. -- Paul Evans
Subject: rt78525.patch
=== modified file 'lib/IO/Socket/IP.pm' --- lib/IO/Socket/IP.pm 2012-06-24 14:03:53 +0000 +++ lib/IO/Socket/IP.pm 2012-07-23 18:29:42 +0000 @@ -235,10 +235,12 @@ =item GetAddrInfoFlags => INT -More flags to pass to the C<getaddrinfo()> function. These flags will be -combined with C<AI_ADDRCONFIG>, and if the C<Listen> argument is given, -C<AI_PASSIVE>. For more information see the documentation about -C<getaddrinfo()> in the L<Socket> module. +More flags to pass to the C<getaddrinfo()> function. If not supplied, a +default of C<AI_ADDRCONFIG> will be used. + +These flags will be combined with C<AI_PASSIVE> if the C<Listen> argument is +given. For more information see the documentation about C<getaddrinfo()> in +the L<Socket> module. =item Listen => INT @@ -371,7 +373,12 @@ my @localinfos; my @peerinfos; - $hints{flags} = ( $arg->{GetAddrInfoFlags} || 0 ) | $AI_ADDRCONFIG; + if( defined $arg->{GetAddrInfoFlags} ) { + $hints{flags} = $arg->{GetAddrInfoFlags}; + } + else { + $hints{flags} = $AI_ADDRCONFIG; + } if( defined( my $family = $arg->{Family} ) ) { $hints{family} = $family; === modified file 't/17gai-flags.t' --- t/17gai-flags.t 2012-06-20 12:15:02 +0000 +++ t/17gai-flags.t 2012-07-23 18:29:42 +0000 @@ -55,7 +55,7 @@ is_deeply( \@gai_args, [ - [ undef, "80", { flags => AI_PASSIVE|AI_NUMERICSERV|$AI_ADDRCONFIG, socktype => SOCK_STREAM, protocol => IPPROTO_TCP } ], + [ undef, "80", { flags => AI_PASSIVE|AI_NUMERICSERV, socktype => SOCK_STREAM, protocol => IPPROTO_TCP } ], ], '@gai_args for LocalPort => "80", GetAddrInfoFlags => AI_NUMERICSERV' ); }
RT-Send-CC: avkhozov [...] gmail.com
On Mon Jul 23 14:30:43 2012, PEVANS wrote: Show quoted text
> > See attached patch. > > If you pass > > GetAddrInfoFlags => 0 > > explicitly, it won't set the AI_ADDRCONFIG flag any more.
Yes, all work fine with this patch. Thanks! I will be wait for new release of IO::Socket::IP. I continued to investigate the problem with next example: $ cat 1.c #include <sys/types.h> #include <sys/socket.h> #include <stdio.h> #include <string.h> #include <netdb.h> int main() { struct addrinfo hints; struct addrinfo *res; memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = PF_INET6; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_ADDRCONFIG; hints.ai_protocol = 6; int ret = getaddrinfo("::1", "12345", &hints, &res); if (ret != 0) { fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(ret)); } return 0; } $ and get the following results: 1) Ubutntu 12.04 $ dpkg -l libc6 | grep ii ii libc6 2.15-0ubuntu10 Embedded GNU C Library: Shared libraries $ uname -a Linux x200 3.2.0-26-generic #41-Ubuntu SMP Thu Jun 14 17:49:24 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux $ gcc -o 1 1.c && ./1 getaddrinfo: Name or service not known $ ip -6 addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 inet6 ::1/128 scope host valid_lft forever preferred_lft forever 3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qlen 1000 inet6 fe80::216:ebff:fe15:6d52/64 scope link tentative dadfailed valid_lft forever preferred_lft forever $ 2) Ubuntu 11.10 $ dpkg -l libc6 | grep ii ii libc6 2.13-20ubuntu5.1 Embedded GNU C Library: Shared libraries $ uname -a Linux google 3.0.0-23-generic #38-Ubuntu SMP Fri Jul 6 14:43:30 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux $ gcc -o 1 1.c && ./1 getaddrinfo: Name or service not known $ ip -6 addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436      inet6 ::1/128 scope host         valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qlen 1000     inet6 fe80::e269:95ff:fe99:a961/64 scope link         valid_lft forever preferred_lft forever $  3) Debian 6.0.5 # dpkg -l libc6 | grep ii ii libc6 2.11.3-3 Embedded GNU C Library: Shared libraries # uname -a Linux debian 2.6.32-5-amd64 #1 SMP Sun May 6 04:00:17 UTC 2012 x86_64 GNU/Linux # gcc -o 1 1.c && ./1 # ip -6 addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qlen 1000 inet6 fe80::a00:27ff:feed:fc2e/64 scope link valid_lft forever preferred_lft forever # Found that the problem was not up to version glibc 2.11.3-3 and appeared after version 2.13-20.
Subject: 1.c
#include <sys/types.h> #include <sys/socket.h> #include <stdio.h> #include <string.h> #include <netdb.h> int main() { struct addrinfo hints; struct addrinfo *res; memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = PF_INET6; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_ADDRCONFIG; hints.ai_protocol = 6; int ret = getaddrinfo("::1", "12345", &hints, &res); if (ret != 0) { fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(ret)); } return 0; }
This was released in 0.17 but I forgot to update the ticket. -- Paul Evans