pack_sockaddr_un#

Build a packed sockaddr_un from a filesystem path, for use with Unix-domain sockets.

תקציר#

my $sun = pack_sockaddr_un($path);

מה מוחזר#

A fixed-size byte string matching the platform’s struct sockaddr_un, ready for bind or connect against an AF_UNIX / AF_LOCAL socket.

דוגמאות#

socket(my $sock, AF_UNIX, SOCK_STREAM, 0) or die $!;
connect($sock, pack_sockaddr_un("/tmp/app.sock")) or die $!;
## Abstract Linux namespace: first byte is NUL.

my $sun = pack_sockaddr_un("\0app.mysvc");

מקרי קצה#

  • Paths longer than 107 bytes are truncated to fit sun_path.

  • No explicit trailing NUL is appended by the caller; the struct is zero-initialised and the path is copied in.

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

Fully compatible with upstream Socket.

ראו גם#

  • unpack_sockaddr_un - reverse direction.

  • sockaddr_family - read the family byte from an unknown sockaddr.