Debian Codegraph @

tests/test_gethostent.c

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