Deleted Added
sdiff udiff text old ( 111729 ) new ( 127675 )
full compact
1/*
2 * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and

--- 8 unchanged lines hidden (view full) ---

17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 *
21 * Format and print ntp packets.
22 * By Jeffrey Mogul/DECWRL
23 * loosely based on print-bootp.c
24 *
25 * $FreeBSD: head/contrib/tcpdump/print-ntp.c 111729 2003-03-02 08:25:48Z fenner $
26 */
27
28#ifndef lint
29static const char rcsid[] =
30 "@(#) $Header: /tcpdump/master/tcpdump/print-ntp.c,v 1.32.4.1 2002/07/10 07:13:37 guy Exp $ (LBL)";
31#endif
32
33#ifdef HAVE_CONFIG_H
34#include "config.h"
35#endif
36
37#include <sys/param.h>
38#include <sys/time.h>
39#include <sys/socket.h>
40
41#include <netinet/in.h>
42
43#include <ctype.h>
44#include <stdio.h>
45#include <string.h>
46
47#include "interface.h"
48#include "addrtoname.h"
49#ifdef MODEMASK
50#undef MODEMASK /* Solaris sucks */
51#endif
52#include "ntp.h"
53
54static void p_sfix(const struct s_fixedpt *);
55static void p_ntp_time(const struct l_fixedpt *);
56static void p_ntp_delta(const struct l_fixedpt *, const struct l_fixedpt *);

--- 10 unchanged lines hidden (view full) ---

67 bp = (struct ntpdata *)cp;
68 /* Note funny sized packets */
69 if (length != sizeof(struct ntpdata))
70 (void)printf(" [len=%d]", length);
71
72 TCHECK(bp->status);
73
74 version = (int)(bp->status & VERSIONMASK) >> 3;
75 printf(" v%d", version);
76
77 leapind = bp->status & LEAPMASK;
78 switch (leapind) {
79
80 case NO_WARNING:
81 break;
82
83 case PLUS_SEC:

--- 38 unchanged lines hidden (view full) ---

122
123 case MODE_RES2: /* reserved */
124 fputs(" res2", stdout);
125 break;
126
127 }
128
129 TCHECK(bp->stratum);
130 printf(" strat %d", bp->stratum);
131
132 TCHECK(bp->ppoll);
133 printf(" poll %d", bp->ppoll);
134
135 /* Can't TCHECK bp->precision bitfield so bp->distance + 0 instead */
136 TCHECK2(bp->distance, 0);
137 printf(" prec %d", bp->precision);
138
139 if (!vflag)
140 return;
141
142 TCHECK(bp->distance);
143 fputs(" dist ", stdout);
144 p_sfix(&bp->distance);
145
146 TCHECK(bp->dispersion);
147 fputs(" disp ", stdout);
148 p_sfix(&bp->dispersion);
149
150 TCHECK(bp->refid);
151 fputs(" ref ", stdout);
152 /* Interpretation depends on stratum */
153 switch (bp->stratum) {
154
155 case UNSPECIFIED:
156 printf("(unspec)");
157 break;
158
159 case PRIM_REF:

--- 39 unchanged lines hidden (view full) ---

199
200static void
201p_sfix(register const struct s_fixedpt *sfp)
202{
203 register int i;
204 register int f;
205 register float ff;
206
207 i = ntohs(sfp->int_part);
208 f = ntohs(sfp->fraction);
209 ff = f / 65536.0; /* shift radix point by 16 bits */
210 f = ff * 1000000.0; /* Treat fraction as parts per million */
211 printf("%d.%06d", i, f);
212}
213
214#define FMAXINT (4294967296.0) /* floating point rep. of MAXINT */
215
216static void
217p_ntp_time(register const struct l_fixedpt *lfp)
218{
219 register int32_t i;
220 register u_int32_t uf;
221 register u_int32_t f;
222 register float ff;
223
224 i = ntohl(lfp->int_part);
225 uf = ntohl(lfp->fraction);
226 ff = uf;
227 if (ff < 0.0) /* some compilers are buggy */
228 ff += FMAXINT;
229 ff = ff / FMAXINT; /* shift radix point by 32 bits */
230 f = ff * 1000000000.0; /* treat fraction as parts per billion */
231 printf("%u.%09d", i, f);
232}
233
234/* Prints time difference between *lfp and *olfp */
235static void
236p_ntp_delta(register const struct l_fixedpt *olfp,
237 register const struct l_fixedpt *lfp)
238{
239 register int32_t i;
240 register u_int32_t uf;
241 register u_int32_t ouf;
242 register u_int32_t f;
243 register float ff;
244 int signbit;
245
246 i = ntohl(lfp->int_part) - ntohl(olfp->int_part);
247
248 uf = ntohl(lfp->fraction);
249 ouf = ntohl(olfp->fraction);
250
251 if (i > 0) { /* new is definitely greater than old */
252 signbit = 0;
253 f = uf - ouf;
254 if (ouf > uf) /* must borrow from high-order bits */
255 i -= 1;
256 } else if (i < 0) { /* new is definitely less than old */
257 signbit = 1;

--- 17 unchanged lines hidden (view full) ---

275 ff = ff / FMAXINT; /* shift radix point by 32 bits */
276 f = ff * 1000000000.0; /* treat fraction as parts per billion */
277 if (signbit)
278 putchar('-');
279 else
280 putchar('+');
281 printf("%d.%09d", i, f);
282}