On Wed, 2003-06-18 at 16:07, Mike Johnson wrote:
> Chris Merrill [EMAIL PROTECTED] 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 


Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to