nwrap: Forward ERANGE error to caller in gethostbyname[2]_r
[nss_wrapper.git] / tests / test_gethostent.c
1 #include "config.h"
2
3 #include <stdarg.h>
4 #include <stddef.h>
5 #include <setjmp.h>
6 #include <cmocka.h>
7
8 #include <stdio.h>
9 #include <string.h>
10 #include <unistd.h>
11
12 #include <sys/socket.h>
13 #include <netinet/in.h>
14 #include <arpa/inet.h>
15 #include <netdb.h>
16
17 static void test_nwrap_gethostent(void **state)
18 {
19         struct hostent *he;
20         uint32_t i;
21
22         (void)state; /* unused */
23
24         sethostent(0);
25
26         for (he = gethostent(); he != NULL; he = gethostent()) {
27                 assert_non_null(he->h_addr_list);
28                 assert_non_null(he->h_aliases);
29
30                 for (i = 0; he->h_addr_list[i] != NULL; i++) {
31                         char buf[INET6_ADDRSTRLEN];
32                         uint32_t j;
33                         const char *ip;
34                         
35                         ip = inet_ntop(he->h_addrtype,
36                                        he->h_addr_list[i],
37                                        buf,
38                                        sizeof(buf));
39
40                         printf("ip: %s\n", ip);
41
42                         for (j = 0; he->h_aliases[j] != NULL; j++) {
43                                 printf("alias: %s\n", he->h_aliases[j]);
44                         }
45                 }
46         }
47
48         endhostent();
49 }
50
51 int main(void) {
52         int rc;
53
54         const struct CMUnitTest tests[] = {
55                 cmocka_unit_test(test_nwrap_gethostent),
56         };
57
58         rc = cmocka_run_group_tests(tests, NULL, NULL);
59
60         return rc;
61 }