[TriLUG] C & sockets programming question

Ben Pitzer bpitzer at gmail.com
Fri Jul 29 09:16:29 EDT 2005


Actually, if I remember my networking correctly, the socket is a layer
above the IP address, so it is, and by definition must be IP address
agnostic.  The IP address is just the packet's destination, but once
it gets there, the network stack hands it off to the correct socket
for handling.  Therefore, the network stack usually handles the
binding of the socket to every IP address on the host, from the
loopback on.

You might want to check the ISC BIND or DCHPd code to see how they do
interface binding, although I'm not sure if that's C.  You might be
better off binding to an IP rather than an interface, if that's
possible.

Regards,
Ben Pitzer


On 7/27/05, Wing D Lizard <wingedlizard at nc.rr.com> wrote:
> Rick DeNatale wrote:
> 
> >On 7/27/05, Michael Tharp <gxti at partiallystapled.com> wrote:
> >
> >
> >>You're entirely correct, but most hosts have one default route and one
> >>interface that that route can take, and in this case it's assumed that
> >>is the goal - to find which. If this were a multihomed router, routes
> >>change often and packets may not always go out the same interface.
> >>Here it is assumed that there are fixed, single routes out each
> >>interface and an additional default route which picks one and only one
> >>outbound interface.
> >>
> >
> >Right, but because of the general case, I don't think that the socket
> >has any idea of being tied to a particular interface, unless somehow
> >it got bound to a particular interface with setsockoptions() and that
> >generally doesn't happen.
> >
> But a socket is tied to an ip address, and each interface has it's own
> ip address.
> 
> 
> 
> --
> No virus found in this outgoing message.
> Checked by AVG Anti-Virus.
> Version: 7.0.338 / Virus Database: 267.9.5/58 - Release Date: 7/25/2005
> 
> --
> TriLUG mailing list        : http://www.trilug.org/mailman/listinfo/trilug
> TriLUG Organizational FAQ  : http://trilug.org/faq/
> TriLUG Member Services FAQ : http://members.trilug.org/services_faq/
> TriLUG PGP Keyring         : http://trilug.org/~chrish/trilug.asc
>



More information about the TriLUG mailing list