Re: bind() not working for outbound socket connections...
Re: bind() not working for outbound socket connections...
- Subject: Re: bind() not working for outbound socket connections...
- From: Justin Walker <email@hidden>
- Date: Sat, 21 May 2005 18:54:03 -0700
On May 21, 2005, at 18:28, Philip George wrote:
why is bind() not letting me specify a particular interface (on a
multihomed system) to send socket messages thru?
Because that is not bind()'s job. bind() does one thing: it tells the
kernel to assign a network address, which you provide, to a local
endpoint, specified by the value that you get from a socket() call.
The network address consists, for PF_INET, an IPv4 address and a port;
you can specify either, both, or neither, in your call. If you specify
neither, your endpoint will be assigned a port number by the kernel.
If you do not specify an address, it will be effectively set to
INADDR_ANY (i.e., "*").
If you specify an address, that address will be used for outbound
packets; if you do not, the kernel will pick one based on the
destination address. If you chose an address that does not "go towards
the Internet", and you don't have routing enabled, then your packet
won't go anywhere.
This is as close as you can get to binding to an interface: you can
choose an address that is associated to the interface you are
interested in.
i have a system with two ports, one is connected to a router that CAN
see the internet and and one is connected to a router that CANNOT see
the internet.
if i try to bind() a socket to the port that connects to the "dead"
router, the system still autoroutes it through the good interface to
get the message to the web server out on the internet. for most
practical purposes, that feature rocks, but for my particular needs, i
have to be sure that the messages are being routed out through a
specific interface. if there is no good route to the destination
address thru the chosen interface, then the subsequent connect()
should fail (as opposed to looking for another route).
i **don't** want these particular messages autorouted thru any random
interface.
You really do need to read enough to understand IP routing. You can
complain all you want, but the kernel routing engine is still going to
pick an outbound interface that takes your packets in the direction of
the destination address. The interfaces aren't chosen randomly; they
are chosen in a deterministic way by the routing engine.
Regards,
Justin
--
Justin C. Walker, Curmudgeon-At-Large
Institute for General Semantics
--------
"Weaseling out of things is what separates us from the animals.
Well, except the weasel."
- Homer J Simpson
--------
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden