9

Operating systems limit the length of a path of a Unix domain socket. How can I check whether a particular path is within that limit?

Or, to put it another way, how can I check the maximum permitted length of a path of a Unix domain socket, on a Linux or Mac OS X system?

My use case here is for SSH multiplexing: if the ControlPath is too long, then SSH multiplexing won't work since it creates a unix domain sockets. I want to be able to check for a valid control path without having to actually start an ssh session and look for the error message.

8

how can I check the maximum permitted length of a path of a Unix domain socket, on a Linux

On Linux, this length is usually defined as 108.

It is defined by the UNIX_PATH_MAX variable in the /usr/include/linux/un.h header file :

cat /usr/include/linux/un.h | grep "define UNIX_PATH_MAX"

#define UNIX_PATH_MAX   108

You could find further info here :

  • Is there a reason why Unix socket path addresses are more limited than than PATH_MAX? – CMCDragonkai Oct 30 '16 at 12:36
6

On Mac OS X, According to the unix man page:

UNIX-domain addresses are variable-length filesystem pathnames of at most
104 characters.  The include file <sys/un.h> defines this address:

       struct sockaddr_un {
               u_char  sun_len;
               u_char  sun_family;
               char    sun_path[104];
       };

Here's a program that compiles on both Linux and OS X that will output the maximum length of the path of a unix domain socket.

#include <sys/un.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
    struct sockaddr_un s;
    printf("%lu\n", sizeof(s.sun_path));
    return 0;
}

On Linux, it outputs 108, and on OS X, it outputs 104.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.