unpack_sockaddr_in6#

Split a packed sockaddr_in6 into port, 16-byte address, scope id, and flow-info.

Synopsis#

my ($port, $addr, $scope_id, $flowinfo) = unpack_sockaddr_in6($sockaddr);

What you get back#

A four-element list. When the input is shorter than a sockaddr_in6, all four elements come back as undef.

Examples#

my ($port, $addr, $scope, $flow) = unpack_sockaddr_in6(getpeername($sock));
printf "[%s%%%d]:%d\n", inet_ntop(AF_INET6, $addr), $scope, $port;

Edge cases#

  • Scope id and flow-info are often 0 for non-link-local traffic.

  • Input shorter than sockaddr_in6 yields four undefs.

  • The family byte is not validated — pass an IPv6 sockaddr.

Differences from upstream#

Fully compatible with upstream Socket.

See also#

  • pack_sockaddr_in6 — reverse direction.

  • unpack_sockaddr_in — IPv4 counterpart.

  • inet_ntop — turn the returned packed address into a string.