sockaddr_in#

Dual-mode shortcut: with two arguments it behaves like pack_sockaddr_in; with one argument it behaves like unpack_sockaddr_in.

תקציר#

my $sin            = sockaddr_in($port, $packed_ipv4);
my ($port, $addr)  = sockaddr_in($sockaddr);

מה מוחזר#

The same values as the underlying pack_sockaddr_in or unpack_sockaddr_in, depending on argument count.

דוגמאות#

## Packing

connect($sock, sockaddr_in(80, inet_aton("127.0.0.1"))) or die $!;
## Unpacking

my ($port, $ip) = sockaddr_in(getpeername($sock));

מקרי קצה#

  • 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_in in new code; this name exists for compatibility with older Perl idioms.

הבדלים מן ה-upstream#

Fully compatible with upstream Socket.

ראו גם#

  • pack_sockaddr_in, unpack_sockaddr_in - the explicit forms.

  • sockaddr_in6 - IPv6 counterpart with the same dual behaviour.