[Git][NTPsec/ntpsec][master] Replace local numtoa() with POSIX inet_ntoa()
Eric S. Raymond
gitlab at mg.gitlab.com
Tue Jul 31 11:16:53 UTC 2018
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
5b6bf7a2 by Matt Selsky at 2018-07-31T03:50:50Z
Replace local numtoa() with POSIX inet_ntoa()
- - - - -
5 changed files:
- include/ntp_stdlib.h
- libntp/numtoa.c
- ntpd/ntp_control.c
- ntpd/ntp_util.c
- tests/libntp/numtoa.c
Changes:
=====================================
include/ntp_stdlib.h
=====================================
@@ -101,7 +101,6 @@ extern const char * res_access_flags(unsigned short);
extern const char * k_st_flags (uint32_t);
extern char * statustoa (int, int);
extern sockaddr_u * netof6 (sockaddr_u *);
-extern char * numtoa (uint32_t);
extern const char * socktoa (const sockaddr_u *);
extern const char * sockporttoa(const sockaddr_u *);
extern unsigned short sock_hash(const sockaddr_u *) __attribute__((pure));
=====================================
libntp/numtoa.c
=====================================
@@ -12,25 +12,6 @@
#include "lib_strbuf.h"
#include "ntp_stdlib.h"
-char *
-numtoa(
- uint32_t num
- )
-{
- uint32_t netnum;
- char *buf;
-
- netnum = ntohl(num);
- buf = lib_getbuf();
- snprintf(buf, LIB_BUFLENGTH, "%lu.%lu.%lu.%lu",
- ((unsigned long)netnum >> 24) & 0xff,
- ((unsigned long)netnum >> 16) & 0xff,
- ((unsigned long)netnum >> 8) & 0xff,
- (unsigned long)netnum & 0xff);
- return buf;
-}
-
-
/* Convert a refid & stratum to a string */
const char *
refid_str(
@@ -41,8 +22,11 @@ refid_str(
char * text;
size_t tlen;
- if (stratum > 1)
- return numtoa(refid);
+ if (stratum > 1) {
+ struct in_addr in4;
+ in4.s_addr = refid;
+ return inet_ntoa(in4);
+ }
text = lib_getbuf();
text[0] = '.';
=====================================
ntpd/ntp_control.c
=====================================
@@ -1365,8 +1365,11 @@ ctl_putadr(
*cp++ = *cq++;
*cp++ = '=';
- if (NULL == addr)
- cq = numtoa(addr32);
+ if (NULL == addr) {
+ struct in_addr in4;
+ in4.s_addr = addr32;
+ cq = inet_ntoa(in4);
+ }
else
cq = socktoa(addr);
INSIST((cp - buffer) < (int)sizeof(buffer));
=====================================
ntpd/ntp_util.c
=====================================
@@ -518,7 +518,7 @@ mprintf_clock_stats(
* file format
* day (MJD)
* time (s past midnight)
- * source IP address old format) or drivername(unit) (new format)
+ * source IP address (old format) or drivername(unit) (new format)
* destination peer address
* t1 t2 t3 t4 timestamps
* various other local statistics
=====================================
tests/libntp/numtoa.c
=====================================
@@ -11,20 +11,6 @@ TEST_SETUP(numtoa) {}
TEST_TEAR_DOWN(numtoa) {}
-TEST(numtoa, Address) {
- uint32_t input = htonl(3221225472UL+512UL+1UL); // 192.0.2.1
-
- TEST_ASSERT_EQUAL_STRING("192.0.2.1", numtoa(input));
-}
-
-TEST(numtoa, Netmask) {
- // 255.255.255.0
- uint32_t hostOrder = 255UL*256UL*256UL*256UL + 255UL*256UL*256UL + 255UL*256UL;
- uint32_t input = htonl(hostOrder);
-
- TEST_ASSERT_EQUAL_STRING("255.255.255.0", numtoa(input));
-}
-
TEST(numtoa, RefidStr) {
const char *res;
@@ -37,7 +23,5 @@ TEST(numtoa, RefidStr) {
}
TEST_GROUP_RUNNER(numtoa) {
- RUN_TEST_CASE(numtoa, Address);
- RUN_TEST_CASE(numtoa, Netmask);
RUN_TEST_CASE(numtoa, RefidStr);
}
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/5b6bf7a26ff6b46795f8a7fc293c3c89933ad627
--
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/5b6bf7a26ff6b46795f8a7fc293c3c89933ad627
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20180731/8349e6fb/attachment-0001.html>
More information about the vc
mailing list