summaryrefslogtreecommitdiff
path: root/test/inet/gethost.c
blob: 77467e9e32cb8c11f9320f530011058cb5d4696f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <errno.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <arpa/inet.h>
#include <sys/socket.h>

int main(void)
{
       in_addr_t addr = inet_addr("127.0.0.1");
       struct hostent *hent;

       hent = gethostent();
       if (hent == NULL) {
               printf("gethostent(%d):%s\n", errno, hstrerror(h_errno));
               exit(1);
       }

       hent = gethostbyname("localhost");
       if (hent == NULL) {
               printf("gethostbyname(%d):%s\n", errno, hstrerror(h_errno));
               exit(1);
       }

       hent = gethostbyname2("localhost", AF_INET);
       if (hent == NULL) {
               printf("gethostbyname2(%d):%s\n", errno, hstrerror(h_errno));
               exit(1);
       }

       hent = gethostbyaddr(&addr, sizeof(addr), AF_INET);
       if (hent == NULL) {
               printf("gethostbyaddr(%d):%s\n", errno, hstrerror(h_errno));
               exit(1);
       }

       return 0;
}