Contents
How is a Unix domain socket structure address is represented?
Address format A UNIX domain socket address is represented in the following structure: struct sockaddr_un { sa_family_t sun_family; /* AF_UNIX */ char sun_path[108]; /* Pathname */ }; The sun_family field always contains AF_UNIX. On Linux, sun_path is 108 bytes in size; see also NOTES, below.
What is abstract Unix domain socket?
The socket address is abstract when sun_path[0] is a null byte (‘\0’). The rest of sun_path is used to name the socket in the abstract namespace which is independent of the file system. This feature is only supported in Linux and it is not portable.
What are abstract sockets?
The abstract namespace socket allows the creation of a socket connection which does not require a path to be created. Abstract namespace sockets disappear as soon as all open instances of the socket are removed.
How do I use a domain socket in unix?
To create a UNIX domain socket, use the socket function and specify AF_UNIX as the domain for the socket. The z/TPF system supports a maximum number of 16,383 active UNIX domain sockets at any time. After a UNIX domain socket is created, you must bind the socket to a unique file path by using the bind function.
How are domain sockets represented in Unix file system?
UNIX domain sockets do not use port numbers to distinguish between multiple instances. Traditionally they use paths and are represented in the file system as socket Inodes. But there also exists a second variant, which is described in below.
When to use file descriptor in Unix socket?
So, if you want to communicate with the peer socket, you should use the file descriptor returned from accept (), not the file descriptor returned from the call to socket () in step #1. The latter socket remains open and is used to accept further connection requests.
How is an inode different from a socket in Linux?
The listed Inode in is different from the Inode in the file system: To handle sockets like files the Linux kernel implements a virtual file system called sockfs: For each opened socket it contains an Inode, which then the processes reference:
When to unlink the socket file in Unix?
Therefore many services unconditionally unlink the socket file before starting. If the old service is still running, its socket will no longer be reachable. Also be aware that close () ing the socket will not remove the socket path, so your daemon should unlink () it itself when shutting down.