unpack_sockaddr_un#

Extract the filesystem path from a packed sockaddr_un.

Synopsis#

my ($path) = unpack_sockaddr_un($sockaddr);

What you get back#

The sun_path field as a string, trimmed at the first NUL byte.

Examples#

my ($path) = unpack_sockaddr_un(getsockname($sock));
print "listening on $path\n";

Edge cases#

  • An abstract Linux-namespace name (leading NUL) comes back whole, NULs included: its length is the structure’s length less the family field.

  • A structure shorter than struct sockaddr_un is accepted, as the kernel returns from accept, recvfrom, getpeername and getsockname.

  • undef croaks “Undefined address for Socket::unpack_sockaddr_un”; a family other than AF_UNIX croaks “Bad address family”.

See also#

  • pack_sockaddr_un - reverse direction.