Abstract Domain Socket
lastmod 2022-03-03created 2022-03-032 edits
How to use/check
It means that when you use a unix domain socket, you don't have to use an actual file path. In this case, it is treated simply as a name rather than a file... (abstract domain socket) When you open the /proc/net/unix file or look with the netstat command, an @ is prepended to the file name to tell them apart.
To use it, put '\0' in the first byte of sun_path in the sockaddr_un struct, and then write the file path after it.
struct sockaddr_un serveraddr;
bzero(&serveraddr, sizeof(serveraddr));
serveraddr.sun_family = AF_UNIX;
serveraddr.sun_path[0] = '\0';
strcpy(&serveraddr.sun_path[1], "/path/to/non-exist");
ret = bind(sockfd, (struct sockaddr *)&serveraddr, sizeof(serveraddr));
...
With the following command,
it is shown as follows:
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
unix 2 [ ] DGRAM 189653 3374/a.out @/path/to/non-exist
See the abstract part of the Address Format section in the man page of unix(7). (man -7 unix)
See also
- Unix Domain Socket (UDS)
- gRPC - supported via the
unix-abstract:scheme.