Deleted Added
full compact
print-udp.c (98527) print-udp.c (127675)
1/*
2 * Copyright (c) 1988, 1989, 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

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

13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
16 * written permission.
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 *
1/*
2 * Copyright (c) 1988, 1989, 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

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

13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
16 * written permission.
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 * $FreeBSD: head/contrib/tcpdump/print-udp.c 98527 2002-06-21 00:49:02Z fenner $
21 * $FreeBSD: head/contrib/tcpdump/print-udp.c 127675 2004-03-31 14:57:24Z bms $
22 */
23
24#ifndef lint
22 */
23
24#ifndef lint
25static const char rcsid[] =
26 "@(#) $Header: /tcpdump/master/tcpdump/print-udp.c,v 1.101 2001/10/08 21:25:24 fenner Exp $ (LBL)";
25static const char rcsid[] _U_ =
26 "@(#) $Header: /tcpdump/master/tcpdump/print-udp.c,v 1.124.2.5 2003/11/19 00:19:25 guy Exp $ (LBL)";
27#endif
28
29#ifdef HAVE_CONFIG_H
30#include "config.h"
31#endif
32
27#endif
28
29#ifdef HAVE_CONFIG_H
30#include "config.h"
31#endif
32
33#include <sys/param.h>
34#include <sys/time.h>
33#include <tcpdump-stdinc.h>
35
34
36#include <netinet/in.h>
37
38#ifdef SEGSIZE
39#undef SEGSIZE
40#endif
41#include <arpa/tftp.h>
42
43#include <rpc/rpc.h>
44
45#include <stdio.h>
46#include <string.h>
47
48#include "interface.h"
49#include "addrtoname.h"
35#ifdef SEGSIZE
36#undef SEGSIZE
37#endif
38#include <arpa/tftp.h>
39
40#include <rpc/rpc.h>
41
42#include <stdio.h>
43#include <string.h>
44
45#include "interface.h"
46#include "addrtoname.h"
47#include "extract.h"
50#include "appletalk.h"
51
52#include "udp.h"
53
54#include "ip.h"
55#ifdef INET6
56#include "ip6.h"
57#endif
48#include "appletalk.h"
49
50#include "udp.h"
51
52#include "ip.h"
53#ifdef INET6
54#include "ip6.h"
55#endif
56#include "ipproto.h"
58
59#include "nameser.h"
60#include "nfs.h"
61#include "bootp.h"
62
63struct rtcphdr {
64 u_int16_t rh_flags; /* T:2 P:1 CNT:5 PT:8 */
65 u_int16_t rh_len; /* length of message (in words) */

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

105#define RTCP_SDES_LOC 5
106#define RTCP_SDES_TOOL 6
107#define RTCP_SDES_NOTE 7
108#define RTCP_SDES_PRIV 8
109#define RTCP_PT_BYE 203
110#define RTCP_PT_APP 204
111
112static void
57
58#include "nameser.h"
59#include "nfs.h"
60#include "bootp.h"
61
62struct rtcphdr {
63 u_int16_t rh_flags; /* T:2 P:1 CNT:5 PT:8 */
64 u_int16_t rh_len; /* length of message (in words) */

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

104#define RTCP_SDES_LOC 5
105#define RTCP_SDES_TOOL 6
106#define RTCP_SDES_NOTE 7
107#define RTCP_SDES_PRIV 8
108#define RTCP_PT_BYE 203
109#define RTCP_PT_APP 204
110
111static void
113vat_print(const void *hdr, u_int len, register const struct udphdr *up)
112vat_print(const void *hdr, register const struct udphdr *up)
114{
115 /* vat/vt audio */
116 u_int ts = *(u_int16_t *)hdr;
117 if ((ts & 0xf060) != 0) {
118 /* probably vt */
119 (void)printf("udp/vt %u %d / %d",
113{
114 /* vat/vt audio */
115 u_int ts = *(u_int16_t *)hdr;
116 if ((ts & 0xf060) != 0) {
117 /* probably vt */
118 (void)printf("udp/vt %u %d / %d",
120 (u_int32_t)(ntohs(up->uh_ulen) - sizeof(*up)),
119 (u_int32_t)(EXTRACT_16BITS(&up->uh_ulen) - sizeof(*up)),
121 ts & 0x3ff, ts >> 10);
122 } else {
123 /* probably vat */
120 ts & 0x3ff, ts >> 10);
121 } else {
122 /* probably vat */
124 u_int32_t i0 = (u_int32_t)ntohl(((u_int *)hdr)[0]);
125 u_int32_t i1 = (u_int32_t)ntohl(((u_int *)hdr)[1]);
123 u_int32_t i0 = EXTRACT_32BITS(&((u_int *)hdr)[0]);
124 u_int32_t i1 = EXTRACT_32BITS(&((u_int *)hdr)[1]);
126 printf("udp/vat %u c%d %u%s",
125 printf("udp/vat %u c%d %u%s",
127 (u_int32_t)(ntohs(up->uh_ulen) - sizeof(*up) - 8),
126 (u_int32_t)(EXTRACT_16BITS(&up->uh_ulen) - sizeof(*up) - 8),
128 i0 & 0xffff,
129 i1, i0 & 0x800000? "*" : "");
130 /* audio format */
131 if (i0 & 0x1f0000)
132 printf(" f%d", (i0 >> 16) & 0x1f);
133 if (i0 & 0x3f000000)
134 printf(" s%d", (i0 >> 24) & 0x3f);
135 }
136}
137
138static void
139rtp_print(const void *hdr, u_int len, register const struct udphdr *up)
140{
141 /* rtp v1 or v2 */
142 u_int *ip = (u_int *)hdr;
143 u_int hasopt, hasext, contype, hasmarker;
127 i0 & 0xffff,
128 i1, i0 & 0x800000? "*" : "");
129 /* audio format */
130 if (i0 & 0x1f0000)
131 printf(" f%d", (i0 >> 16) & 0x1f);
132 if (i0 & 0x3f000000)
133 printf(" s%d", (i0 >> 24) & 0x3f);
134 }
135}
136
137static void
138rtp_print(const void *hdr, u_int len, register const struct udphdr *up)
139{
140 /* rtp v1 or v2 */
141 u_int *ip = (u_int *)hdr;
142 u_int hasopt, hasext, contype, hasmarker;
144 u_int32_t i0 = (u_int32_t)ntohl(((u_int *)hdr)[0]);
145 u_int32_t i1 = (u_int32_t)ntohl(((u_int *)hdr)[1]);
146 u_int dlen = ntohs(up->uh_ulen) - sizeof(*up) - 8;
143 u_int32_t i0 = EXTRACT_32BITS(&((u_int *)hdr)[0]);
144 u_int32_t i1 = EXTRACT_32BITS(&((u_int *)hdr)[1]);
145 u_int dlen = EXTRACT_16BITS(&up->uh_ulen) - sizeof(*up) - 8;
147 const char * ptype;
148
149 ip += 2;
150 len >>= 2;
151 len -= 2;
152 hasopt = 0;
153 hasext = 0;
154 if ((i0 >> 30) == 1) {

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

171 ptype,
172 dlen,
173 contype,
174 (hasopt || hasext)? "+" : "",
175 hasmarker? "*" : "",
176 i0 & 0xffff,
177 i1);
178 if (vflag) {
146 const char * ptype;
147
148 ip += 2;
149 len >>= 2;
150 len -= 2;
151 hasopt = 0;
152 hasext = 0;
153 if ((i0 >> 30) == 1) {

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

170 ptype,
171 dlen,
172 contype,
173 (hasopt || hasext)? "+" : "",
174 hasmarker? "*" : "",
175 i0 & 0xffff,
176 i1);
177 if (vflag) {
179 printf(" %u", (u_int32_t)ntohl(((u_int *)hdr)[2]));
178 printf(" %u", EXTRACT_32BITS(&((u_int *)hdr)[2]));
180 if (hasopt) {
181 u_int i2, optlen;
182 do {
183 i2 = ip[0];
184 optlen = (i2 >> 16) & 0xff;
185 if (optlen == 0 || optlen > len) {
186 printf(" !opt");
187 return;

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

215 u_int len;
216 u_int16_t flags;
217 int cnt;
218 double ts, dts;
219 if ((u_char *)(rh + 1) > ep) {
220 printf(" [|rtcp]");
221 return (ep);
222 }
179 if (hasopt) {
180 u_int i2, optlen;
181 do {
182 i2 = ip[0];
183 optlen = (i2 >> 16) & 0xff;
184 if (optlen == 0 || optlen > len) {
185 printf(" !opt");
186 return;

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

214 u_int len;
215 u_int16_t flags;
216 int cnt;
217 double ts, dts;
218 if ((u_char *)(rh + 1) > ep) {
219 printf(" [|rtcp]");
220 return (ep);
221 }
223 len = (ntohs(rh->rh_len) + 1) * 4;
224 flags = ntohs(rh->rh_flags);
222 len = (EXTRACT_16BITS(&rh->rh_len) + 1) * 4;
223 flags = EXTRACT_16BITS(&rh->rh_flags);
225 cnt = (flags >> 8) & 0x1f;
226 switch (flags & 0xff) {
227 case RTCP_PT_SR:
228 sr = (struct rtcp_sr *)(rh + 1);
229 printf(" sr");
230 if (len != cnt * sizeof(*rr) + sizeof(*sr) + sizeof(*rh))
231 printf(" [%d]", len);
232 if (vflag)
224 cnt = (flags >> 8) & 0x1f;
225 switch (flags & 0xff) {
226 case RTCP_PT_SR:
227 sr = (struct rtcp_sr *)(rh + 1);
228 printf(" sr");
229 if (len != cnt * sizeof(*rr) + sizeof(*sr) + sizeof(*rh))
230 printf(" [%d]", len);
231 if (vflag)
233 printf(" %u", (u_int32_t)ntohl(rh->rh_ssrc));
232 printf(" %u", EXTRACT_32BITS(&rh->rh_ssrc));
234 if ((u_char *)(sr + 1) > ep) {
235 printf(" [|rtcp]");
236 return (ep);
237 }
233 if ((u_char *)(sr + 1) > ep) {
234 printf(" [|rtcp]");
235 return (ep);
236 }
238 ts = (double)((u_int32_t)ntohl(sr->sr_ntp.upper)) +
239 ((double)((u_int32_t)ntohl(sr->sr_ntp.lower)) /
237 ts = (double)(EXTRACT_32BITS(&sr->sr_ntp.upper)) +
238 ((double)(EXTRACT_32BITS(&sr->sr_ntp.lower)) /
240 4294967296.0);
239 4294967296.0);
241 printf(" @%.2f %u %up %ub", ts, (u_int32_t)ntohl(sr->sr_ts),
242 (u_int32_t)ntohl(sr->sr_np), (u_int32_t)ntohl(sr->sr_nb));
240 printf(" @%.2f %u %up %ub", ts, EXTRACT_32BITS(&sr->sr_ts),
241 EXTRACT_32BITS(&sr->sr_np), EXTRACT_32BITS(&sr->sr_nb));
243 rr = (struct rtcp_rr *)(sr + 1);
244 break;
245 case RTCP_PT_RR:
246 printf(" rr");
247 if (len != cnt * sizeof(*rr) + sizeof(*rh))
248 printf(" [%d]", len);
249 rr = (struct rtcp_rr *)(rh + 1);
250 if (vflag)
242 rr = (struct rtcp_rr *)(sr + 1);
243 break;
244 case RTCP_PT_RR:
245 printf(" rr");
246 if (len != cnt * sizeof(*rr) + sizeof(*rh))
247 printf(" [%d]", len);
248 rr = (struct rtcp_rr *)(rh + 1);
249 if (vflag)
251 printf(" %u", (u_int32_t)ntohl(rh->rh_ssrc));
250 printf(" %u", EXTRACT_32BITS(&rh->rh_ssrc));
252 break;
253 case RTCP_PT_SDES:
254 printf(" sdes %d", len);
255 if (vflag)
251 break;
252 case RTCP_PT_SDES:
253 printf(" sdes %d", len);
254 if (vflag)
256 printf(" %u", (u_int32_t)ntohl(rh->rh_ssrc));
255 printf(" %u", EXTRACT_32BITS(&rh->rh_ssrc));
257 cnt = 0;
258 break;
259 case RTCP_PT_BYE:
260 printf(" bye %d", len);
261 if (vflag)
256 cnt = 0;
257 break;
258 case RTCP_PT_BYE:
259 printf(" bye %d", len);
260 if (vflag)
262 printf(" %u", (u_int32_t)ntohl(rh->rh_ssrc));
261 printf(" %u", EXTRACT_32BITS(&rh->rh_ssrc));
263 cnt = 0;
264 break;
265 default:
266 printf(" type-0x%x %d", flags & 0xff, len);
267 cnt = 0;
268 break;
269 }
270 if (cnt > 1)
271 printf(" c%d", cnt);
272 while (--cnt >= 0) {
273 if ((u_char *)(rr + 1) > ep) {
274 printf(" [|rtcp]");
275 return (ep);
276 }
277 if (vflag)
262 cnt = 0;
263 break;
264 default:
265 printf(" type-0x%x %d", flags & 0xff, len);
266 cnt = 0;
267 break;
268 }
269 if (cnt > 1)
270 printf(" c%d", cnt);
271 while (--cnt >= 0) {
272 if ((u_char *)(rr + 1) > ep) {
273 printf(" [|rtcp]");
274 return (ep);
275 }
276 if (vflag)
278 printf(" %u", (u_int32_t)ntohl(rr->rr_srcid));
279 ts = (double)((u_int32_t)ntohl(rr->rr_lsr)) / 65536.;
280 dts = (double)((u_int32_t)ntohl(rr->rr_dlsr)) / 65536.;
277 printf(" %u", EXTRACT_32BITS(&rr->rr_srcid));
278 ts = (double)(EXTRACT_32BITS(&rr->rr_lsr)) / 65536.;
279 dts = (double)(EXTRACT_32BITS(&rr->rr_dlsr)) / 65536.;
281 printf(" %ul %us %uj @%.2f+%.2f",
280 printf(" %ul %us %uj @%.2f+%.2f",
282 (u_int32_t)ntohl(rr->rr_nl) & 0x00ffffff,
283 (u_int32_t)ntohl(rr->rr_ls),
284 (u_int32_t)ntohl(rr->rr_dv), ts, dts);
281 EXTRACT_32BITS(&rr->rr_nl) & 0x00ffffff,
282 EXTRACT_32BITS(&rr->rr_ls),
283 EXTRACT_32BITS(&rr->rr_dv), ts, dts);
285 }
286 return (hdr + len);
287}
288
289static int udp_cksum(register const struct ip *ip,
290 register const struct udphdr *up,
284 }
285 return (hdr + len);
286}
287
288static int udp_cksum(register const struct ip *ip,
289 register const struct udphdr *up,
291 register int len)
290 register u_int len)
292{
293 union phu {
294 struct phdr {
295 u_int32_t src;
296 u_int32_t dst;
297 u_char mbz;
298 u_char proto;
299 u_int16_t len;
300 } ph;
301 u_int16_t pa[6];
302 } phu;
303 register const u_int16_t *sp;
304
305 /* pseudo-header.. */
291{
292 union phu {
293 struct phdr {
294 u_int32_t src;
295 u_int32_t dst;
296 u_char mbz;
297 u_char proto;
298 u_int16_t len;
299 } ph;
300 u_int16_t pa[6];
301 } phu;
302 register const u_int16_t *sp;
303
304 /* pseudo-header.. */
306 phu.ph.len = htons(len);
305 phu.ph.len = htons((u_int16_t)len);
307 phu.ph.mbz = 0;
308 phu.ph.proto = IPPROTO_UDP;
309 memcpy(&phu.ph.src, &ip->ip_src.s_addr, sizeof(u_int32_t));
306 phu.ph.mbz = 0;
307 phu.ph.proto = IPPROTO_UDP;
308 memcpy(&phu.ph.src, &ip->ip_src.s_addr, sizeof(u_int32_t));
310 memcpy(&phu.ph.dst, &ip->ip_dst.s_addr, sizeof(u_int32_t));
309 if (IP_HL(ip) == 5)
310 memcpy(&phu.ph.dst, &ip->ip_dst.s_addr, sizeof(u_int32_t));
311 else
312 phu.ph.dst = ip_finddst(ip);
311
312 sp = &phu.pa[0];
313 return in_cksum((u_short *)up, len,
314 sp[0]+sp[1]+sp[2]+sp[3]+sp[4]+sp[5]);
315}
316
317#ifdef INET6
318static int udp6_cksum(const struct ip6_hdr *ip6, const struct udphdr *up,
313
314 sp = &phu.pa[0];
315 return in_cksum((u_short *)up, len,
316 sp[0]+sp[1]+sp[2]+sp[3]+sp[4]+sp[5]);
317}
318
319#ifdef INET6
320static int udp6_cksum(const struct ip6_hdr *ip6, const struct udphdr *up,
319 int len)
321 u_int len)
320{
322{
321 int i, tlen;
323 size_t i;
322 register const u_int16_t *sp;
323 u_int32_t sum;
324 union {
325 struct {
326 struct in6_addr ph_src;
327 struct in6_addr ph_dst;
328 u_int32_t ph_len;
329 u_int8_t ph_zero[3];
330 u_int8_t ph_nxt;
331 } ph;
332 u_int16_t pa[20];
333 } phu;
334
324 register const u_int16_t *sp;
325 u_int32_t sum;
326 union {
327 struct {
328 struct in6_addr ph_src;
329 struct in6_addr ph_dst;
330 u_int32_t ph_len;
331 u_int8_t ph_zero[3];
332 u_int8_t ph_nxt;
333 } ph;
334 u_int16_t pa[20];
335 } phu;
336
335 tlen = ntohs(ip6->ip6_plen) + sizeof(struct ip6_hdr) -
336 ((const char *)up - (const char*)ip6);
337
338 /* pseudo-header */
339 memset(&phu, 0, sizeof(phu));
340 phu.ph.ph_src = ip6->ip6_src;
341 phu.ph.ph_dst = ip6->ip6_dst;
337 /* pseudo-header */
338 memset(&phu, 0, sizeof(phu));
339 phu.ph.ph_src = ip6->ip6_src;
340 phu.ph.ph_dst = ip6->ip6_dst;
342 phu.ph.ph_len = htonl(tlen);
341 phu.ph.ph_len = htonl(len);
343 phu.ph.ph_nxt = IPPROTO_UDP;
344
345 sum = 0;
346 for (i = 0; i < sizeof(phu.pa) / sizeof(phu.pa[0]); i++)
347 sum += phu.pa[i];
348
349 sp = (const u_int16_t *)up;
350
342 phu.ph.ph_nxt = IPPROTO_UDP;
343
344 sum = 0;
345 for (i = 0; i < sizeof(phu.pa) / sizeof(phu.pa[0]); i++)
346 sum += phu.pa[i];
347
348 sp = (const u_int16_t *)up;
349
351 for (i = 0; i < (tlen & ~1); i += 2)
350 for (i = 0; i < (len & ~1); i += 2)
352 sum += *sp++;
353
351 sum += *sp++;
352
354 if (tlen & 1)
353 if (len & 1)
355 sum += htons((*(const u_int8_t *)sp) << 8);
356
357 while (sum > 0xffff)
358 sum = (sum & 0xffff) + (sum >> 16);
359 sum = ~sum & 0xffff;
360
361 return (sum);
362}
363#endif
364
354 sum += htons((*(const u_int8_t *)sp) << 8);
355
356 while (sum > 0xffff)
357 sum = (sum & 0xffff) + (sum >> 16);
358 sum = ~sum & 0xffff;
359
360 return (sum);
361}
362#endif
363
364static void
365udpipaddr_print(const struct ip *ip, int sport, int dport)
366{
367#ifdef INET6
368 const struct ip6_hdr *ip6;
365
369
366/* XXX probably should use getservbyname() and cache answers */
367#define TFTP_PORT 69 /*XXX*/
368#define KERBEROS_PORT 88 /*XXX*/
369#define SUNRPC_PORT 111 /*XXX*/
370#define SNMP_PORT 161 /*XXX*/
371#define NTP_PORT 123 /*XXX*/
372#define SNMPTRAP_PORT 162 /*XXX*/
373#define ISAKMP_PORT 500 /*XXX*/
374#define TIMED_PORT 525 /*XXX*/
375#define RIP_PORT 520 /*XXX*/
376#define KERBEROS_SEC_PORT 750 /*XXX*/
377#define L2TP_PORT 1701 /*XXX*/
378#define ISAKMP_PORT_USER1 7500 /*XXX - nonstandard*/
379#define ISAKMP_PORT_USER2 8500 /*XXX - nonstandard*/
380#define RX_PORT_LOW 7000 /*XXX*/
381#define RX_PORT_HIGH 7009 /*XXX*/
382#define NETBIOS_NS_PORT 137
383#define NETBIOS_DGRAM_PORT 138
384#define CISCO_AUTORP_PORT 496 /*XXX*/
385#define RADIUS_PORT 1645
386#define RADIUS_NEW_PORT 1812
387#define RADIUS_ACCOUNTING_PORT 1646
388#define RADIUS_NEW_ACCOUNTING_PORT 1813
389#define HSRP_PORT 1985 /*XXX*/
390#define LWRES_PORT 921
391#define ZEPHYR_SRV_PORT 2103
392#define ZEPHYR_CLT_PORT 2104
370 if (IP_V(ip) == 6)
371 ip6 = (const struct ip6_hdr *)ip;
372 else
373 ip6 = NULL;
393
374
394#ifdef INET6
395#define RIPNG_PORT 521 /*XXX*/
396#define DHCP6_SERV_PORT 546 /*XXX*/
397#define DHCP6_CLI_PORT 547 /*XXX*/
398#endif
375 if (ip6) {
376 if (ip6->ip6_nxt == IPPROTO_UDP) {
377 if (sport == -1) {
378 (void)printf("%s > %s: ",
379 ip6addr_string(&ip6->ip6_src),
380 ip6addr_string(&ip6->ip6_dst));
381 } else {
382 (void)printf("%s.%s > %s.%s: ",
383 ip6addr_string(&ip6->ip6_src),
384 udpport_string(sport),
385 ip6addr_string(&ip6->ip6_dst),
386 udpport_string(dport));
387 }
388 } else {
389 if (sport != -1) {
390 (void)printf("%s > %s: ",
391 udpport_string(sport),
392 udpport_string(dport));
393 }
394 }
395 } else
396#endif /*INET6*/
397 {
398 if (ip->ip_p == IPPROTO_UDP) {
399 if (sport == -1) {
400 (void)printf("%s > %s: ",
401 ipaddr_string(&ip->ip_src),
402 ipaddr_string(&ip->ip_dst));
403 } else {
404 (void)printf("%s.%s > %s.%s: ",
405 ipaddr_string(&ip->ip_src),
406 udpport_string(sport),
407 ipaddr_string(&ip->ip_dst),
408 udpport_string(dport));
409 }
410 } else {
411 if (sport != -1) {
412 (void)printf("%s > %s: ",
413 udpport_string(sport),
414 udpport_string(dport));
415 }
416 }
417 }
418}
399
400void
401udp_print(register const u_char *bp, u_int length,
402 register const u_char *bp2, int fragmented)
403{
404 register const struct udphdr *up;
405 register const struct ip *ip;
406 register const u_char *cp;

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

416 ip = (struct ip *)bp2;
417#ifdef INET6
418 if (IP_V(ip) == 6)
419 ip6 = (struct ip6_hdr *)bp2;
420 else
421 ip6 = NULL;
422#endif /*INET6*/
423 cp = (u_char *)(up + 1);
419
420void
421udp_print(register const u_char *bp, u_int length,
422 register const u_char *bp2, int fragmented)
423{
424 register const struct udphdr *up;
425 register const struct ip *ip;
426 register const u_char *cp;

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

436 ip = (struct ip *)bp2;
437#ifdef INET6
438 if (IP_V(ip) == 6)
439 ip6 = (struct ip6_hdr *)bp2;
440 else
441 ip6 = NULL;
442#endif /*INET6*/
443 cp = (u_char *)(up + 1);
424 if (cp > snapend) {
425 (void)printf("%s > %s: [|udp]",
426 ipaddr_string(&ip->ip_src), ipaddr_string(&ip->ip_dst));
444 if (!TTEST(up->uh_dport)) {
445 udpipaddr_print(ip, -1, -1);
446 (void)printf("[|udp]");
427 return;
428 }
447 return;
448 }
449
450 sport = EXTRACT_16BITS(&up->uh_sport);
451 dport = EXTRACT_16BITS(&up->uh_dport);
452
429 if (length < sizeof(struct udphdr)) {
453 if (length < sizeof(struct udphdr)) {
430 (void)printf("%s > %s: truncated-udp %d",
431 ipaddr_string(&ip->ip_src), ipaddr_string(&ip->ip_dst),
432 length);
454 udpipaddr_print(ip, sport, dport);
455 (void)printf("truncated-udp %d", length);
433 return;
434 }
435 length -= sizeof(struct udphdr);
436
456 return;
457 }
458 length -= sizeof(struct udphdr);
459
437 sport = ntohs(up->uh_sport);
438 dport = ntohs(up->uh_dport);
439 ulen = ntohs(up->uh_ulen);
460 if (cp > snapend) {
461 udpipaddr_print(ip, sport, dport);
462 (void)printf("[|udp]");
463 return;
464 }
465
466 ulen = EXTRACT_16BITS(&up->uh_ulen);
440 if (ulen < 8) {
467 if (ulen < 8) {
441 (void)printf("%s > %s: truncated-udplength %d",
442 ipaddr_string(&ip->ip_src),
443 ipaddr_string(&ip->ip_dst),
444 ulen);
468 udpipaddr_print(ip, sport, dport);
469 (void)printf("truncated-udplength %d", ulen);
445 return;
446 }
447 if (packettype) {
448 register struct rpc_msg *rp;
449 enum msg_type direction;
450
451 switch (packettype) {
452
453 case PT_VAT:
470 return;
471 }
472 if (packettype) {
473 register struct rpc_msg *rp;
474 enum msg_type direction;
475
476 switch (packettype) {
477
478 case PT_VAT:
454 (void)printf("%s.%s > %s.%s: ",
455 ipaddr_string(&ip->ip_src),
456 udpport_string(sport),
457 ipaddr_string(&ip->ip_dst),
458 udpport_string(dport));
459 vat_print((void *)(up + 1), length, up);
479 udpipaddr_print(ip, sport, dport);
480 vat_print((void *)(up + 1), up);
460 break;
461
462 case PT_WB:
481 break;
482
483 case PT_WB:
463 (void)printf("%s.%s > %s.%s: ",
464 ipaddr_string(&ip->ip_src),
465 udpport_string(sport),
466 ipaddr_string(&ip->ip_dst),
467 udpport_string(dport));
484 udpipaddr_print(ip, sport, dport);
468 wb_print((void *)(up + 1), length);
469 break;
470
471 case PT_RPC:
472 rp = (struct rpc_msg *)(up + 1);
485 wb_print((void *)(up + 1), length);
486 break;
487
488 case PT_RPC:
489 rp = (struct rpc_msg *)(up + 1);
473 direction = (enum msg_type)ntohl(rp->rm_direction);
490 direction = (enum msg_type)EXTRACT_32BITS(&rp->rm_direction);
474 if (direction == CALL)
475 sunrpcrequest_print((u_char *)rp, length,
476 (u_char *)ip);
477 else
478 nfsreply_print((u_char *)rp, length,
479 (u_char *)ip); /*XXX*/
480 break;
481
482 case PT_RTP:
491 if (direction == CALL)
492 sunrpcrequest_print((u_char *)rp, length,
493 (u_char *)ip);
494 else
495 nfsreply_print((u_char *)rp, length,
496 (u_char *)ip); /*XXX*/
497 break;
498
499 case PT_RTP:
483 (void)printf("%s.%s > %s.%s: ",
484 ipaddr_string(&ip->ip_src),
485 udpport_string(sport),
486 ipaddr_string(&ip->ip_dst),
487 udpport_string(dport));
500 udpipaddr_print(ip, sport, dport);
488 rtp_print((void *)(up + 1), length, up);
489 break;
490
491 case PT_RTCP:
501 rtp_print((void *)(up + 1), length, up);
502 break;
503
504 case PT_RTCP:
492 (void)printf("%s.%s > %s.%s:",
493 ipaddr_string(&ip->ip_src),
494 udpport_string(sport),
495 ipaddr_string(&ip->ip_dst),
496 udpport_string(dport));
505 udpipaddr_print(ip, sport, dport);
497 while (cp < ep)
498 cp = rtcp_print(cp, ep);
499 break;
500
501 case PT_SNMP:
506 while (cp < ep)
507 cp = rtcp_print(cp, ep);
508 break;
509
510 case PT_SNMP:
502 (void)printf("%s.%s > %s.%s:",
503 ipaddr_string(&ip->ip_src),
504 udpport_string(sport),
505 ipaddr_string(&ip->ip_dst),
506 udpport_string(dport));
511 udpipaddr_print(ip, sport, dport);
507 snmp_print((const u_char *)(up + 1), length);
508 break;
509
510 case PT_CNFP:
512 snmp_print((const u_char *)(up + 1), length);
513 break;
514
515 case PT_CNFP:
511 (void)printf("%s.%s > %s.%s:",
512 ipaddr_string(&ip->ip_src),
513 udpport_string(sport),
514 ipaddr_string(&ip->ip_dst),
515 udpport_string(dport));
516 cnfp_print(cp, length, (const u_char *)ip);
516 udpipaddr_print(ip, sport, dport);
517 cnfp_print(cp, (const u_char *)ip);
517 break;
518 break;
519
520 case PT_TFTP:
521 udpipaddr_print(ip, sport, dport);
522 tftp_print(cp, length);
523 break;
524
525 case PT_AODV:
526 udpipaddr_print(ip, sport, dport);
527 aodv_print((const u_char *)(up + 1), length,
528#ifdef INET6
529 ip6 != NULL);
530#else
531 FALSE);
532#endif
533 break;
518 }
519 return;
520 }
521
522 if (!qflag) {
523 register struct rpc_msg *rp;
524 enum msg_type direction;
525
526 rp = (struct rpc_msg *)(up + 1);
527 if (TTEST(rp->rm_direction)) {
534 }
535 return;
536 }
537
538 if (!qflag) {
539 register struct rpc_msg *rp;
540 enum msg_type direction;
541
542 rp = (struct rpc_msg *)(up + 1);
543 if (TTEST(rp->rm_direction)) {
528 direction = (enum msg_type)ntohl(rp->rm_direction);
544 direction = (enum msg_type)EXTRACT_32BITS(&rp->rm_direction);
529 if (dport == NFS_PORT && direction == CALL) {
530 nfsreq_print((u_char *)rp, length,
531 (u_char *)ip);
532 return;
533 }
534 if (sport == NFS_PORT && direction == REPLY) {
535 nfsreply_print((u_char *)rp, length,
536 (u_char *)ip);

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

547 ((struct LAP *)cp)->type == lapDDP &&
548 (atalk_port(sport) || atalk_port(dport))) {
549 if (vflag)
550 fputs("kip ", stdout);
551 llap_print(cp, length);
552 return;
553 }
554 }
545 if (dport == NFS_PORT && direction == CALL) {
546 nfsreq_print((u_char *)rp, length,
547 (u_char *)ip);
548 return;
549 }
550 if (sport == NFS_PORT && direction == REPLY) {
551 nfsreply_print((u_char *)rp, length,
552 (u_char *)ip);

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

563 ((struct LAP *)cp)->type == lapDDP &&
564 (atalk_port(sport) || atalk_port(dport))) {
565 if (vflag)
566 fputs("kip ", stdout);
567 llap_print(cp, length);
568 return;
569 }
570 }
555#ifdef INET6
556 if (ip6) {
557 if (ip6->ip6_nxt == IPPROTO_UDP) {
558 (void)printf("%s.%s > %s.%s: ",
559 ip6addr_string(&ip6->ip6_src),
560 udpport_string(sport),
561 ip6addr_string(&ip6->ip6_dst),
562 udpport_string(dport));
563 } else {
564 (void)printf("%s > %s: ",
565 udpport_string(sport), udpport_string(dport));
566 }
567 } else
568#endif /*INET6*/
569 {
570 if (ip->ip_p == IPPROTO_UDP) {
571 (void)printf("%s.%s > %s.%s: ",
572 ipaddr_string(&ip->ip_src),
573 udpport_string(sport),
574 ipaddr_string(&ip->ip_dst),
575 udpport_string(dport));
576 } else {
577 (void)printf("%s > %s: ",
578 udpport_string(sport), udpport_string(dport));
579 }
580 }
571 udpipaddr_print(ip, sport, dport);
581
582 if (IP_V(ip) == 4 && vflag && !fragmented) {
583 int sum = up->uh_sum;
584 if (sum == 0) {
585 (void)printf("[no cksum] ");
586 } else if (TTEST2(cp[0], length)) {
587 sum = udp_cksum(ip, up, length + sizeof(struct udphdr));
588 if (sum != 0)
589 (void)printf("[bad udp cksum %x!] ", sum);
590 else
591 (void)printf("[udp sum ok] ");
592 }
593 }
594#ifdef INET6
595 if (IP_V(ip) == 6 && ip6->ip6_plen && vflag && !fragmented) {
596 int sum = up->uh_sum;
597 /* for IPv6, UDP checksum is mandatory */
598 if (TTEST2(cp[0], length)) {
572
573 if (IP_V(ip) == 4 && vflag && !fragmented) {
574 int sum = up->uh_sum;
575 if (sum == 0) {
576 (void)printf("[no cksum] ");
577 } else if (TTEST2(cp[0], length)) {
578 sum = udp_cksum(ip, up, length + sizeof(struct udphdr));
579 if (sum != 0)
580 (void)printf("[bad udp cksum %x!] ", sum);
581 else
582 (void)printf("[udp sum ok] ");
583 }
584 }
585#ifdef INET6
586 if (IP_V(ip) == 6 && ip6->ip6_plen && vflag && !fragmented) {
587 int sum = up->uh_sum;
588 /* for IPv6, UDP checksum is mandatory */
589 if (TTEST2(cp[0], length)) {
599 sum = udp6_cksum(ip6, up, length);
590 sum = udp6_cksum(ip6, up, length + sizeof(struct udphdr));
600 if (sum != 0)
601 (void)printf("[bad udp cksum %x!] ", sum);
602 else
603 (void)printf("[udp sum ok] ");
604 }
605 }
606#endif
607
608 if (!qflag) {
609#define ISPORT(p) (dport == (p) || sport == (p))
610 if (ISPORT(NAMESERVER_PORT))
591 if (sum != 0)
592 (void)printf("[bad udp cksum %x!] ", sum);
593 else
594 (void)printf("[udp sum ok] ");
595 }
596 }
597#endif
598
599 if (!qflag) {
600#define ISPORT(p) (dport == (p) || sport == (p))
601 if (ISPORT(NAMESERVER_PORT))
611 ns_print((const u_char *)(up + 1), length);
602 ns_print((const u_char *)(up + 1), length, 0);
603 else if (ISPORT(MULTICASTDNS_PORT))
604 ns_print((const u_char *)(up + 1), length, 1);
612 else if (ISPORT(TIMED_PORT))
605 else if (ISPORT(TIMED_PORT))
613 timed_print((const u_char *)(up + 1), length);
606 timed_print((const u_char *)(up + 1));
614 else if (ISPORT(TFTP_PORT))
615 tftp_print((const u_char *)(up + 1), length);
616 else if (ISPORT(IPPORT_BOOTPC) || ISPORT(IPPORT_BOOTPS))
607 else if (ISPORT(TFTP_PORT))
608 tftp_print((const u_char *)(up + 1), length);
609 else if (ISPORT(IPPORT_BOOTPC) || ISPORT(IPPORT_BOOTPS))
617 bootp_print((const u_char *)(up + 1), length,
618 sport, dport);
610 bootp_print((const u_char *)(up + 1), length);
619 else if (ISPORT(RIP_PORT))
620 rip_print((const u_char *)(up + 1), length);
611 else if (ISPORT(RIP_PORT))
612 rip_print((const u_char *)(up + 1), length);
613 else if (ISPORT(AODV_PORT))
614 aodv_print((const u_char *)(up + 1), length,
615#ifdef INET6
616 ip6 != NULL);
617#else
618 FALSE);
619#endif
621 else if (ISPORT(ISAKMP_PORT))
622 isakmp_print((const u_char *)(up + 1), length, bp2);
623#if 1 /*???*/
624 else if (ISPORT(ISAKMP_PORT_USER1) || ISPORT(ISAKMP_PORT_USER2))
625 isakmp_print((const u_char *)(up + 1), length, bp2);
626#endif
627 else if (ISPORT(SNMP_PORT) || ISPORT(SNMPTRAP_PORT))
628 snmp_print((const u_char *)(up + 1), length);
629 else if (ISPORT(NTP_PORT))
630 ntp_print((const u_char *)(up + 1), length);
631 else if (ISPORT(KERBEROS_PORT) || ISPORT(KERBEROS_SEC_PORT))
620 else if (ISPORT(ISAKMP_PORT))
621 isakmp_print((const u_char *)(up + 1), length, bp2);
622#if 1 /*???*/
623 else if (ISPORT(ISAKMP_PORT_USER1) || ISPORT(ISAKMP_PORT_USER2))
624 isakmp_print((const u_char *)(up + 1), length, bp2);
625#endif
626 else if (ISPORT(SNMP_PORT) || ISPORT(SNMPTRAP_PORT))
627 snmp_print((const u_char *)(up + 1), length);
628 else if (ISPORT(NTP_PORT))
629 ntp_print((const u_char *)(up + 1), length);
630 else if (ISPORT(KERBEROS_PORT) || ISPORT(KERBEROS_SEC_PORT))
632 krb_print((const void *)(up + 1), length);
631 krb_print((const void *)(up + 1));
633 else if (ISPORT(L2TP_PORT))
634 l2tp_print((const u_char *)(up + 1), length);
635#ifdef TCPDUMP_DO_SMB
632 else if (ISPORT(L2TP_PORT))
633 l2tp_print((const u_char *)(up + 1), length);
634#ifdef TCPDUMP_DO_SMB
636 else if (ISPORT(NETBIOS_NS_PORT))
635 else if (ISPORT(NETBIOS_NS_PORT))
637 nbt_udp137_print((const u_char *)(up + 1), length);
636 nbt_udp137_print((const u_char *)(up + 1), length);
638 else if (ISPORT(NETBIOS_DGRAM_PORT))
639 nbt_udp138_print((const u_char *)(up + 1), length);
637 else if (ISPORT(NETBIOS_DGRAM_PORT))
638 nbt_udp138_print((const u_char *)(up + 1), length);
640#endif
641 else if (dport == 3456)
639#endif
640 else if (dport == 3456)
642 vat_print((const void *)(up + 1), length, up);
641 vat_print((const void *)(up + 1), up);
643 else if (ISPORT(ZEPHYR_SRV_PORT) || ISPORT(ZEPHYR_CLT_PORT))
644 zephyr_print((const void *)(up + 1), length);
642 else if (ISPORT(ZEPHYR_SRV_PORT) || ISPORT(ZEPHYR_CLT_PORT))
643 zephyr_print((const void *)(up + 1), length);
645 /*
646 * Since there are 10 possible ports to check, I think
647 * a <> test would be more efficient
648 */
649 else if ((sport >= RX_PORT_LOW && sport <= RX_PORT_HIGH) ||
650 (dport >= RX_PORT_LOW && dport <= RX_PORT_HIGH))
651 rx_print((const void *)(up + 1), length, sport, dport,
652 (u_char *) ip);
644 /*
645 * Since there are 10 possible ports to check, I think
646 * a <> test would be more efficient
647 */
648 else if ((sport >= RX_PORT_LOW && sport <= RX_PORT_HIGH) ||
649 (dport >= RX_PORT_LOW && dport <= RX_PORT_HIGH))
650 rx_print((const void *)(up + 1), length, sport, dport,
651 (u_char *) ip);
653#ifdef INET6
654 else if (ISPORT(RIPNG_PORT))
655 ripng_print((const u_char *)(up + 1), length);
656 else if (ISPORT(DHCP6_SERV_PORT) || ISPORT(DHCP6_CLI_PORT)) {
652#ifdef INET6
653 else if (ISPORT(RIPNG_PORT))
654 ripng_print((const u_char *)(up + 1), length);
655 else if (ISPORT(DHCP6_SERV_PORT) || ISPORT(DHCP6_CLI_PORT)) {
657 dhcp6_print((const u_char *)(up + 1), length,
658 sport, dport);
656 dhcp6_print((const u_char *)(up + 1), length);
659 }
660#endif /*INET6*/
661 /*
662 * Kludge in test for whiteboard packets.
663 */
664 else if (dport == 4567)
665 wb_print((const void *)(up + 1), length);
666 else if (ISPORT(CISCO_AUTORP_PORT))
667 cisco_autorp_print((const void *)(up + 1), length);
668 else if (ISPORT(RADIUS_PORT) ||
669 ISPORT(RADIUS_NEW_PORT) ||
657 }
658#endif /*INET6*/
659 /*
660 * Kludge in test for whiteboard packets.
661 */
662 else if (dport == 4567)
663 wb_print((const void *)(up + 1), length);
664 else if (ISPORT(CISCO_AUTORP_PORT))
665 cisco_autorp_print((const void *)(up + 1), length);
666 else if (ISPORT(RADIUS_PORT) ||
667 ISPORT(RADIUS_NEW_PORT) ||
670 ISPORT(RADIUS_ACCOUNTING_PORT) ||
668 ISPORT(RADIUS_ACCOUNTING_PORT) ||
671 ISPORT(RADIUS_NEW_ACCOUNTING_PORT) )
672 radius_print((const u_char *)(up+1), length);
673 else if (dport == HSRP_PORT)
669 ISPORT(RADIUS_NEW_ACCOUNTING_PORT) )
670 radius_print((const u_char *)(up+1), length);
671 else if (dport == HSRP_PORT)
674 hsrp_print((const u_char *)(up + 1), length);
672 hsrp_print((const u_char *)(up + 1), length);
675 else if (ISPORT(LWRES_PORT))
676 lwres_print((const u_char *)(up + 1), length);
673 else if (ISPORT(LWRES_PORT))
674 lwres_print((const u_char *)(up + 1), length);
675 else if (ISPORT(LDP_PORT))
676 ldp_print((const u_char *)(up + 1), length);
677 else if (ISPORT(MPLS_LSP_PING_PORT))
678 mpls_lsp_ping_print((const u_char *)(up + 1), length);
679 else if (dport == BFD_CONTROL_PORT ||
680 dport == BFD_ECHO_PORT )
681 bfd_print((const u_char *)(up+1), length, dport);
677 else
682 else
678 (void)printf("udp %u",
683 (void)printf("UDP, length: %u",
679 (u_int32_t)(ulen - sizeof(*up)));
680#undef ISPORT
681 } else
684 (u_int32_t)(ulen - sizeof(*up)));
685#undef ISPORT
686 } else
682 (void)printf("udp %u", (u_int32_t)(ulen - sizeof(*up)));
687 (void)printf("UDP, length: %u", (u_int32_t)(ulen - sizeof(*up)));
683}
688}