[Python-Dev] Re: _socket efficiency ideas

Marangozov, Vladimir (Vladimir) vladimir.marangozov@optimay.com
Thu, 10 Apr 2003 09:40:44 -0400


About the DNS discussion, I'll chime in with some info.
(I don't know what Python does about this and have no
 time to figure it out).

The format of an Internet (IPv4) address is:

 a.b.c.d  - with all parts treated as 8 bits
 a.b.c    - with 'c' treated as 16 bits
 a.b      - with 'b' treated as 24 bits
 a        - with 'a' treated as 32 bits

You can try this out with ping 127.1; ping 127, etc.

Any decent DNS resolver first tries to figure out whether
the requested name string is an IP address.  If it is, it
doesn't send a query and returns immediately the numeric
value of the string representation of the IP address.

How a DNS resolver detects whether it should launch a
query for the name 'name' varies from resolver to resolver,
but basically, it does the following:

1. check for local resolution of 'name'
   (ex. if 'name' =3D=3D 'localhost', return

2. if inet_aton('name') succeeds, 'name' is an IP address
   and return the result from inet_aton.

3. If caching is enabled, check the cache for 'name'

If 1, 2 and 3 don't hold, send a DNS query.

Caching is a separate/complementary issue and I agree that
it should be left to the underlying resolver.