SDLNetResolveIP coded

I have coded the function that wasn’t implemented,
simply add the file to the project.

I have test it under Windows and Linux.
Also I have modified what the funciton return in case of error.

Sam, could you put my name somewhere in the SDLnet page?

Miguel Angel Blanch Lardin
Main developer of Arianne RPG
http://come.to/arianne_rpg
-------------- next part --------------
A non-text attachment was scrubbed…
Name: SDLnetResolveIP.c
Type: application/octet-stream
Size: 1119 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20000414/ae190e37/attachment.obj

/* Resolve an ip address to a host name in canonical form.
If the ip couldn’t be resolved, this function returns NULL,
otherwise a pointer to a static buffer containing the hostname
is returned. Note that this function is not thread-safe.

No, you return a malloc (leaking memory) if the reverse lookup fail.
Better return a pointer to static storage.

It would be handy to have a thread-safe or (better) asynch version
of this call, since that is tricky to do portably. If the platform
supports getXbyY_r(), you can have it thread safe and run the lookup
in a thread; otherwise, the usual procedure is to fork and pass the
result in a pipe.

(Why doesn’t POSIX have an asynch DNS lookups? Even Windows and MacOS can
do that!)

Quoting Mattias Engdeg?rd :

For the thread safe, we could use a Mutex, isn’ it?

About the error case, I prefer it to return me a string
with the name of the host that it hasn’t resolved.

/* Resolve an ip address to a host name in canonical form.
If the ip couldn’t be resolved, this function returns NULL,
otherwise a pointer to a static buffer containing the hostname
is returned. Note that this function is not thread-safe.

No, you return a malloc (leaking memory) if the reverse lookup fail.
Better return a pointer to static storage.

It would be handy to have a thread-safe or (better) asynch version
of this call, since that is tricky to do portably. If the platform
supports getXbyY_r(), you can have it thread safe and run the lookup
in a thread; otherwise, the usual procedure is to fork and pass the
result in a pipe.

(Why doesn’t POSIX have an asynch DNS lookups? Even Windows and
MacOS can> do that!)

For the thread safe, we could use a Mutex, isn’ it?

Yes, but you can’t run more than one lookup at the same time. And mutices
don’t protect functions returning pointers to static storage.

About the error case, I prefer it to return me a string
with the name of the host that it hasn’t resolved.

Now it sometimes returns a pointer to static storage, sometimes to
malloc:ed memory. How do you know if you should call free()? Besides,
nothing prevents you from doing inet_ntoa() yourself.