Addressing within the AF_UNIX Domain

A socket address in the AF_UNIX address family is defined by the sockaddr_un structure, which is defined in the sys/un.h header file:
struct sockaddr_un  {
    unsigned char sun_len;       /* length of sockaddr struct */
    unsigned char sun_family;    /* addressing family */
             char sun_path[108]; /* file name */
};

When the application provides a sockaddr_un structure to the sockets library, the sun_len field should be set to either 0 or a value greater than or equal to SUN_LEN(&sa), where sa is the name of the sockaddr_un variable, but less than or equal to sizeof(struct sockaddr_un). The SUN_LEN() macro, which is defined in sys/un.h, evaluates to an expression which returns the total length of the used portion of the sockaddr_un structure, when sun_path has been filled in with a null-terminated file name. The length returned by SUN_LEN() does not include the terminating null character. If a 0 is specified for sun_len, the sockaddr length provided on the specific socket function call determines how long the path name is. If sun_len is nonzero, the lesser of sun_len and the provided length is used. In either case, if a null character appears in the string before the given length, the path name is considered to end there. When the sockets library provides a sockaddr_un structure to the application, the sun_len field is set to SUN_LEN(&sa)+1, where sa is the name of the sockaddr_un variable. This length thus includes the null byte which terminates the file name.

The sun_family field is set to AF_UNIX.

The sun_path field contains the name of the file which represents the open socket. It need not be null delimited, although it is recommended that it is, so that the SUN_LEN() macro can be used. A file by this name will be created in the Byte File System by the bind() function call, and must exist there for the connect() function call to succeed. Because the Byte File System contains the file, the form of the path name should follow the POSIX conventions. Generally, an absolute path name (one that begins with a slash) should be specified, so that the client and the server can both use the same path name to identify the file. If an AF_UNIX socket is not yet bound when a client calls the connect() function, it will be bound to the null path name string (for example, the string ""). In this case, no file is created in the Byte File System.

For more information about the Byte File System, see the z/VM: OpenExtensions User's Guide.