netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Miller <davem@davemloft.net>
To: herbert@gondor.apana.org.au
Cc: shemminger@linux-foundation.org, dean@arctic.org, netdev@vger.kernel.org
Subject: Re: why would EPIPE cause socket port to change?
Date: Tue, 23 Jan 2007 22:30:23 -0800 (PST)	[thread overview]
Message-ID: <20070123.223023.45743778.davem@davemloft.net> (raw)
In-Reply-To: <20070124055833.GA17989@gondor.apana.org.au>

From: Herbert Xu <herbert@gondor.apana.org.au>
Date: Wed, 24 Jan 2007 16:58:33 +1100

> On Tue, Jan 23, 2007 at 12:26:52PM -0800, Stephen Hemminger wrote:
> > 
> > Why does write cause an autobind? One would think that on a
> > SOCK_STREAM socket, the write should just fail with ENOTCONN
> 
> The autobind is occuring in generic code, i.e., inet_sendmsg().
> It will subsequently fail because the socket is not connected.

This is one of those situations where the -ENOTCONN might be
preferable, but we are not helping application writers one
iota because the bazillion existing kernels running out there
have the old behavior so app writers have to code for it
anyways.

So I think we should just leave things as they are.

If you read the language Richard Stevens uses when describing
both the usage and implementation of getsockname and
getpeername in BSD, he makes it very clear exactly what these
two interfaces are intended to be used for.

They are to be invoked in situations where the application
has no reason to know what the socket is bound to locally
or remotely, and there are two real cases:

1) determining the result of an auto-bind
2) finding the remote address/port of a socket obtained
   via a fork/exec

I'm sure there are some other minimally different variants,
but those are the two main cases.

This makes it doubly clear that uses such as the one in libnss-ldap
were totally unintended, and should be avoided since every single
OS behaves differently in this case. :-)

      reply	other threads:[~2007-01-24  6:30 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-23  4:01 why would EPIPE cause socket port to change? dean gaudet
2007-01-23  5:44 ` Herbert Xu
2007-01-23 11:10   ` Michael Tokarev
2007-01-23 11:12     ` Herbert Xu
2007-01-23 11:15       ` Michael Tokarev
2007-01-23 11:18         ` Herbert Xu
2007-01-23 18:22   ` Rick Jones
2007-01-23 20:11     ` dean gaudet
2007-01-24  5:11       ` David Miller
2007-01-24  6:09         ` dean gaudet
2007-01-23 20:26   ` Stephen Hemminger
2007-01-24  5:58     ` Herbert Xu
2007-01-24  6:30       ` David Miller [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070123.223023.45743778.davem@davemloft.net \
    --to=davem@davemloft.net \
    --cc=dean@arctic.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=netdev@vger.kernel.org \
    --cc=shemminger@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).