From: "Michael T Kerrisk" <mtk-lists@gmx.net>
To: netdev@oss.sgi.com
Subject: SO_REUSEADDR behavior different from BSD
Date: Wed, 4 Aug 2004 16:25:27 +0200 (MEST) [thread overview]
Message-ID: <16224.1091629527@www2.gmx.net> (raw)
Gidday,
In the classical BSD sockets implementation, the
SO_REUSEADDR socket option serves two purposes:
(a) to permit a socket to be bound to a port that currently
has a bound endpoint in the TIME_WAIT state, and
(b) to allow a terminated server to be restarted (and once
again be bound to it's well-known port), even if there
is a child of the previous server still serving a
connection.
On Linux SO_REUSEADDR does serve this purpose. However,
other second scenario is mot permitted by SO_REUSEADDR.
To make it clear what I mean, Ill detail the scenario.
Suppose we have the following:
Server (host Y)
Create listening socket -- fd 4
bind() to INADDR_ANY:9999
listen()
accept()
Client (host X)
Create socket
connect() to Y:9999 <accept unblocks, fd 5 returned>
server forks --------+
\ <child>
server terminates closes fd 4
<keeps running, with
fd 5 holding the
connection to client>
At this point, netstat on host Y shows the tuple
[local=Y-IP-addr:9999, remote=X-IP-addr:ephem-port] ESTABLISHED
New Server started
Create listening socket -- fd 4
set SO_REUSEADDR to 1 for fd 4
bind() fd 4 to port INADDR_ANY:9999
WHAT HAPPENS?
On FreeBSD, the bind() succeeds, and then using "netstat an"
on host Y shows:
[local=Y-IP-addr:9999, remote=X-IP-addr:ephem-port] ESTABLISHED
and
[local=*:9999, remote=*.*] CLOSED
But on Linux (2.6), the bind() fails with EADDRINUSE.
Why does Linux behave differently in this scenario?
Cheers,
Michael
--
Michael Kerrisk
mtk-lists@gmx.net
NEU: WLAN-Router für 0,- EUR* - auch für DSL-Wechsler!
GMX DSL = supergünstig & kabellos http://www.gmx.net/de/go/dsl
next reply other threads:[~2004-08-04 14:25 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-08-04 14:25 Michael T Kerrisk [this message]
2004-08-05 14:14 ` SO_REUSEADDR behavior different from BSD bert hubert
2004-08-05 16:36 ` Michael T Kerrisk
2004-08-05 18:20 ` David Stevens
2004-08-05 18:34 ` YOSHIFUJI Hideaki / 吉藤英明
2004-08-08 2:25 ` Fernando Gont
2004-08-09 13:29 ` Michael T Kerrisk
-- strict thread matches above, loose matches on Subject: below --
2004-08-05 22:25 Michael T Kerrisk
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=16224.1091629527@www2.gmx.net \
--to=mtk-lists@gmx.net \
--cc=netdev@oss.sgi.com \
/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).