* connect() man page
@ 2020-02-12 17:50 Eric Dumazet
2020-04-06 11:47 ` Michael Kerrisk (man-pages)
0 siblings, 1 reply; 2+ messages in thread
From: Eric Dumazet @ 2020-02-12 17:50 UTC (permalink / raw)
To: Michael Kerrisk, netdev, linux-man
Hi Michael
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 ...
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).
Thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: connect() man page
2020-02-12 17:50 connect() man page Eric Dumazet
@ 2020-04-06 11:47 ` Michael Kerrisk (man-pages)
0 siblings, 0 replies; 2+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-04-06 11:47 UTC (permalink / raw)
To: Eric Dumazet, netdev, linux-man; +Cc: mtk.manpages
Hello Eric,
My apologies for the delayed reply.
On 2/12/20 6:50 PM, Eric Dumazet wrote:
> Hi Michael
>
> 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.
Thanks for the heads-up,
> 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.)
I like your proposed text, but would like to include more
information. How about this:
Some protocol sockets (e.g., UNIX domain stream sockets) may suc‐
cessfully connect() only once.
Some protocol sockets (e.g., datagram sockets in the UNIX and
Internet domains) may use connect() multiple times to change their
association.
Some protocol sockets (e.g., TCP sockets as well as datagram sock‐
ets in the UNIX and Internet domains) may dissolve the association
by connecting to an address with the sa_family member of sockaddr
set to AF_UNSPEC; thereafter, the socket can be connected to
another address. (AF_UNSPEC is supported on Linux since kernel
2.2.)
?
Thanks,
Michael
--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-04-06 11:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-12 17:50 connect() man page Eric Dumazet
2020-04-06 11:47 ` Michael Kerrisk (man-pages)
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.