Re: Source IP / INADDR_ANY
- From: Tauno Voipio <tauno.voipio@xxxxxxxxxxxxx>
- Date: Tue, 06 Mar 2007 16:47:28 GMT
André Hänsel wrote:
Hi,
I'm wondering which IP address is used as the source IP of a TCP
connection.
I came across this issue when I was debugging problems with a box with
several IP aliases that could not connect to another box where it is
identified by its IP. (mysql_connect)
To connect libmysql.c calls socket() and then connect(), without any
bind() inbetween.
In ip(7) I found:
"When listen(2) or connect(2) are called on an unbound socket, it is
automatically bound to a random free port with the local address set
to INADDR_ANY."
So what does this INADDR_ANY mean? I guess, when there are multiple
interfaces but they point to different routes, the one which points to
my destination address is selected. (I did not verify this behaviour
yet.)
But what if there are just a few IP aliases that point all to the same
net. Googling for INADDR_ANY gave me (although unproven):
"When sending, a socket bound with INADDR_ANY binds to the default IP
address, which is that of the lowest-numbered interface."
However this is not the behaviour I see on my box, unless the
"interface numbering" is secretly rotated. ;)
The operating system will find a free port and use it.
The IP used is the IP address associated with the interface
which handles the connection.
So, the local in a multi-homed host depends on the target
address and the routing tables.
--
Tauno Voipio
tauno voipio (at) iki fi
.
- Follow-Ups:
- Re: Source IP / INADDR_ANY
- From: André Hänsel
- Re: Source IP / INADDR_ANY
- References:
- Source IP / INADDR_ANY
- From: André Hänsel
- Source IP / INADDR_ANY
- Prev by Date: Nistnet 2.012c on Fedora Core 4
- Next by Date: Re: Source IP / INADDR_ANY
- Previous by thread: Source IP / INADDR_ANY
- Next by thread: Re: Source IP / INADDR_ANY
- Index(es):
Relevant Pages
|