Say i have a system with more than one IP.. multiple ethernet card, dial up etc etc.. Now how do I make a POSIX socket connect through a particular IP...
thanx for any answer...
Say i have a system with more than one IP.. multiple ethernet card, dial up etc etc.. Now how do I make a POSIX socket connect through a particular IP...
thanx for any answer...
I suspect that you bind() to the appropriate IP address before calling connect(). Use a port number of zero to specify that the provider should provide the port number.
If you just need to get the source ip address that has been used with an unbound socket you can call getsocketname() after the connect() call.
Yeah but if you have a client program, and you didn't use bind(), it still works with multiple interfaces!
That's because when you don't bind to an interface, the OS is the one to make the decision, using your computer's routing table.
Infact i don't think you should ever attempt to bind the program to any interface, allow the OS to make the best decision.
Remember that you don't really need bind() when you're writing a client, and when you're writing a server i suggest you use INADDR_ANY as your local address.
Last edited by Devil Panther; 08-22-2004 at 01:31 PM.
"I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe
http://www.Bloodware.net - Developing free software for the community.
I agree but the problem is that I will be having arounf 200 instance of the client running on a machine.. so i thought it was better to load balance between the 2 nw interface I have... will the OS automatically balance it on the two cards if it sees that both of them have access to the server???
load sharing?
your computer has more than one interface, and they both go the same network? are you sure about that?
well... i guess you can connect both interfaces of the same computer to the same switch, but you'll need to define lag on that switch (by that the switch is the one to load balance the incomming data to your computer).
but i know not all switches support this option, especially not the small 8 port type; but the bigger ones that support vlans and other advance settings. So check the load sharing thing, because i'm not sure about it.
if it's not load sharing and you have more than one interface, this means that each interface should be connected to a different network (not the same broadcast domain - each of the interfaces has it's own default gateway).
here the computer makes the decision according to it's routing table to find the right path to the requested host.
but you must understand something: your computer is not a router (unless you set it up to be one) so it doesn't really know the right path, so you might have problems with it more than one interface, when your computer makes the wrong decision, because there is no way for it to know the best router, simple because it's not a router!
Last edited by Devil Panther; 08-24-2004 at 10:34 AM.
"I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe
http://www.Bloodware.net - Developing free software for the community.