Deleted Added
full compact
print-ntp.c (127675) print-ntp.c (146778)
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 *
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 127675 2004-03-31 14:57:24Z bms $
25 * $FreeBSD: head/contrib/tcpdump/print-ntp.c 146778 2005-05-29 19:09:28Z sam $
26 */
27
28#ifndef lint
29static const char rcsid[] _U_ =
26 */
27
28#ifndef lint
29static const char rcsid[] _U_ =
30 "@(#) $Header: /tcpdump/master/tcpdump/print-ntp.c,v 1.37.2.2 2003/11/16 08:51:36 guy Exp $ (LBL)";
30 "@(#) $Header: /tcpdump/master/tcpdump/print-ntp.c,v 1.41 2004/01/28 14:54:50 hannes Exp $ (LBL)";
31#endif
32
33#ifdef HAVE_CONFIG_H
34#include "config.h"
35#endif
36
37#include <tcpdump-stdinc.h>
38

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

49#undef MODEMASK /* Solaris sucks */
50#endif
51#include "ntp.h"
52
53static void p_sfix(const struct s_fixedpt *);
54static void p_ntp_time(const struct l_fixedpt *);
55static void p_ntp_delta(const struct l_fixedpt *, const struct l_fixedpt *);
56
31#endif
32
33#ifdef HAVE_CONFIG_H
34#include "config.h"
35#endif
36
37#include <tcpdump-stdinc.h>
38

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

49#undef MODEMASK /* Solaris sucks */
50#endif
51#include "ntp.h"
52
53static void p_sfix(const struct s_fixedpt *);
54static void p_ntp_time(const struct l_fixedpt *);
55static void p_ntp_delta(const struct l_fixedpt *, const struct l_fixedpt *);
56
57static struct tok ntp_mode_values[] = {
58 { MODE_UNSPEC, "unspecified" },
59 { MODE_SYM_ACT, "symmetric active" },
60 { MODE_SYM_PAS, "symmetric passive" },
61 { MODE_CLIENT, "Client" },
62 { MODE_SERVER, "Server" },
63 { MODE_BROADCAST, "Broadcast" },
64 { MODE_RES1, "Reserved" },
65 { MODE_RES2, "Reserved" },
66 { 0, NULL }
67};
68
69static struct tok ntp_leapind_values[] = {
70 { NO_WARNING, "" },
71 { PLUS_SEC, "+1s" },
72 { MINUS_SEC, "-1s" },
73 { ALARM, "clock unsynchronized" },
74 { 0, NULL }
75};
76
57/*
58 * Print ntp requests
59 */
60void
61ntp_print(register const u_char *cp, u_int length)
62{
63 register const struct ntpdata *bp;
64 int mode, version, leapind;
65
66 bp = (struct ntpdata *)cp;
77/*
78 * Print ntp requests
79 */
80void
81ntp_print(register const u_char *cp, u_int length)
82{
83 register const struct ntpdata *bp;
84 int mode, version, leapind;
85
86 bp = (struct ntpdata *)cp;
67 /* Note funny sized packets */
68 if (length != sizeof(struct ntpdata))
69 (void)printf(" [len=%d]", length);
70
71 TCHECK(bp->status);
72
73 version = (int)(bp->status & VERSIONMASK) >> 3;
74 printf("NTPv%d", version);
75
87
88 TCHECK(bp->status);
89
90 version = (int)(bp->status & VERSIONMASK) >> 3;
91 printf("NTPv%d", version);
92
76 leapind = bp->status & LEAPMASK;
77 switch (leapind) {
78
79 case NO_WARNING:
80 break;
81
82 case PLUS_SEC:
83 fputs(" +1s", stdout);
84 break;
85
86 case MINUS_SEC:
87 fputs(" -1s", stdout);
88 break;
89 }
90
91 mode = bp->status & MODEMASK;
93 mode = bp->status & MODEMASK;
92 switch (mode) {
94 if (!vflag) {
95 printf (", %s, length %u",
96 tok2str(ntp_mode_values, "Unknown mode", mode),
97 length);
98 return;
99 }
100
101 printf (", length %u\n\t%s",
102 length,
103 tok2str(ntp_mode_values, "Unknown mode", mode));
93
104
94 case MODE_UNSPEC: /* unspecified */
95 fputs(" unspec", stdout);
96 break;
105 leapind = bp->status & LEAPMASK;
106 printf (", Leap indicator: %s (%u)",
107 tok2str(ntp_leapind_values, "Unknown", leapind),
108 leapind);
97
109
98 case MODE_SYM_ACT: /* symmetric active */
99 fputs(" sym_act", stdout);
100 break;
101
102 case MODE_SYM_PAS: /* symmetric passive */
103 fputs(" sym_pas", stdout);
104 break;
105
106 case MODE_CLIENT: /* client */
107 fputs(" client", stdout);
108 break;
109
110 case MODE_SERVER: /* server */
111 fputs(" server", stdout);
112 break;
113
114 case MODE_BROADCAST: /* broadcast */
115 fputs(" bcast", stdout);
116 break;
117
118 case MODE_RES1: /* reserved */
119 fputs(" res1", stdout);
120 break;
121
122 case MODE_RES2: /* reserved */
123 fputs(" res2", stdout);
124 break;
125
126 }
127
128 TCHECK(bp->stratum);
110 TCHECK(bp->stratum);
129 printf(", strat %d", bp->stratum);
111 printf(", Stratum %u", bp->stratum);
130
131 TCHECK(bp->ppoll);
112
113 TCHECK(bp->ppoll);
132 printf(", poll %d", bp->ppoll);
114 printf(", poll %us", bp->ppoll);
133
134 /* Can't TCHECK bp->precision bitfield so bp->distance + 0 instead */
115
116 /* Can't TCHECK bp->precision bitfield so bp->distance + 0 instead */
135 TCHECK2(bp->distance, 0);
136 printf(", prec %d", bp->precision);
117 TCHECK2(bp->root_delay, 0);
118 printf(", precision %d", bp->precision);
137
119
138 if (!vflag)
139 return;
120 TCHECK(bp->root_delay);
121 fputs("\n\tRoot Delay: ", stdout);
122 p_sfix(&bp->root_delay);
140
123
141 TCHECK(bp->distance);
142 fputs(" dist ", stdout);
143 p_sfix(&bp->distance);
124 TCHECK(bp->root_dispersion);
125 fputs(", Root dispersion: ", stdout);
126 p_sfix(&bp->root_dispersion);
144
127
145 TCHECK(bp->dispersion);
146 fputs(", disp ", stdout);
147 p_sfix(&bp->dispersion);
148
149 TCHECK(bp->refid);
128 TCHECK(bp->refid);
150 fputs(", ref ", stdout);
129 fputs(", Reference-ID: ", stdout);
151 /* Interpretation depends on stratum */
152 switch (bp->stratum) {
153
154 case UNSPECIFIED:
155 printf("(unspec)");
156 break;
157
158 case PRIM_REF:

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

169 /* this is too complex to be worth printing */
170 return;
171
172 default:
173 printf("%s", ipaddr_string(&(bp->refid)));
174 break;
175 }
176
130 /* Interpretation depends on stratum */
131 switch (bp->stratum) {
132
133 case UNSPECIFIED:
134 printf("(unspec)");
135 break;
136
137 case PRIM_REF:

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

148 /* this is too complex to be worth printing */
149 return;
150
151 default:
152 printf("%s", ipaddr_string(&(bp->refid)));
153 break;
154 }
155
177 TCHECK(bp->reftime);
178 putchar('@');
179 p_ntp_time(&(bp->reftime));
156 TCHECK(bp->ref_timestamp);
157 fputs("\n\t Reference Timestamp: ", stdout);
158 p_ntp_time(&(bp->ref_timestamp));
180
159
181 TCHECK(bp->org);
182 fputs(" orig ", stdout);
183 p_ntp_time(&(bp->org));
160 TCHECK(bp->org_timestamp);
161 fputs("\n\t Originator Timestamp: ", stdout);
162 p_ntp_time(&(bp->org_timestamp));
184
163
185 TCHECK(bp->rec);
186 fputs(" rec ", stdout);
187 p_ntp_delta(&(bp->org), &(bp->rec));
164 TCHECK(bp->rec_timestamp);
165 fputs("\n\t Receive Timestamp: ", stdout);
166 p_ntp_time(&(bp->rec_timestamp));
188
167
189 TCHECK(bp->xmt);
190 fputs(" xmt ", stdout);
191 p_ntp_delta(&(bp->org), &(bp->xmt));
168 TCHECK(bp->xmt_timestamp);
169 fputs("\n\t Transmit Timestamp: ", stdout);
170 p_ntp_time(&(bp->xmt_timestamp));
192
171
172 fputs("\n\t Originator - Receive Timestamp: ", stdout);
173 p_ntp_delta(&(bp->org_timestamp), &(bp->rec_timestamp));
174
175 fputs("\n\t Originator - Transmit Timestamp: ", stdout);
176 p_ntp_delta(&(bp->org_timestamp), &(bp->xmt_timestamp));
177
178 /* FIXME key-id, authentication */
179
193 return;
194
195trunc:
196 fputs(" [|ntp]", stdout);
197}
198
199static void
200p_sfix(register const struct s_fixedpt *sfp)

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

226 if (ff < 0.0) /* some compilers are buggy */
227 ff += FMAXINT;
228 ff = ff / FMAXINT; /* shift radix point by 32 bits */
229 f = ff * 1000000000.0; /* treat fraction as parts per billion */
230 printf("%u.%09d", i, f);
231
232#ifdef HAVE_STRFTIME
233 /*
180 return;
181
182trunc:
183 fputs(" [|ntp]", stdout);
184}
185
186static void
187p_sfix(register const struct s_fixedpt *sfp)

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

213 if (ff < 0.0) /* some compilers are buggy */
214 ff += FMAXINT;
215 ff = ff / FMAXINT; /* shift radix point by 32 bits */
216 f = ff * 1000000000.0; /* treat fraction as parts per billion */
217 printf("%u.%09d", i, f);
218
219#ifdef HAVE_STRFTIME
220 /*
234 * For extra verbosity, print the time in human-readable format.
221 * print the time in human-readable format.
235 */
222 */
236 if (vflag > 1 && i) {
223 if (i) {
237 time_t seconds = i - JAN_1970;
238 struct tm *tm;
239 char time_buf[128];
240
241 tm = localtime(&seconds);
242 strftime(time_buf, sizeof (time_buf), "%Y/%m/%d %H:%M:%S", tm);
243 printf (" (%s)", time_buf);
244 }

--- 59 unchanged lines hidden ---
224 time_t seconds = i - JAN_1970;
225 struct tm *tm;
226 char time_buf[128];
227
228 tm = localtime(&seconds);
229 strftime(time_buf, sizeof (time_buf), "%Y/%m/%d %H:%M:%S", tm);
230 printf (" (%s)", time_buf);
231 }

--- 59 unchanged lines hidden ---