unpack_sockaddr_in#
Split a packed sockaddr_in back into its port and 4-byte address.
Σύνοψη#
my ($port, $packed_ipv4) = unpack_sockaddr_in($sockaddr);
Τι επιστρέφεται#
A two-element list: the port as an integer, the address as a 4-byte packed string. Feed the second through inet_ntoa to see it as dotted-quad. When the input is shorter than a sockaddr_in, both elements come back as undef.
Παραδείγματα#
my $peer = getpeername($sock);
my ($port, $ip) = unpack_sockaddr_in($peer);
printf "connected from %s:%d\n", inet_ntoa($ip), $port;
Οριακές περιπτώσεις#
Input shorter than
sockaddr_inyields(undef, undef)rather than croaking - check the first return value before using it.The address family byte in the input is not validated; the caller is expected to have an IPv4 sockaddr in hand.
Διαφορές από το upstream#
Fully compatible with upstream Socket.
Δείτε επίσης#
pack_sockaddr_in- reverse direction.sockaddr_family- read just the family byte without unpacking.unpack_sockaddr_in6- IPv6 counterpart.inet_ntoa- turn the returned packed address into a string.