in reply to IO::Socket::INET's sockaddr() returns 16 byte instead of 4, Socket::inet_ntoa() complains
The socket uses IPv6. I'm guessing you're using localhost and that Squeeze defines localhost as ::1. The dumb thing is that sockaddr doesn't tell you if what kind of address it's returning. The module, was written with only IPv4 in mind.
Here's how you can address this in a portable manner:
use Socket qw( sockaddr_family sockaddr_in sockaddr_in6 inet_ntop AF_I +NET ); my $sockaddr = getsockaddr($sock); # Or: $sock->sockname() my $fam = sockaddr_family($sockaddr); my $addr_n = $fam == AF_INET ? (sockaddr_in($sockaddr))[1] : (sockaddr_in6($sockaddr))[1]; my $addr_a = inet_ntop($fam, $addr_n); say $addr_a;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: IO::Socket::INET's sockaddr() returns 16 byte instead of 4, Socket::inet_ntoa() complains
by sedusedan (Pilgrim) on Jan 21, 2012 at 03:06 UTC | |
by Anonymous Monk on Feb 28, 2012 at 15:26 UTC | |
by sedusedan (Pilgrim) on Mar 06, 2012 at 02:08 UTC |