X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/779bcfb73addf223ee78104af297ab794c1d008e..e01c9bf76740802025c9328901b55ee4a0c49ed6:/print-ntp.c diff --git a/print-ntp.c b/print-ntp.c index 5dd0e240..0689264f 100644 --- a/print-ntp.c +++ b/print-ntp.c @@ -18,23 +18,23 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * Format and print ntp packets. * By Jeffrey Mogul/DECWRL * loosely based on print-bootp.c */ -#define NETDISSECT_REWORKED +/* \summary: Network Time Protocol (NTP) printer */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include +#include #ifdef HAVE_STRFTIME #include #endif -#include "interface.h" +#include "netdissect.h" #include "addrtoname.h" #include "extract.h" @@ -66,13 +66,13 @@ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ struct l_fixedpt { - u_int32_t int_part; - u_int32_t fraction; + uint32_t int_part; + uint32_t fraction; }; struct s_fixedpt { - u_int16_t int_part; - u_int16_t fraction; + uint16_t int_part; + uint16_t fraction; }; /* rfc2030 @@ -120,13 +120,13 @@ struct ntpdata { int precision:8; struct s_fixedpt root_delay; struct s_fixedpt root_dispersion; - u_int32_t refid; + uint32_t refid; struct l_fixedpt ref_timestamp; struct l_fixedpt org_timestamp; struct l_fixedpt rec_timestamp; struct l_fixedpt xmt_timestamp; - u_int32_t key_id; - u_int8_t message_digest[16]; + uint32_t key_id; + uint8_t message_digest[16]; }; /* * Leap Second Codes (high order two bits) @@ -207,7 +207,7 @@ ntp_print(netdissect_options *ndo, register const struct ntpdata *bp; int mode, version, leapind; - bp = (struct ntpdata *)cp; + bp = (const struct ntpdata *)cp; ND_TCHECK(bp->status); @@ -261,22 +261,22 @@ ntp_print(netdissect_options *ndo, break; case PRIM_REF: - if (fn_printn((u_char *)&(bp->refid), 4, ndo->ndo_snapend)) + if (fn_printn(ndo, (const u_char *)&(bp->refid), 4, ndo->ndo_snapend)) goto trunc; break; case INFO_QUERY: - ND_PRINT((ndo, "%s INFO_QUERY", ipaddr_string(&(bp->refid)))); + ND_PRINT((ndo, "%s INFO_QUERY", ipaddr_string(ndo, &(bp->refid)))); /* this doesn't have more content */ return; case INFO_REPLY: - ND_PRINT((ndo, "%s INFO_REPLY", ipaddr_string(&(bp->refid)))); + ND_PRINT((ndo, "%s INFO_REPLY", ipaddr_string(ndo, &(bp->refid)))); /* this is too complex to be worth printing */ return; default: - ND_PRINT((ndo, "%s", ipaddr_string(&(bp->refid)))); + ND_PRINT((ndo, "%s", ipaddr_string(ndo, &(bp->refid)))); break; } @@ -327,12 +327,12 @@ p_sfix(netdissect_options *ndo, { register int i; register int f; - register float ff; + register double ff; i = EXTRACT_16BITS(&sfp->int_part); f = EXTRACT_16BITS(&sfp->fraction); - ff = f / 65536.0; /* shift radix point by 16 bits */ - f = ff * 1000000.0; /* Treat fraction as parts per million */ + ff = f / 65536.0; /* shift radix point by 16 bits */ + f = (int)(ff * 1000000.0); /* Treat fraction as parts per million */ ND_PRINT((ndo, "%d.%06d", i, f)); } @@ -343,17 +343,17 @@ p_ntp_time(netdissect_options *ndo, register const struct l_fixedpt *lfp) { register int32_t i; - register u_int32_t uf; - register u_int32_t f; - register float ff; + register uint32_t uf; + register uint32_t f; + register double ff; i = EXTRACT_32BITS(&lfp->int_part); uf = EXTRACT_32BITS(&lfp->fraction); ff = uf; if (ff < 0.0) /* some compilers are buggy */ ff += FMAXINT; - ff = ff / FMAXINT; /* shift radix point by 32 bits */ - f = ff * 1000000000.0; /* treat fraction as parts per billion */ + ff = ff / FMAXINT; /* shift radix point by 32 bits */ + f = (uint32_t)(ff * 1000000000.0); /* treat fraction as parts per billion */ ND_PRINT((ndo, "%u.%09d", i, f)); #ifdef HAVE_STRFTIME @@ -379,10 +379,10 @@ p_ntp_delta(netdissect_options *ndo, register const struct l_fixedpt *lfp) { register int32_t i; - register u_int32_t u, uf; - register u_int32_t ou, ouf; - register u_int32_t f; - register float ff; + register uint32_t u, uf; + register uint32_t ou, ouf; + register uint32_t f; + register double ff; int signbit; u = EXTRACT_32BITS(&lfp->int_part); @@ -420,8 +420,8 @@ p_ntp_delta(netdissect_options *ndo, ff = f; if (ff < 0.0) /* some compilers are buggy */ ff += FMAXINT; - ff = ff / FMAXINT; /* shift radix point by 32 bits */ - f = ff * 1000000000.0; /* treat fraction as parts per billion */ + ff = ff / FMAXINT; /* shift radix point by 32 bits */ + f = (uint32_t)(ff * 1000000000.0); /* treat fraction as parts per billion */ ND_PRINT((ndo, "%s%d.%09d", signbit ? "-" : "+", i, f)); }