2 #include "ntp_stdlib.h"
3 #include "sockaddrtest.h"
7 extern void test_IPv4AddressOnly(void);
8 extern void test_IPv4AddressWithPort(void);
9 //#ifdef ISC_PLATFORM_HAVEIPV6
10 extern void test_IPv6AddressOnly(void);
11 extern void test_IPv6AddressWithPort(void);
12 //#endif /* ISC_PLATFORM_HAVEIPV6 */
13 extern void test_IllegalAddress(void);
14 extern void test_IllegalCharInPort(void);
18 test_IPv4AddressOnly(void) {
19 const char *str = "192.0.2.1";
23 expected.sa4.sin_family = AF_INET;
24 expected.sa4.sin_addr.s_addr = inet_addr("192.0.2.1");
25 SET_PORT(&expected, NTP_PORT);
27 TEST_ASSERT_TRUE(decodenetnum(str, &actual));
28 TEST_ASSERT_TRUE(IsEqual(expected, actual));
32 test_IPv4AddressWithPort(void) {
33 const char *str = "192.0.2.2:2000";
37 expected.sa4.sin_family = AF_INET;
38 expected.sa4.sin_addr.s_addr = inet_addr("192.0.2.2");
39 SET_PORT(&expected, 2000);
41 TEST_ASSERT_TRUE(decodenetnum(str, &actual));
42 TEST_ASSERT_TRUE(IsEqual(expected, actual));
47 test_IPv6AddressOnly(void) {
49 //#ifdef ISC_PLATFORM_HAVEIPV6 //looks like HAVEIPV6 checks if system has IPV6 capabilies. WANTIPV6 can be changed with build --disable-ipv6
50 #ifdef ISC_PLATFORM_WANTIPV6
51 const struct in6_addr address = {
52 0x20, 0x01, 0x0d, 0xb8,
53 0x85, 0xa3, 0x08, 0xd3,
54 0x13, 0x19, 0x8a, 0x2e,
55 0x03, 0x70, 0x73, 0x34
58 const char *str = "2001:0db8:85a3:08d3:1319:8a2e:0370:7334";
62 expected.sa6.sin6_family = AF_INET6;
63 expected.sa6.sin6_addr = address;
64 SET_PORT(&expected, NTP_PORT);
66 TEST_ASSERT_TRUE(decodenetnum(str, &actual));
67 TEST_ASSERT_TRUE(IsEqual(expected, actual));
70 TEST_IGNORE_MESSAGE("IPV6 disabled in build, skipping.");
71 #endif /* ISC_PLATFORM_HAVEIPV6 */
79 test_IPv6AddressWithPort(void) {
81 #ifdef ISC_PLATFORM_WANTIPV6
83 const struct in6_addr address = {
84 0x20, 0x01, 0x0d, 0xb8,
85 0x85, 0xa3, 0x08, 0xd3,
86 0x13, 0x19, 0x8a, 0x2e,
87 0x03, 0x70, 0x73, 0x34
90 const char *str = "[2001:0db8:85a3:08d3:1319:8a2e:0370:7334]:3000";
94 expected.sa6.sin6_family = AF_INET6;
95 expected.sa6.sin6_addr = address;
96 SET_PORT(&expected, 3000);
98 TEST_ASSERT_TRUE(decodenetnum(str, &actual));
99 TEST_ASSERT_TRUE(IsEqual(expected, actual));
102 TEST_IGNORE_MESSAGE("IPV6 disabled in build, skipping.");
103 #endif /* ISC_PLATFORM_HAVEIPV6 */
108 test_IllegalAddress(void) {
109 const char *str = "192.0.2.270:2000";
112 TEST_ASSERT_FALSE(decodenetnum(str, &actual));
116 test_IllegalCharInPort(void) {
117 /* An illegal port does not make the decodenetnum fail, but instead
118 * makes it use the standard port.
120 const char *str = "192.0.2.1:a700";
124 expected.sa4.sin_family = AF_INET;
125 expected.sa4.sin_addr.s_addr = inet_addr("192.0.2.1");
126 SET_PORT(&expected, NTP_PORT);
128 TEST_ASSERT_TRUE(decodenetnum(str, &actual));
129 TEST_ASSERT_TRUE(IsEqual(expected, actual));