Aug 242010

Date: 3 Nov 2005
Author: Daniel Stenberg
License: freely available to do whatever you want with.

roundrobin.c – test the round robin DNS features of the resolver functions

Note: this test script is written to be compiled and run on Linux. It is
not as portable as it could be, but that is just to make it a simpler test

$ gcc roundrobin.c

This source snippet resolves a name with multiple IP addresses and prints them out in the order the addresses were returned by the resolving function. It first uses getaddrinfo() (called GAI) and then gethostbyname() (called GHBN).

On my three test machines they both show the same sympthoms:

The GAI list is a lot less “random” than the GHBN one. The GAI list almost always returns the same first entry on repeated invokes (while the subsequent entries comes somewhat more random). The GHBN list is returned in a much more random fashion.

The test machines are all running Debian Unstable glibc 2.3.5

What this program does:

It runs N resolves of a given host names. It stores the order it gets the returned addresses. When all N resolves are done, it checks how the returned addresses were distributed. The procedure is first done with GAI and then with GHBN. The output is presented in list index order. That means: ‘index 0’ is the first address in the returned list and ‘index 1’ is the second address and so on. We have found out that in the GAI case you very often get 100% of the same address in index 0.

We have three hosts names that resolves to multiple IP addresses:

As you will see, none of them resolves any sensible data for other purposes
than resolve tests or similar.
Continue reading »