text
stringlengths
0
234
.pp
three types of address are distinguished in the
.i sockaddr_un
structure:
.ip * 3
.ir pathname :
a unix domain socket can be bound to a null-terminated
filesystem pathname using
.br bind (2).
when the address of a pathname socket is returned
(by one of the system calls noted above),
its length is
.ip
offsetof(struct sockaddr_un, sun_path) + strlen(sun_path) + 1
.ip
and
.i sun_path
contains the null-terminated pathname.
(on linux, the above
.br offsetof ()
expression equates to the same value as
.ir sizeof(sa_family_t) ,
but some other implementations include other fields before
.ir sun_path ,
so the
.br offsetof ()
expression more portably describes the size of the address structure.)
.ip
for further details of pathname sockets, see below.
.ip *
.ir unnamed :
a stream socket that has not been bound to a pathname using
.br bind (2)
has no name.
likewise, the two sockets created by
.br socketpair (2)
are unnamed.
when the address of an unnamed socket is returned,
its length is
.ir "sizeof(sa_family_t)" ,
and
.i sun_path
should not be inspected.
.\" there is quite some variation across implementations: freebsd
.\" says the length is 16 bytes, hp-ux 11 says it's zero bytes.
.ip *
.ir abstract :
an abstract socket address is distinguished (from a pathname socket)
by the fact that
.ir sun_path[0]
is a null byte (\(aq\e0\(aq).
the socket's address in this namespace is given by the additional
bytes in
.ir sun_path
that are covered by the specified length of the address structure.
(null bytes in the name have no special significance.)
the name has no connection with filesystem pathnames.
when the address of an abstract socket is returned,
the returned
.i addrlen
is greater than
.ir "sizeof(sa_family_t)"
(i.e., greater than 2), and the name of the socket is contained in
the first
.ir "(addrlen \- sizeof(sa_family_t))"
bytes of
.ir sun_path .
.ss pathname sockets
when binding a socket to a pathname, a few rules should be observed
for maximum portability and ease of coding:
.ip * 3
the pathname in
.i sun_path
should be null-terminated.
.ip *
the length of the pathname, including the terminating null byte,
should not exceed the size of
.ir sun_path .
.ip *
the
.i addrlen
argument that describes the enclosing
.i sockaddr_un
structure should have a value of at least:
.ip
.nf
offsetof(struct sockaddr_un, sun_path)+strlen(addr.sun_path)+1
.fi
.ip
or, more simply,
.i addrlen
can be specified as
.ir "sizeof(struct sockaddr_un)" .
.pp
there is some variation in how implementations handle unix domain
socket addresses that do not follow the above rules.
for example, some (but not all) implementations
.\" linux does this, including for the case where the supplied path
.\" is 108 bytes
append a null terminator if none is present in the supplied