sockaddr_in#
Dual-mode shortcut: with two arguments it behaves like pack_sockaddr_in; with one argument it behaves like unpack_sockaddr_in.
Synopsis#
my $sin = sockaddr_in($port, $packed_ipv4);
my ($port, $addr) = sockaddr_in($sockaddr);
What you get back#
The same values as the underlying pack_sockaddr_in or
unpack_sockaddr_in, depending on argument count.
Examples#
## Packing
connect($sock, sockaddr_in(80, inet_aton("127.0.0.1"))) or die $!;
## Unpacking
my ($port, $ip) = sockaddr_in(getpeername($sock));
Edge cases#
The dispatch is on argument count, not argument type. Calling with a single two-element list-in-scalar oddity will still take the unpack branch.
Prefer the explicit
pack_sockaddr_in/unpack_sockaddr_inin new code; this name exists for compatibility with older Perl idioms.
Differences from upstream#
Fully compatible with upstream Socket.
See also#
pack_sockaddr_in,unpack_sockaddr_in— the explicit forms.sockaddr_in6— IPv6 counterpart with the same dual behaviour.