From: Dave Hart Date: Sun, 12 Dec 2010 08:30:28 +0000 (+0000) Subject: Add test for socktoa(), sockporttoa() with scoped address. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=60e2dd294f2abf1bf338033693db908ddb26e1ef;p=thirdparty%2Fntp.git Add test for socktoa(), sockporttoa() with scoped address. Correct unit tests for sntp offset_calculation() arg change. bk: 4d048824jcvkNGaNeqf0qvlEPvBKDw --- diff --git a/ntpd/ntp_control.c b/ntpd/ntp_control.c index f032809c49..9b3394e8fb 100644 --- a/ntpd/ntp_control.c +++ b/ntpd/ntp_control.c @@ -579,8 +579,6 @@ ctl_error( * send packet and bump counters */ if (res_authenticate && sys_authenticate) { - int maclen; - maclen = authencrypt(res_keyid, (u_int32 *)&rpkt, CTL_HEADER_LEN); sendpkt(rmt_addr, lcl_inter, -2, (void *)&rpkt, diff --git a/ntpd/ntpsim.c b/ntpd/ntpsim.c index d15b2f7565..9ef3bf69b4 100644 --- a/ntpd/ntpsim.c +++ b/ntpd/ntpsim.c @@ -70,24 +70,26 @@ determine_recv_buf_ordering( /* Define a function to create the server associations */ void create_server_associations(void) { - int i; - for (i = 0;i < simulation.num_of_servers;++i) { - printf("%s\n", stoa(simulation.servers[i].addr)); - if (peer_config(simulation.servers[i].addr, - NULL, - ANY_INTERFACE_CHOOSE(simulation.servers[i].addr), - MODE_CLIENT, - NTP_VERSION, - NTP_MINDPOLL, - NTP_MAXDPOLL, - 0, /* peerflags */ - 0, /* ttl */ - 0, /* peerkey */ - (u_char *)"*" /* peerkeystr */) == 0) { - fprintf(stderr, "ERROR!! Could not create association for: %s", - stoa(simulation.servers[i].addr)); + int i; + + for (i = 0; i < simulation.num_of_servers; ++i) { + printf("%s\n", stoa(simulation.servers[i].addr)); + if (peer_config(simulation.servers[i].addr, + NULL, + ANY_INTERFACE_CHOOSE(simulation.servers[i].addr), + MODE_CLIENT, + NTP_VERSION, + NTP_MINDPOLL, + NTP_MAXDPOLL, + 0, /* peerflags */ + 0, /* ttl */ + 0, /* peerkey */ + NULL /* group ident */) == 0) { + fprintf(stderr, + "ERROR!! Could not create association for: %s", + stoa(simulation.servers[i].addr)); + } } - } } diff --git a/sntp/tests/packetHandling.cpp b/sntp/tests/packetHandling.cpp index c24f624232..74b861da7f 100644 --- a/sntp/tests/packetHandling.cpp +++ b/sntp/tests/packetHandling.cpp @@ -111,11 +111,12 @@ TEST_F(mainTest, OffsetCalculationPositiveOffset) { tmp.l_uf = 0UL; HTONL_FP(&tmp, &rpkt.xmt); - // T4 - Destination timestamp + // T4 - Destination timestamp as standard timeval tmp.l_ui = 1000000001UL; tmp.l_uf = 0UL; timeval dst; TSTOTV(&tmp, &dst); + dst.tv_sec -= JAN_1970; double offset, precision, root_disp; offset_calculation(&rpkt, LEN_PKT_NOMAC, &dst, &offset, &precision, &root_disp); @@ -152,11 +153,12 @@ TEST_F(mainTest, OffsetCalculationNegativeOffset) { tmp.l_uf = 2147483648UL; HTONL_FP(&tmp, &rpkt.xmt); - // T4 - Destination timestamp + // T4 - Destination timestamp as standard timeval tmp.l_ui = 1000000003UL; tmp.l_uf = 0UL; timeval dst; TSTOTV(&tmp, &dst); + dst.tv_sec -= JAN_1970; double offset, precision, root_disp; offset_calculation(&rpkt, LEN_PKT_NOMAC, &dst, &offset, &precision, &root_disp); diff --git a/sntp/tests/utilities.cpp b/sntp/tests/utilities.cpp index 1142971e7c..bd4c58b204 100644 --- a/sntp/tests/utilities.cpp +++ b/sntp/tests/utilities.cpp @@ -85,6 +85,7 @@ TEST_F(utilitiesTest, IPv6Address) { sockaddr_u input; addrinfo inputA; + memset(&input, 0, sizeof(input)); input.sa6.sin6_family = AF_INET6; input.sa6.sin6_addr = address; EXPECT_STREQ(expected, ss_to_str(&input)); @@ -96,8 +97,8 @@ TEST_F(utilitiesTest, IPv6Address) { TEST_F(utilitiesTest, SetLiVnMode1) { pkt expected; expected.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOWARNING, - NTP_VERSION, - MODE_SERVER); + NTP_VERSION, + MODE_SERVER); pkt actual; set_li_vn_mode(&actual, LEAP_NOWARNING, NTP_VERSION, diff --git a/tests/libntp/socktoa.cpp b/tests/libntp/socktoa.cpp index 2b6827e80d..6c70b6d8dd 100644 --- a/tests/libntp/socktoa.cpp +++ b/tests/libntp/socktoa.cpp @@ -13,9 +13,9 @@ TEST_F(socktoaTest, IPv4AddressWithPort) { TEST_F(socktoaTest, IPv6AddressWithPort) { const struct in6_addr address = { 0x20, 0x01, 0x0d, 0xb8, - 0x85, 0xa3, 0x08, 0xd3, - 0x13, 0x19, 0x8a, 0x2e, - 0x03, 0x70, 0x73, 0x34 + 0x85, 0xa3, 0x08, 0xd3, + 0x13, 0x19, 0x8a, 0x2e, + 0x03, 0x70, 0x73, 0x34 }; const char* expected = @@ -24,13 +24,40 @@ TEST_F(socktoaTest, IPv6AddressWithPort) { "[2001:db8:85a3:8d3:1319:8a2e:370:7334]:123"; sockaddr_u input; - input.sa6.sin6_family = AF_INET6; - input.sa6.sin6_addr = address; + memset(&input, 0, sizeof(input)); + AF(&input) = AF_INET6; + SET_ADDR6N(&input, address); + SET_PORT(&input, 123); + + EXPECT_STREQ(expected, socktoa(&input)); + EXPECT_STREQ(expected_port, sockporttoa(&input)); +} + +#ifdef ISC_PLATFORM_HAVESCOPEID +TEST_F(socktoaTest, ScopedIPv6AddressWithPort) { + const struct in6_addr address = { + 0xfe, 0x80, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x02, 0x12, 0x3f, 0xff, + 0xfe, 0x29, 0xff, 0xfa + }; + + const char* expected = + "fe80::212:3fff:fe29:fffa%5"; + const char* expected_port = + "[fe80::212:3fff:fe29:fffa%5]:123"; + + sockaddr_u input; + memset(&input, 0, sizeof(input)); + AF(&input) = AF_INET6; + SET_ADDR6N(&input, address); SET_PORT(&input, 123); + SCOPE_VAR(&input) = 5; EXPECT_STREQ(expected, socktoa(&input)); EXPECT_STREQ(expected_port, sockporttoa(&input)); } +#endif /* ISC_PLATFORM_HAVESCOPEID */ TEST_F(socktoaTest, HashEqual) { sockaddr_u input1 = CreateSockaddr4("192.00.2.2", 123);