dnsresolve.c
changeset 0 af501b0c1716
child 8 96d16dfe787a
equal deleted inserted replaced
-1:000000000000 0:af501b0c1716
       
     1 /**
       
     2  *     $Id: dnsresolve.c,v 1.1.1.1 2008-04-28 17:32:53 mbroeker Exp $
       
     3  * $Source: /development/c/demos/dnsresolve.c,v $
       
     4  *
       
     5  */
       
     6 
       
     7 #include <stdio.h>
       
     8 #include <stdlib.h>
       
     9 #include <string.h>
       
    10 #include <arpa/inet.h>
       
    11 #include <netdb.h>
       
    12 
       
    13 int main (int argc, char **argv)
       
    14 {
       
    15     struct hostent *he;
       
    16     char *ip;
       
    17 
       
    18     int i = 0;
       
    19 
       
    20     if (argc != 2) {
       
    21         fprintf (stderr, "Usage: %s hostname\n", argv[0]);
       
    22         exit (0);
       
    23     }
       
    24 
       
    25     he = gethostbyname (argv[1]);
       
    26     ip = NULL;
       
    27 
       
    28     if (he != NULL) {
       
    29         while (he->h_addr_list[i] != NULL) {
       
    30             ip = inet_ntoa (*((struct in_addr *)he->h_addr_list[i]));
       
    31             printf ("%s: %s\n", argv[1], ip);
       
    32             i++;
       
    33         }
       
    34     }
       
    35 
       
    36     return 0;
       
    37 }