sockaddr_family#
Read the address-family byte from any packed sockaddr without committing to one unpacking shape.
תקציר#
my $family = sockaddr_family($sockaddr);
מה מוחזר#
An integer equal to one of AF_INET, AF_INET6, AF_UNIX, etc., or undef if the input is shorter than 2 bytes.
דוגמאות#
my $sa = getpeername($sock);
if (sockaddr_family($sa) == AF_INET6) {
my ($port, $addr) = unpack_sockaddr_in6($sa);
...
} else {
my ($port, $addr) = unpack_sockaddr_in($sa);
...
}
מקרי קצה#
The family byte is read in native byte order - this matches how every
pack_sockaddr_*writes it.Input shorter than 2 bytes returns
undef.
הבדלים מן ה-upstream#
Fully compatible with upstream Socket.
ראו גם#
unpack_sockaddr_in,unpack_sockaddr_in6,unpack_sockaddr_unthe right unpacker depends on the family returned here.