netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Hemminger <shemminger@linux-foundation.org>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: dean@arctic.org (dean gaudet), netdev@vger.kernel.org
Subject: Re: why would EPIPE cause socket port to change?
Date: Tue, 23 Jan 2007 12:26:52 -0800	[thread overview]
Message-ID: <20070123122652.484c05b3@freekitty> (raw)
In-Reply-To: <E1H9ES2-0006uJ-00@gondolin.me.apana.org.au>

On Tue, 23 Jan 2007 16:44:10 +1100
Herbert Xu <herbert@gondor.apana.org.au> wrote:

> dean gaudet <dean@arctic.org> wrote:
> > in the test program below the getsockname result on a TCP socket changes 
> > across a write which produces EPIPE... here's a fragment of the strace:
> > 
> > getsockname(3, {sa_family=AF_INET, sin_port=htons(37636), sin_addr=inet_addr("127.0.0.1")}, [17863593746633850896]) = 0
> > ...
> > write(3, "hi!\n", 4)                    = 4
> > write(3, "hi!\n", 4)                    = -1 EPIPE (Broken pipe)
> > --- SIGPIPE (Broken pipe) @ 0 (0) ---
> > getsockname(3, {sa_family=AF_INET, sin_port=htons(59882), sin_addr=inet_addr("127.0.0.1")}, [16927060683038654480]) = 0
> > 
> > why does the port# change?  this is on 2.6.19.1.
> 
> Prior to the last write, the socket entered the CLOSED state meaning
> that the old port is no longer allocated to it.  As a result, the
> last write operates on an unconnected socket which causes a new local
> port to be allocated as an autobind.  It then fails because the socket
> is still not connected.

Why does write cause an autobind? One would think that on a
SOCK_STREAM socket, the write should just fail with ENOTCONN


> 
> So any attempt to run getsockname after an error on the socket is
> simply buggy.
> 
> Cheers,


-- 
Stephen Hemminger <shemminger@linux-foundation.org>

  parent reply	other threads:[~2007-01-23 20:29 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 [this message]
2007-01-24  5:58     ` Herbert Xu
2007-01-24  6:30       ` David Miller

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=20070123122652.484c05b3@freekitty \
    --to=shemminger@linux-foundation.org \
    --cc=dean@arctic.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=netdev@vger.kernel.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).