[Python-Dev] Re: More socket questions
Marangozov, Vladimir (Vladimir)
vladimir.marangozov@optimay.com
Fri, 11 Apr 2003 04:38:12 -0400
Hi,
inet_aton() is a pretty simple parser of an IP address string,
but it is not available on all setups. Libraries relying on
it usually provide a local version. So do the same.
Search the Web for "inet_aton.c" and you'll hit a standard
implementation, with all the niceties about the base encoding
of each part of the IP address which follows the C convention:
0x - hex, 0 - octal, other - decimal. And thus, BTW,
"ping 192.30.20.10" is not the same as "ping 192.030.020.010".
So take that code, stuff it in my_inet_aton() and case closed.
You could use my_inet_aton() before calling gethostbyname('name')
to see whether 'name' is an IP address and return immediately,
but as I said, decent resolvers should do that for you. After
all, their job is to give you an IP address in return. If you
feed an IP address as an input, you should get it as a reply.
Not all resolvers are decent, though. On top of that, some have
bugs :-). I can't answer the question about netdb's status quo.
Cheers,
Vladimir