author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Sat, 13 Dec 2008 17:58:00 +0100 | |
changeset 8 | 96d16dfe787a |
parent 0 | af501b0c1716 |
child 9 | c3fecc82ade6 |
permissions | -rw-r--r-- |
0 | 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 |
||
8
96d16dfe787a
We use return EXIT_SUCCESS instead of return 0
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
36 |
return EXIT_SUCCESS; |
0 | 37 |
} |