dnsresolve.c
author Markus Brökers <mbroeker@largo.homelinux.org>
Sun, 29 Aug 2010 16:36:19 +0200
changeset 145 63a5269fb113
parent 77 49e0babccb23
child 153 b223089872b6
permissions -rw-r--r--
removed code without effect time_t represents the number of seconds since the birth of unix. to deal with microseconds and friends, use a) gettimeofday b) struct timeval

/**
 * dnsresolve.c
 * Copyright (C) 2008 Markus Broeker
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <arpa/inet.h>
#include <netdb.h>

int main (int argc, char **argv)
{
    struct hostent *he;

    char *ip;

    int i = 0;

    if (argc != 2) {
        fprintf (stderr, "Usage: %s <hostname>\n", argv[0]);
        return EXIT_FAILURE;
    }

    he = gethostbyname (argv[1]);
    ip = NULL;

    if (he != NULL) {
        while (he->h_addr_list[i] != NULL) {
            ip = inet_ntoa (*((struct in_addr *)he->h_addr_list[i]));
            printf ("%s: %s\n", argv[1], ip);
            i++;
        }
    }

    return EXIT_SUCCESS;
}