File: test_gethostent.c

package info (click to toggle)
nss-wrapper 1.1.16-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 888 kB
  • sloc: ansic: 7,947; perl: 372; sh: 26; makefile: 12
file content (61 lines) | stat: -rw-r--r-- 1,065 bytes parent folder | download | duplicates (4)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "config.h"

#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>

#include <stdio.h>
#include <string.h>
#include <unistd.h>

#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>

static void test_nwrap_gethostent(void **state)
{
	struct hostent *he;
	uint32_t i;

	(void)state; /* unused */

	sethostent(0);

	for (he = gethostent(); he != NULL; he = gethostent()) {
		assert_non_null(he->h_addr_list);
		assert_non_null(he->h_aliases);

		for (i = 0; he->h_addr_list[i] != NULL; i++) {
			char buf[INET6_ADDRSTRLEN];
			uint32_t j;
			const char *ip;
			
			ip = inet_ntop(he->h_addrtype,
				       he->h_addr_list[i],
				       buf,
				       sizeof(buf));

			printf("ip: %s\n", ip);

			for (j = 0; he->h_aliases[j] != NULL; j++) {
				printf("alias: %s\n", he->h_aliases[j]);
			}
		}
	}

	endhostent();
}

int main(void) {
	int rc;

	const struct CMUnitTest tests[] = {
		cmocka_unit_test(test_nwrap_gethostent),
	};

	rc = cmocka_run_group_tests(tests, NULL, NULL);

	return rc;
}