inet_ntop#
Turn a packed IPv4 or IPv6 address back into its printable string form, selected by the first argument.
Synopsis#
my $s = inet_ntop(AF_INET, $packed4);
my $s = inet_ntop(AF_INET6, $packed6);
What you get back#
A dotted-quad string for AF_INET, a canonical colon-hex string
(with :: compression) for AF_INET6, or undef if the input
is too short or the family is unsupported.
Examples#
print inet_ntop(AF_INET6, IN6ADDR_LOOPBACK); # ::1
my ($port, $addr, $scope, $flow) = unpack_sockaddr_in6($peer);
printf "[%s]:%d\n", inet_ntop(AF_INET6, $addr), $port;
Edge cases#
Input shorter than the family’s address length returns
undef.Any family other than
AF_INETorAF_INET6returnsundef.
Differences from upstream#
Fully compatible with upstream Socket.
See also#
inet_pton— reverse direction, string to packed bytes.inet_ntoa— IPv4-only shortcut with no family argument.