[SDL] SDLNet_resolveHost

Tyler Montbriand tsm at accesscomm.ca
Sun Sep 18 09:25:06 PDT 2005


On September 18, 2005 04:58 am, santi wrote:
> Hi,
>
> I'm trying to obtain the IP of my local machine using SDL_net. If I
> haven't misunderstood the SDL_net manual, using:
>
> IPaddress ip;
> if (SDLNet_ResolveHost(&ip,0,network_port)!=0) {
>     printf("Error\n");
> } // if
>
> should fill the "ip" variable with the IP of my machine. But this just
> returns 0.0.0.0, Have I misunderstood something?
The typical way you'd use SDLNet_ResolveHost is like this:

SDLNet_ResolveHost(&ip,"something.org",port);

Instead of giving it a string, you're giving it NULL.  It doesn't know what to 
do with NULL, so it sets things to INADDR_ANY.  If you only need to talk to 
your own machine, you can just resolve "127.0.0.1".  If you need to know your 
REAL, ACTUAL IP address, SDL_Net can't do that.  It's a more complicated 
problem than it sounds -- if your machine has several IPs on several cards, 
which should it choose?

I had to find out the actual host IP address for one of my projects, faf, 
derived from SDL_webserver...  the IP address detection currently works under 
win, linux, and mac.  It's in it's own file in the tarball somewhere, maybye 
you'll find it helpful.  http://burningsmell.org/faf/




More information about the SDL mailing list