[TriLUG] multiple IP from the same network card?

Ken Mink kmtrilug at nc.rr.com
Wed Jun 18 16:49:30 EDT 2003


On Wed, 2003-06-18 at 16:07, Mike Johnson wrote:
> Chris Merrill [cmerrill at nc.rr.com] wrote:
>  
> > Are you sure?  In Java, for instance, you can "bind" a socket to the
> > IP address of your choice.  I assume this is supported on all platforms.
> 
> No, I'm not sure.  :)  Almost, though.  Like I said, I'm willing to be
> proven wrong.  However, what kind of socket are you binding?  A server,
> or client?  I can see that being supported for a server/listening
> socket, but seems kinda odd for a client.
> 
> Try it, and let us know.
> 
> Mike


I believe you can bind a client socket to a specific IP address using
the bind function, I assuming C here. I don't have any code laying
around to try it with, but I think these three steps work;

sock = socket(domain, type, protocol);
/* fill in my_addr struct with the ip address you want to use */
bind(sock, *my_addr, addrlen);
connect(sock, *serv_addr, addrlen);

Connect assigns the ip address and port if they have not been previously
specified. By calling bind before connect, you are specifying your ip
address and port. Be aware the port you select may already be in use, so
have appropriate error checking.

Ken
-- 
"They that can give up essential liberty to obtain a little temporary
safety deserve neither liberty nor safety."--Benjamin Franklin
" 'Necessity' is the plea for every infringement of human liberty; it
is the argument of tyrants; it is the creed of slaves."--William Pitt 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://www.trilug.org/pipermail/trilug/attachments/20030618/5df140b3/attachment.pgp>


More information about the TriLUG mailing list