//    dnsquery.c

#include <stdio.h>
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

/*    Description of data base entry for a single host.
      struct hostent
      {
        char *h_name;                 // Official name of host.
        char **h_aliases;             // Alias list.
        int h_addrtype;               // Host address type.
        int h_length;                 // Length of address.
        char **h_addr_list;           // List of addresses from name server.
      };
*/

void dnsquery(char *name)
{
	struct hostent *phostent;
	int x=0;

	if ((phostent = gethostbyname(name))==NULL) {
		herror("il dns non riesce a risolvere il nome\n gethostbyname() failed:");
		exit(0);
	}
	while	( phostent->h_addr_list[x]!=NULL )
	{
      printf("%s\n",  inet_ntoa(   *( (struct in_addr*)(phostent->h_addr_list[x])  ) )  );
		x++;
	}
}

void main(void)
{
   int i;

   for(i=0;i<10;i++)
      dnsquery("sistemimm.radio.csr.unibo.it");
}


