From: Miroslav Lichvar Date: Mon, 19 Jun 2017 13:32:36 +0000 (+0200) Subject: Fix printing of NTP poll interval. X-Git-Tag: tcpdump-4.99-bp~2025 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/63c8c04ea769c70ce49eeb23c2040597aa9945f8 Fix printing of NTP poll interval. The poll value in an NTP packet is a signed integer. For negative values print the interval as a fraction of second. Also, ignore values outside of interval (-32, 32). --- diff --git a/print-ntp.c b/print-ntp.c index 0689264f..1593ca6b 100644 --- a/print-ntp.c +++ b/print-ntp.c @@ -116,7 +116,7 @@ struct s_fixedpt { struct ntpdata { u_char status; /* status of local clock and leap info */ u_char stratum; /* Stratum level */ - u_char ppoll; /* poll value */ + int ppoll:8; /* poll value */ int precision:8; struct s_fixedpt root_delay; struct s_fixedpt root_dispersion; @@ -170,6 +170,7 @@ struct ntpdata { static void p_sfix(netdissect_options *ndo, const struct s_fixedpt *); static void p_ntp_time(netdissect_options *, const struct l_fixedpt *); static void p_ntp_delta(netdissect_options *, const struct l_fixedpt *, const struct l_fixedpt *); +static void p_poll(netdissect_options *, register const int); static const struct tok ntp_mode_values[] = { { MODE_UNSPEC, "unspecified" }, @@ -236,8 +237,10 @@ ntp_print(netdissect_options *ndo, bp->stratum, tok2str(ntp_stratum_values, (bp->stratum >=2 && bp->stratum<=15) ? "secondary reference" : "reserved", bp->stratum))); - ND_TCHECK(bp->ppoll); - ND_PRINT((ndo, ", poll %u (%us)", bp->ppoll, 1 << bp->ppoll)); + /* Can't ND_TCHECK bp->ppoll bitfield so bp->stratum + 2 instead */ + ND_TCHECK2(bp->stratum, 2); + ND_PRINT((ndo, ", poll %d", bp->ppoll)); + p_poll(ndo, bp->ppoll); /* Can't ND_TCHECK bp->precision bitfield so bp->distance + 0 instead */ ND_TCHECK2(bp->root_delay, 0); @@ -425,3 +428,17 @@ p_ntp_delta(netdissect_options *ndo, ND_PRINT((ndo, "%s%d.%09d", signbit ? "-" : "+", i, f)); } +/* Prints polling interval in log2 as seconds or fraction of second */ +static void +p_poll(netdissect_options *ndo, + register const int poll) +{ + if (poll <= -32 || poll >= 32) + return; + + if (poll >= 0) + ND_PRINT((ndo, " (%us)", 1U << poll)); + else + ND_PRINT((ndo, " (1/%us)", 1U << -poll)); +} +