in reply to IO::Socket::INET's sockaddr() returns 16 byte instead of 4, Socket::inet_ntoa() complains
Depending on the version of Perl you're using, I believe Socket6 isn't required for IPv6 lookups, Socket itself handles both IPv4 and IPv6. You're correct in the comment that this is (most likely) an IPv6/IPv4 thing as IPv6 addresses are 16 bytes and I've seen this before myself.
In most operating systems, IPv6 is preferred over IPv4, so if you don't want that behavior, turn off IPv6 on the interface(s) that $addr returns values for.
Alternatively, use calls that can deal with IPv4/IPv6 address families:
gethostbyname -> getaddrinfo gethostbyaddr -> getnameinfo inet_aton -> inet_pton inet_ntoa -> inet_ntop
Your grabbing a substring is certainly *not* a way to get around this as you'll just be pulling the last 4 bytes of an IPv6 address - this is *not* equivalent to the IPv4 address (in most all cases unless specifically configured or using IPv4 compatible addressing).
|
|---|