- 论坛徽章:
- 0
|
#include <netdb.h>
int main(int argc, const char **argv)
{
in_addr_t addr;
struct hostent *hp;
char **p;
if (argc != 2) {
(void) printf("usage: %s IP-address0, argv[0]);
exit (1);
}
if ((int)(addr = inet_addr(argv[1])) == -1) {
(void) printf("IP-address must be of the form a.b.c.d0);
exit (2);
}
hp = gethostbyaddr((char *)&addr, 4, AF_INET);
if (hp == NULL) {
(void) printf("host information for %s not found0, argv[1]);
exit (3);
}
for (p = hp->h_addr_list; *p != 0; p++) {
struct in_addr in;
char **q;
(void) memcpy(&in.s_addr, *p, sizeof (in.s_addr));
(void) printf("%s%s", inet_ntoa(in), hp->h_name);
for (q = hp->h_aliases; *q != 0; q++)
(void) printf(" %s", *q);
(void) putchar('0');
}
exit (0);
}
this is a example in the man manual |
|