From: Michael Tokarev <mjt@tls.msk.ru>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: dean gaudet <dean@arctic.org>, netdev@vger.kernel.org
Subject: Re: why would EPIPE cause socket port to change?
Date: Tue, 23 Jan 2007 14:10:39 +0300 [thread overview]
Message-ID: <45B5ED2F.7020303@tls.msk.ru> (raw)
In-Reply-To: <E1H9ES2-0006uJ-00@gondolin.me.apana.org.au>
Herbert Xu 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.
Well, but why getsockname() didn't just return ENOTCONN?
> So any attempt to run getsockname after an error on the socket is
> simply buggy.
Yes it is. But so is not returning ENOTCONN from getsockname(). I think.
/mjt
next prev parent reply other threads:[~2007-01-23 11:10 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 [this message]
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
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=45B5ED2F.7020303@tls.msk.ru \
--to=mjt@tls.msk.ru \
--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).