Re: getaddrinfo: DNS round robin vs RFC3484 s6 rule 9, for etch
On Sat, Sep 29, 2007 at 02:07:02PM +0200, Wolf Wiegand wrote:
>
> The machine I have access to doesn't support ahosts. getent host
> returns different addresses for ftp.us.debian.org on subsequent calls.
Please either try this python script:
import socket
k = [ socket.getaddrinfo("rule9.erisian.com.au", "http")[0][4][0] for blah in range(1000) ]
print dict([ (l, k.count(l)) for l in k ])
Or compile the attached C file and run it multiple times.
Kurt
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdio.h>
int main()
{
struct addrinfo *res, *p, hints;
hints.ai_flags = 0;
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_DGRAM;
hints.ai_protocol = 0;
hints.ai_addrlen = 0;
hints.ai_addr = NULL;
hints.ai_canonname = NULL;
hints.ai_next = NULL;
getaddrinfo("0.pool.ntp.org", "ntp", &hints, &res);
for (p = res; p; p = p->ai_next)
{
if (p->ai_family == AF_INET)
{
char ip[INET_ADDRSTRLEN];
if (inet_ntop(p->ai_family,
&(*(struct sockaddr_in *)p->ai_addr).sin_addr,
ip, sizeof(ip)) != NULL)
{
printf("%s\n", ip);
}
}
}
freeaddrinfo(res);
return 0;
}
Reply to: