1 /*
2 * Copyright (c) 2022 Meta
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include "_common.h"
8
9 #ifdef CONFIG_POSIX_API
10 #include <netdb.h>
11 #else
12 #include <zephyr/posix/netdb.h>
13 #endif
14
15 /**
16 * @brief existence test for `<netdb.h>`
17 *
18 * @see <a href="https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netdb.h.html>netdb.h</a>
19 */
ZTEST(posix_headers,test_netdb_h)20 ZTEST(posix_headers, test_netdb_h)
21 {
22 zassert_not_equal(-1, offsetof(struct hostent, h_name));
23 zassert_not_equal(-1, offsetof(struct hostent, h_aliases));
24 zassert_not_equal(-1, offsetof(struct hostent, h_addrtype));
25 zassert_not_equal(-1, offsetof(struct hostent, h_length));
26 zassert_not_equal(-1, offsetof(struct hostent, h_addr_list));
27
28 zassert_not_equal(-1, offsetof(struct netent, n_name));
29 zassert_not_equal(-1, offsetof(struct netent, n_aliases));
30 zassert_not_equal(-1, offsetof(struct netent, n_addrtype));
31 zassert_not_equal(-1, offsetof(struct netent, n_net));
32
33 zassert_not_equal(-1, offsetof(struct protoent, p_name));
34 zassert_not_equal(-1, offsetof(struct protoent, p_aliases));
35 zassert_not_equal(-1, offsetof(struct protoent, p_proto));
36
37 zassert_not_equal(-1, offsetof(struct servent, s_name));
38 zassert_not_equal(-1, offsetof(struct servent, s_aliases));
39 zassert_not_equal(-1, offsetof(struct servent, s_port));
40 zassert_not_equal(-1, offsetof(struct servent, s_proto));
41
42 /* zassert_equal(IPPORT_RESERVED, UINT16_MAX); */ /* not implemented */
43
44 zassert_not_equal(-1, offsetof(struct addrinfo, ai_flags));
45 zassert_not_equal(-1, offsetof(struct addrinfo, ai_family));
46 zassert_not_equal(-1, offsetof(struct addrinfo, ai_socktype));
47 zassert_not_equal(-1, offsetof(struct addrinfo, ai_protocol));
48 zassert_not_equal(-1, offsetof(struct addrinfo, ai_addrlen));
49 zassert_not_equal(-1, offsetof(struct addrinfo, ai_addr));
50 zassert_not_equal(-1, offsetof(struct addrinfo, ai_canonname));
51 zassert_not_equal(-1, offsetof(struct addrinfo, ai_next));
52
53 zassert_not_equal(-1, AI_PASSIVE);
54 zassert_not_equal(-1, AI_CANONNAME);
55 zassert_not_equal(-1, AI_NUMERICHOST);
56 zassert_not_equal(-1, AI_NUMERICSERV);
57 zassert_not_equal(-1, AI_V4MAPPED);
58 zassert_not_equal(-1, AI_ALL);
59 zassert_not_equal(-1, AI_ADDRCONFIG);
60
61 zassert_not_equal(-1, NI_NOFQDN);
62 zassert_not_equal(-1, NI_NUMERICHOST);
63 zassert_not_equal(-1, NI_NAMEREQD);
64 zassert_not_equal(-1, NI_NUMERICSERV);
65 /* zassert_not_equal(-1, NI_NUMERICSCOPE); */ /* not implemented */
66 zassert_not_equal(-1, NI_DGRAM);
67
68 zassert_not_equal(-1, EAI_AGAIN);
69 zassert_equal(-1, EAI_BADFLAGS);
70 zassert_not_equal(-1, EAI_FAIL);
71 zassert_not_equal(-1, EAI_FAMILY);
72 zassert_not_equal(-1, EAI_MEMORY);
73 zassert_not_equal(-1, EAI_NONAME);
74 zassert_not_equal(-1, EAI_SERVICE);
75 zassert_not_equal(-1, EAI_SOCKTYPE);
76 zassert_not_equal(-1, EAI_SYSTEM);
77 zassert_not_equal(-1, EAI_OVERFLOW);
78
79 if (IS_ENABLED(CONFIG_POSIX_NETWORKING)) {
80 zassert_not_null(endhostent);
81 zassert_not_null(endnetent);
82 zassert_not_null(endprotoent);
83 zassert_not_null(endservent);
84 zassert_not_null(freeaddrinfo);
85 zassert_not_null(gai_strerror);
86 zassert_not_null(getaddrinfo);
87 zassert_not_null(gethostent);
88 zassert_not_null(getnameinfo);
89 zassert_not_null(getnetbyaddr);
90 zassert_not_null(getnetbyname);
91 zassert_not_null(getnetent);
92 zassert_not_null(getprotobyname);
93 zassert_not_null(getprotobynumber);
94 zassert_not_null(getprotoent);
95 zassert_not_null(getservbyname);
96 zassert_not_null(getservbyport);
97 zassert_not_null(getservent);
98 zassert_not_null(sethostent);
99 zassert_not_null(setnetent);
100 zassert_not_null(setprotoent);
101 zassert_not_null(setservent);
102 }
103 }
104