dnsresolve.c
author Emilio Largo <largo@largo.homelinux.org>
Thu, 16 Apr 2009 12:49:12 +0200
changeset 45 7197576fedcf
parent 27 81a574d60c15
child 48 b94d657a9acb
permissions -rw-r--r--
pmc: namespace algebra for vector -> the namespace prevents clashes with std::vector -> std::vector and algebra::Vector with capital V. md5: a md5 replacement ncurses: keypad function added committer: Markus Bröker <mbroeker@largo.homelinux.org>

/**
 * test/demos/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]);
        exit (0);
    }

    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;
}