diff options
| author | Michael Kerrisk <mtk.manpages@gmail.com> | 2020-04-06 13:43:00 +0200 |
|---|---|---|
| committer | Michael Kerrisk <mtk.manpages@gmail.com> | 2020-04-06 13:43:00 +0200 |
| commit | f4ba6a215f6d147f9733722d53dbf735b51d4e81 (patch) | |
| tree | 13b83667dbbd0a4b5829d51c0e1de0c577bd3504 /man2/connect.2 | |
| parent | ed6fe0056d9e5253e880ab24e2a31737eade35a7 (diff) | |
| download | man-pages-f4ba6a215f6d147f9733722d53dbf735b51d4e81.tar.gz | |
connect.2: Update the details on AF_UNSPEC
Update the details on AF_UNSPEC and circumstances in which
socket can be reconnected.
From a mail conversation with Eric Dumazet:
> connect() man page seems obsolete or confusing :
>
> Generally, connection-based protocol sockets may successfully
> connect() only once; connectionless protocol sockets may use
> connect() multiple times to change their association.
> Connectionless sockets may dissolve the association by connecting to
> an address with the sa_family member of sockaddr set to AF_UNSPEC
> (supported on Linux since kernel 2.2).>
>
> 1) At least TCP has supported AF_UNSPEC thing forever.
> 2) By definition connectionless sockets do not have an association,
> why would they call connect(AF_UNSPEC) to remove a connection
> which does not exist ...
Calling connect() on a connectionless socket serves two purposes:
a) Assigns a default outgoing address for datagrams (sent using write(2)).
b) Causes datagrams sent from sources other than the peer address to be
discarded.
Both of these things are true in AF_UNIX and the Internet domains.
Using connect(AF_UNSPEC) allows the local datagram socket to clear
this association (without having to connect() to a *different*
peer), so that now it can send datagrams to any peer and receive
datagrams for any peer, (I've just retested all of this.)
>
> Maybe we should rewrite this paragraph to match reality, since
> this causes confusion.
>
>
> Some protocol sockets may successfully connect() only once.
> Some protocol sockets may use connect() multiple times to change
> their association.
> Some protocol sockets may dissolve the association by connecting to
> an address with the sa_family member of sockaddr set to AF_UNSPEC
> (supported on Linux since kernel 2.2).
When I first saw your note, I was afraid that I had written
the offending text. But, I see it has been there since the
manual page was first added in 1992 (other than the piece
"(supported since on Linux since kernel 2.2)", which I added in
2007). Perhaps it was true in 1992.
Anyway, I confirm your statement about TCP sockets. The
connect(AF_UNSPEC) thing works; thereafter, the socket may be
connected to another socket.
Interestingly, connect(AF_UNSPEC) does not seem to work for
UNIX domain stream sockets. (My light testing gives an EINVAL
error on connect(AF_UNSPEC) of an already connected UNIX stream
socket. I could not easily spot where this error was being
generated in the kernel though.)
Reported-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
Diffstat (limited to 'man2/connect.2')
| -rw-r--r-- | man2/connect.2 | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/man2/connect.2 b/man2/connect.2 index 679b0fec50..168526d1ec 100644 --- a/man2/connect.2 +++ b/man2/connect.2 @@ -111,19 +111,29 @@ this call attempts to make a connection to the socket that is bound to the address specified by .IR addr . .PP -Generally, connection-based protocol sockets may successfully +Some protocol sockets (e.g., UNIX domain stream sockets) +may successfully .BR connect () -only once; connectionless protocol sockets may use +only once. +.PP +Some protocol sockets +(e.g., datagram sockets in the UNIX and Internet domains) +may use .BR connect () multiple times to change their association. -Connectionless sockets may -dissolve the association by connecting to an address with the +.PP +Some protocol sockets +(e.g., TCP sockets as well as datagram sockets in the UNIX and +Internet domains) +may dissolve the association by connecting to an address with the .I sa_family member of .I sockaddr set to -.BR AF_UNSPEC -(supported on Linux since kernel 2.2). +.BR AF_UNSPEC; +thereafter, the socket can be connected to another address. +.RB ( AF_UNSPEC +is supported on Linux since kernel 2.2.) .SH RETURN VALUE If the connection or binding succeeds, zero is returned. On error, \-1 is returned, and |
