[erlang-questions] unix domain sockets with abstract namespace: can't use all 108 bytes

Raimo Niskanen raimo+erlang-questions@REDACTED
Wed Apr 26 10:55:58 CEST 2017

On Wed, Apr 26, 2017 at 03:52:52PM +1200, Richard A. O'Keefe wrote:
> > On 26/04/2017, at 2:14 AM, Raimo Niskanen <raimo+erlang-questions@REDACTED> wrote:
> > 
> > Well, it is just because on all other Unix-like OS:es the address is
> > (loosly/de-facto) defined to be zero terminated, and there are macros to
> > calculate the address structure size that use strlen on the string.
> It's not *that* loose.  POSIX explicitly defines sun_path to hold a "pathname"
> and a path name is defined as a character string and those are defined to be
> NUL terminated.  (See <sys/un.h> and then check definitions for "path name"
> and "string".)

Ok.  That is not as loose as I thought.

I can not find (in Posix) any clue to which address_len you shall use with
a sockaddr_un structure.  Is it the size of the whole structure, or is it
the size of the structure ending with the terminating 0 in the path?
There is an example:
    http://pubs.opengroup.org/onlinepubs/9699919799/ ->
       bind - bind a name to a socket
that uses the size of the structure, ignoring the path length in .sun_path.
That would speak for that the Linux use is creative but not violating Posix
since the path is 0 terminated and the address size is large enough.
They just encode an address after the empty path...  But Posix also states
that bind() shall fail with [ENOENT] if the pathname is an empty string. :-)

And e.g FreeBSD unix(4) tells you to use the macro SUN_LEN() that uses
strlen(.sun_path) to calculate the address size.  But it seems Posix does
not define this macro.

So it seems it is not a violation of Posix to use a su->sun_path that starts
with a 0 combined with an address_len of sizeof(*su).  Or maybe even between
SUN_LEN(su) and sizeof(*su)?  Or?

> > 
> > Therefore the Linux way to use the address type contradicts the BSD:s and I
> > guess Solaris.
> And POSIX.  And HP-UX and AIX, as far as I can tell, and to the degree that
> anyone cares.

I am sorry, since I am not a native english speaker; what does "and to the
degree that anyone cares" mean in this context?


/ Raimo Niskanen, Erlang/OTP, Ericsson AB

More information about the erlang-questions mailing list