X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/74bb4ee159b105b333421688f1de6f42d115e803..411c7e7f103ec22c094cb5c84fa325091f58d16e:/print-ntp.c diff --git a/print-ntp.c b/print-ntp.c index fd5143bc..6fc1dd0d 100644 --- a/print-ntp.c +++ b/print-ntp.c @@ -25,7 +25,7 @@ #ifndef lint static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/tcpdump/print-ntp.c,v 1.40 2004-01-28 14:34:50 hannes Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-ntp.c,v 1.43 2007-11-30 13:45:10 hannes Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -72,6 +72,12 @@ static struct tok ntp_leapind_values[] = { { 0, NULL } }; +static struct tok ntp_stratum_values[] = { + { UNSPECIFIED, "unspecified" }, + { PRIM_REF, "primary reference" }, + { 0, NULL } +}; + /* * Print ntp requests */ @@ -82,9 +88,6 @@ ntp_print(register const u_char *cp, u_int length) int mode, version, leapind; bp = (struct ntpdata *)cp; - /* Note funny sized packets */ - if (length != sizeof(struct ntpdata)) - (void)printf(" [len=%d]", length); TCHECK(bp->status); @@ -109,7 +112,9 @@ ntp_print(register const u_char *cp, u_int length) leapind); TCHECK(bp->stratum); - printf(", Stratum %u", bp->stratum); + printf(", Stratum %u (%s)", + bp->stratum, + tok2str(ntp_stratum_values, (bp->stratum >=2 && bp->stratum<=15) ? "secondary reference" : "reserved", bp->stratum)); TCHECK(bp->ppoll); printf(", poll %us", bp->ppoll); @@ -136,7 +141,8 @@ ntp_print(register const u_char *cp, u_int length) break; case PRIM_REF: - fn_printn((u_char *)&(bp->refid), 4, NULL); + if (fn_printn((u_char *)&(bp->refid), 4, snapend)) + goto trunc; break; case INFO_QUERY: @@ -176,8 +182,16 @@ ntp_print(register const u_char *cp, u_int length) fputs("\n\t Originator - Transmit Timestamp: ", stdout); p_ntp_delta(&(bp->org_timestamp), &(bp->xmt_timestamp)); - /* FIXME key-id, authentication */ - + if ( (sizeof(struct ntpdata) - length) == 16) { /* Optional: key-id */ + printf("\n\tKey id: %u", bp->key_id); + } else if ( (sizeof(struct ntpdata) - length) == 0) { /* Optional: key-id + authentication */ + printf("\n\tKey id: %u", bp->key_id); + printf("\n\tAuthentication: %08x%08x%08x%08x", + EXTRACT_32BITS(bp->message_digest), + EXTRACT_32BITS(bp->message_digest + 4), + EXTRACT_32BITS(bp->message_digest + 8), + EXTRACT_32BITS(bp->message_digest + 12)); + } return; trunc: