```{index} single: sockaddr_family; Socket function ``` ```{index} single: Socket::sockaddr_family; Perl function ``` # sockaddr_family Read the address-family byte from any packed sockaddr without committing to one unpacking shape. ## Synopsis ```perl my $family = sockaddr_family($sockaddr); ``` ## What you get back An integer equal to one of `AF_INET`, `AF_INET6`, `AF_UNIX`, etc., or `undef` if the input is shorter than 2 bytes. ## Examples ```perl 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); ... } ``` ## Edge cases - The family byte is read in native byte order — this matches how every `pack_sockaddr_*` writes it. - Input shorter than 2 bytes returns `undef`. ## Differences from upstream Fully compatible with upstream Socket. ## See also - `unpack_sockaddr_in`, `unpack_sockaddr_in6`, `unpack_sockaddr_un` — the right unpacker depends on the family returned here.