]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-ntp.c
don't pass on src & dst MAC adresses to the isoclns decoder as MAC adresses
[tcpdump] / print-ntp.c
index 886a45fa1b9323d572d6821e8b2e5b73c71acc6a..1d32fda80d14340e4e615b1c2a75f7bec14feeff 100644 (file)
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-ntp.c,v 1.28 2000-07-01 03:39:07 assar Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-ntp.c,v 1.36 2002-12-28 17:15:06 hannes Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
-#include <sys/param.h>
-#include <sys/time.h>
-#include <sys/socket.h>
+#include <tcpdump-stdinc.h>
 
-struct mbuf;
-struct rtentry;
-#include <net/if.h>
-
-#include <netinet/in.h>
-#include <netinet/if_ether.h>
-
-#include <ctype.h>
 #include <stdio.h>
 #include <string.h>
 
 #include "interface.h"
 #include "addrtoname.h"
+#include "extract.h"
 #ifdef MODEMASK
 #undef MODEMASK                                        /* Solaris sucks */
 #endif
@@ -66,7 +57,6 @@ ntp_print(register const u_char *cp, u_int length)
 {
        register const struct ntpdata *bp;
        int mode, version, leapind;
-       static char rclock[5];
 
        bp = (struct ntpdata *)cp;
        /* Note funny sized packets */
@@ -76,7 +66,7 @@ ntp_print(register const u_char *cp, u_int length)
        TCHECK(bp->status);
 
        version = (int)(bp->status & VERSIONMASK) >> 3;
-       printf(" v%d", version);
+       printf("NTPv%d", version);
 
        leapind = bp->status & LEAPMASK;
        switch (leapind) {
@@ -131,14 +121,14 @@ ntp_print(register const u_char *cp, u_int length)
        }
 
        TCHECK(bp->stratum);
-       printf(" strat %d", bp->stratum);
+       printf(", strat %d", bp->stratum);
 
        TCHECK(bp->ppoll);
-       printf(" poll %d", bp->ppoll);
+       printf(", poll %d", bp->ppoll);
 
        /* Can't TCHECK bp->precision bitfield so bp->distance + 0 instead */
        TCHECK2(bp->distance, 0);
-       printf(" prec %d", bp->precision);
+       printf(", prec %d", bp->precision);
 
        if (!vflag)
                return;
@@ -148,11 +138,11 @@ ntp_print(register const u_char *cp, u_int length)
        p_sfix(&bp->distance);
 
        TCHECK(bp->dispersion);
-       fputs(" disp ", stdout);
+       fputs(", disp ", stdout);
        p_sfix(&bp->dispersion);
 
        TCHECK(bp->refid);
-       fputs(" ref ", stdout);
+       fputs(", ref ", stdout);
        /* Interpretation depends on stratum */
        switch (bp->stratum) {
 
@@ -161,9 +151,7 @@ ntp_print(register const u_char *cp, u_int length)
                break;
 
        case PRIM_REF:
-               strncpy(rclock, (char *)&(bp->refid), 4);
-               rclock[4] = '\0';
-               fputs(rclock, stdout);
+               fn_printn((u_char *)&(bp->refid), 4, NULL);
                break;
 
        case INFO_QUERY:
@@ -210,8 +198,8 @@ p_sfix(register const struct s_fixedpt *sfp)
        register int f;
        register float ff;
 
-       i = ntohs(sfp->int_part);
-       f = ntohs(sfp->fraction);
+       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 */
        printf("%d.%06d", i, f);
@@ -227,8 +215,8 @@ p_ntp_time(register const struct l_fixedpt *lfp)
        register u_int32_t f;
        register float ff;
 
-       i = ntohl(lfp->int_part);
-       uf = ntohl(lfp->fraction);
+       i = EXTRACT_32BITS(&lfp->int_part);
+       uf = EXTRACT_32BITS(&lfp->fraction);
        ff = uf;
        if (ff < 0.0)           /* some compilers are buggy */
                ff += FMAXINT;
@@ -249,10 +237,10 @@ p_ntp_delta(register const struct l_fixedpt *olfp,
        register float ff;
        int signbit;
 
-       i = ntohl(lfp->int_part) - ntohl(olfp->int_part);
+       i = EXTRACT_32BITS(&lfp->int_part) - EXTRACT_32BITS(&olfp->int_part);
 
-       uf = ntohl(lfp->fraction);
-       ouf = ntohl(olfp->fraction);
+       uf = EXTRACT_32BITS(&lfp->fraction);
+       ouf = EXTRACT_32BITS(&olfp->fraction);
 
        if (i > 0) {            /* new is definitely greater than old */
                signbit = 0;
@@ -286,3 +274,4 @@ p_ntp_delta(register const struct l_fixedpt *olfp,
                putchar('+');
        printf("%d.%09d", i, f);
 }
+