View Full Version : Setting to Local IP
tal0n
05-12-2003, 03:19 AM
Ohh I am embarassed to ask this but say there is a specific IP address that I want my server to connect to how do I set it to that. I want to set it to 127.0.0.1 to test but I have never needed to set it to a specific IP because I have always used INADDR_ANY.
RobSeace
05-12-2003, 12:08 PM
You mean you want to bind() to a specific IP? Well, just fill in
that IP in the same place you normally fill in INADDR_ANY...
Eg: for 127.0.0.1, you can just do:
sa.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
Or, for other arbitrary addresses, you can use inet_pton() or
inet_aton() or inet_addr(), or etc. to convert the IP from string
format to raw format to use...
tal0n
05-12-2003, 09:06 PM
Thank you very much Rob. You are very helpful to me, thanks.
vBulletin® v3.7.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.