Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

IPv6 Sockets

by nitin1704 (Sexton)
on Dec 10, 2012 at 03:40 UTC ( #1008024=perlquestion: print w/ replies, xml ) Need Help??
nitin1704 has asked for the wisdom of the Perl Monks concerning the following question:

I have two scripts for sending out UDP packets to IPv4 and IPv6 sockets, using IO::Socket::INET and INET6 respectively.

IPv4 Client

use IO::Socket; use Socket; my $sock = IO::Socket::INET->new( Proto => 'udp', ) or die "Could not create socket: $!\n"; my $pack = pack_sockaddr_in(23456, inet_aton('10.254.83.40')); IO::Socket::send($sock, "message", 0, $pack) or die "Can't send: $!\n" +; print $sock->sockhost(),"\n"; print $sock->sockport(),"\n"; print $sock->peerhost(),"\n"; print $sock->peerport(),"\n";

IPv6 Client

use IO::Socket::INET6; use Socket; use Socket6; my $sock = IO::Socket::INET6->new( Proto => 'udp', ) or die "Could not create socket: $!\n"; my $pack = pack_sockaddr_in6(23456, inet_pton(AF_INET6,'2000:1234:5678 +:9abc::eeff')); IO::Socket::send($sock, "message", 0, $pack) or die "Can't send: $!\n" +; print $sock->sockhost(),"\n"; print $sock->sockport(),"\n"; print $sock->peerhost(),"\n"; print $sock->peerport(),"\n";

IPv4 Output

0.0.0.0 32807 10.254.83.40 23456

IPv6 Output

:: -4622771466457284569 2000:1234:5678:9abc::eeff -4622771466457293920

Question

I can't figure out why INET6 sockets are printing such weird values for the port numbers, even though I'm using the same 23456 in both cases.

Comment on IPv6 Sockets
Select or Download Code
Re: IPv6 Sockets
by Anonymous Monk on Dec 10, 2012 at 04:25 UTC

    I can't figure out why INET6 sockets are printing such weird values for the port numbers, even though I'm using the same 23456 in both cases.

    Did you read the docs? Probably cause they're supposed to do that, cause they're documented to do that.

    :P If IO::Socket::INET6 isn't satisfying try reading RFC 3493 - Basic Socket Interface Extensions for IPv6

      I can't seem to find this particular issue documented in any of those pages. :/ In any case, is there any way I can get the actual port number?

        I can't seem to find this particular issue documented in any of those pages. :/ In any case, is there any way I can get the actual port number?

        Hmm, I don't know what I was looking at :/ ignore me

Re: IPv6 Sockets
by quester (Vicar) on Dec 10, 2012 at 08:06 UTC

    It works for me... my IPv6 output is:

    :: 49527 2000:1234:5678:9abc::eeff 23456

    You might want to check for an outdated module (or perl, or operating system). I'm using:

    perl 5.14.3 Fedora 17 Linux, kernel 3.6.9 IO::Socket::INET6 2.69 IO::Socket 1.32 Socket 2.001 Socket6 0.23
      I was trying it from a CentOS 5 VirtualBox VM. But then I tried from real Windows and Ubuntu machines and it worked just fine. Probably the VM has something to do with it?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1008024]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (17)
As of 2014-07-24 15:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (161 votes), past polls