pack_sockaddr_in6#
Build a packed sockaddr_in6 from a port, a 16-byte IPv6 address, and optional scope and flow-info fields.
Synopsis#
my $sin6 = pack_sockaddr_in6($port, $packed_ipv6);
my $sin6 = pack_sockaddr_in6($port, $packed_ipv6, $scope_id, $flowinfo);
What you get back#
A fixed-size byte string matching the platform’s struct sockaddr_in6, ready for bind or connect.
Examples#
my $addr = inet_pton(AF_INET6, "::1");
my $sin6 = pack_sockaddr_in6(443, $addr);
connect($sock, $sin6) or die $!;
## Link-local address with scope index for eth0.
my $scope = scalar getsockopt(...); # or from if_nametoindex
my $sin6 = pack_sockaddr_in6(5353, inet_pton(AF_INET6, "fe80::1"), $scope);
Edge cases#
$scope_idand$flowinfodefault to 0 when omitted.An address argument shorter than 16 bytes leaves the address field zeroed (i.e.
::).Port and flow-info are truncated to 16 and 32 bits respectively.
Differences from upstream#
Fully compatible with upstream Socket.
See also#
unpack_sockaddr_in6— reverse direction.sockaddr_in6— dual-mode shortcut that dispatches on arg count.pack_sockaddr_in— IPv4 counterpart.inet_pton— usual source of the address argument.