summaryrefslogtreecommitdiff
path: root/src/bin/gethostbyname.c
blob: b670b1e66834819858f595547054e38d8f2123d0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdio.h>
#include <netdb.h>
#include <arpa/inet.h>

int main(int argc,char *argv[]) {
 int i;
 if(argc < 2) return 1;
 char *addr;
 struct in_addr saddr;
 if(inet_aton(argv[1],&saddr))
  addr=inet_ntoa(saddr);
 else
  addr=argv[1];
 struct hostent *he=gethostbyname(addr);

 for(i=0;he->h_addr_list[i];i++) {
  printf("%u.%u.%u.%u\n",
         (unsigned char)he->h_addr_list[i][0],
         (unsigned char)he->h_addr_list[i][1],
         (unsigned char)he->h_addr_list[i][2],
         (unsigned char)he->h_addr_list[i][3]);
 }
 return 0;
}