From 156a0e0d7e874a835f27d1a6b5946a5544af7582 Mon Sep 17 00:00:00 2001 From: Michael Kerrisk Date: Sun, 10 Oct 2010 06:59:41 +0200 Subject: [PATCH] unix.7: Fix description of abstract socket names As reported by Lennart Poettering: The part about "abstract" sockets is misleading as it suggests that the sockaddr returned by getsockname() would necessarily have the size of sizeof(struct sockaddr), which however is not the case: getsockname() returns exactly the sockaddr size that was passed in on bind(). In particular, two sockets that are bound to the same sockaddr but different sizes are completely independent. See https://bugzilla.kernel.org/show_bug.cgi?id=19812 Reported-by: Lennart Poettering Signed-off-by: Michael Kerrisk --- man7/unix.7 | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/man7/unix.7 b/man7/unix.7 index 5bb8fe624..4a1b46a8f 100644 --- a/man7/unix.7 +++ b/man7/unix.7 @@ -12,7 +12,7 @@ .\" address that can appear in the sockaddr_un structure: pathname, .\" unnamed, and abstract. .\" -.TH UNIX 7 2010-09-10 "Linux" "Linux Programmer's Manual" +.TH UNIX 7 2010-10-10 "Linux" "Linux Programmer's Manual" .SH NAME unix, AF_UNIX, AF_LOCAL \- Sockets for local interprocess communication @@ -109,24 +109,26 @@ should not be inspected. an abstract socket address is distinguished by the fact that .IR sun_path[0] is a null byte ('\\0'). -All of the remaining bytes in -.I sun_path -define the "name" of the socket. +The socket's address in this namespace is given by the additional +bytes in +.IR sun_path +that are covered by the specified length of the address structure. (Null bytes in the name have no special significance.) The name has no connection with file system pathnames. -The socket's address in this namespace is given by the rest of the -bytes in -.IR sun_path . When the address of an abstract socket is returned by .BR getsockname (2), .BR getpeername (2), and .BR accept (2), -its length is -.IR "sizeof(struct sockaddr_un)" , -and -.I sun_path -contains the abstract name. +the returned +.I addrlen +is greater than +.IR "sizeof(sa_family_t)" +(i.e., greater than 2), and the name of the socket is contained in +the first +.IR "(addrlen \- sizeof(sa_family_t))" +bytes of +.IR sun_path . The abstract socket namespace is a nonportable Linux extension. .SS Socket Options For historical reasons these socket options are specified with a