1 | #include <machine/rtems-bsd-user-space.h> |
---|
2 | |
---|
3 | /* |
---|
4 | * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 |
---|
5 | * The Regents of the University of California. All rights reserved. |
---|
6 | * |
---|
7 | * Redistribution and use in source and binary forms, with or without |
---|
8 | * modification, are permitted provided that: (1) source code distributions |
---|
9 | * retain the above copyright notice and this paragraph in its entirety, (2) |
---|
10 | * distributions including binary code include the above copyright notice and |
---|
11 | * this paragraph in its entirety in the documentation or other materials |
---|
12 | * provided with the distribution, and (3) all advertising materials mentioning |
---|
13 | * features or use of this software display the following acknowledgement: |
---|
14 | * ``This product includes software developed by the University of California, |
---|
15 | * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of |
---|
16 | * the University nor the names of its contributors may be used to endorse |
---|
17 | * or promote products derived from this software without specific prior |
---|
18 | * written permission. |
---|
19 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED |
---|
20 | * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF |
---|
21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
---|
22 | * |
---|
23 | * $FreeBSD$ |
---|
24 | */ |
---|
25 | |
---|
26 | #ifndef lint |
---|
27 | static const char rcsid[] _U_ = |
---|
28 | "@(#) $Header: /tcpdump/master/tcpdump/print-udp.c,v 1.142 2007-08-08 17:20:58 hannes Exp $ (LBL)"; |
---|
29 | #endif |
---|
30 | |
---|
31 | #ifdef HAVE_CONFIG_H |
---|
32 | #include "config.h" |
---|
33 | #endif |
---|
34 | |
---|
35 | #include <tcpdump-stdinc.h> |
---|
36 | |
---|
37 | #ifdef SEGSIZE |
---|
38 | #undef SEGSIZE |
---|
39 | #endif |
---|
40 | |
---|
41 | #include <stdio.h> |
---|
42 | #include <string.h> |
---|
43 | |
---|
44 | #include "interface.h" |
---|
45 | #include "addrtoname.h" |
---|
46 | #include "extract.h" |
---|
47 | #include "appletalk.h" |
---|
48 | |
---|
49 | #include "udp.h" |
---|
50 | |
---|
51 | #include "ip.h" |
---|
52 | #ifdef INET6 |
---|
53 | #include "ip6.h" |
---|
54 | #endif |
---|
55 | #include "ipproto.h" |
---|
56 | #include "rpc_auth.h" |
---|
57 | #include "rpc_msg.h" |
---|
58 | |
---|
59 | #include "nameser.h" |
---|
60 | #include "nfs.h" |
---|
61 | #include "bootp.h" |
---|
62 | |
---|
63 | struct 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) */ |
---|
66 | u_int32_t rh_ssrc; /* synchronization src id */ |
---|
67 | }; |
---|
68 | |
---|
69 | typedef struct { |
---|
70 | u_int32_t upper; /* more significant 32 bits */ |
---|
71 | u_int32_t lower; /* less significant 32 bits */ |
---|
72 | } ntp64; |
---|
73 | |
---|
74 | /* |
---|
75 | * Sender report. |
---|
76 | */ |
---|
77 | struct rtcp_sr { |
---|
78 | ntp64 sr_ntp; /* 64-bit ntp timestamp */ |
---|
79 | u_int32_t sr_ts; /* reference media timestamp */ |
---|
80 | u_int32_t sr_np; /* no. packets sent */ |
---|
81 | u_int32_t sr_nb; /* no. bytes sent */ |
---|
82 | }; |
---|
83 | |
---|
84 | /* |
---|
85 | * Receiver report. |
---|
86 | * Time stamps are middle 32-bits of ntp timestamp. |
---|
87 | */ |
---|
88 | struct rtcp_rr { |
---|
89 | u_int32_t rr_srcid; /* sender being reported */ |
---|
90 | u_int32_t rr_nl; /* no. packets lost */ |
---|
91 | u_int32_t rr_ls; /* extended last seq number received */ |
---|
92 | u_int32_t rr_dv; /* jitter (delay variance) */ |
---|
93 | u_int32_t rr_lsr; /* orig. ts from last rr from this src */ |
---|
94 | u_int32_t rr_dlsr; /* time from recpt of last rr to xmit time */ |
---|
95 | }; |
---|
96 | |
---|
97 | /*XXX*/ |
---|
98 | #define RTCP_PT_SR 200 |
---|
99 | #define RTCP_PT_RR 201 |
---|
100 | #define RTCP_PT_SDES 202 |
---|
101 | #define RTCP_SDES_CNAME 1 |
---|
102 | #define RTCP_SDES_NAME 2 |
---|
103 | #define RTCP_SDES_EMAIL 3 |
---|
104 | #define RTCP_SDES_PHONE 4 |
---|
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 | |
---|
112 | static void |
---|
113 | vat_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", |
---|
120 | (u_int32_t)(EXTRACT_16BITS(&up->uh_ulen) - sizeof(*up)), |
---|
121 | ts & 0x3ff, ts >> 10); |
---|
122 | } else { |
---|
123 | /* probably vat */ |
---|
124 | u_int32_t i0 = EXTRACT_32BITS(&((u_int *)hdr)[0]); |
---|
125 | u_int32_t i1 = EXTRACT_32BITS(&((u_int *)hdr)[1]); |
---|
126 | printf("udp/vat %u c%d %u%s", |
---|
127 | (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 | |
---|
138 | static void |
---|
139 | rtp_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; |
---|
144 | u_int32_t i0 = EXTRACT_32BITS(&((u_int *)hdr)[0]); |
---|
145 | u_int32_t i1 = EXTRACT_32BITS(&((u_int *)hdr)[1]); |
---|
146 | 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) { |
---|
155 | /* rtp v1 */ |
---|
156 | hasopt = i0 & 0x800000; |
---|
157 | contype = (i0 >> 16) & 0x3f; |
---|
158 | hasmarker = i0 & 0x400000; |
---|
159 | ptype = "rtpv1"; |
---|
160 | } else { |
---|
161 | /* rtp v2 */ |
---|
162 | hasext = i0 & 0x10000000; |
---|
163 | contype = (i0 >> 16) & 0x7f; |
---|
164 | hasmarker = i0 & 0x800000; |
---|
165 | dlen -= 4; |
---|
166 | ptype = "rtp"; |
---|
167 | ip += 1; |
---|
168 | len -= 1; |
---|
169 | } |
---|
170 | printf("udp/%s %d c%d %s%s %d %u", |
---|
171 | ptype, |
---|
172 | dlen, |
---|
173 | contype, |
---|
174 | (hasopt || hasext)? "+" : "", |
---|
175 | hasmarker? "*" : "", |
---|
176 | i0 & 0xffff, |
---|
177 | i1); |
---|
178 | if (vflag) { |
---|
179 | 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; |
---|
188 | } |
---|
189 | ip += optlen; |
---|
190 | len -= optlen; |
---|
191 | } while ((int)i2 >= 0); |
---|
192 | } |
---|
193 | if (hasext) { |
---|
194 | u_int i2, extlen; |
---|
195 | i2 = ip[0]; |
---|
196 | extlen = (i2 & 0xffff) + 1; |
---|
197 | if (extlen > len) { |
---|
198 | printf(" !ext"); |
---|
199 | return; |
---|
200 | } |
---|
201 | ip += extlen; |
---|
202 | } |
---|
203 | if (contype == 0x1f) /*XXX H.261 */ |
---|
204 | printf(" 0x%04x", ip[0] >> 16); |
---|
205 | } |
---|
206 | } |
---|
207 | |
---|
208 | static const u_char * |
---|
209 | rtcp_print(const u_char *hdr, const u_char *ep) |
---|
210 | { |
---|
211 | /* rtp v2 control (rtcp) */ |
---|
212 | struct rtcp_rr *rr = 0; |
---|
213 | struct rtcp_sr *sr; |
---|
214 | struct rtcphdr *rh = (struct rtcphdr *)hdr; |
---|
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 | } |
---|
223 | len = (EXTRACT_16BITS(&rh->rh_len) + 1) * 4; |
---|
224 | 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) |
---|
233 | printf(" %u", EXTRACT_32BITS(&rh->rh_ssrc)); |
---|
234 | if ((u_char *)(sr + 1) > ep) { |
---|
235 | printf(" [|rtcp]"); |
---|
236 | return (ep); |
---|
237 | } |
---|
238 | ts = (double)(EXTRACT_32BITS(&sr->sr_ntp.upper)) + |
---|
239 | ((double)(EXTRACT_32BITS(&sr->sr_ntp.lower)) / |
---|
240 | 4294967296.0); |
---|
241 | printf(" @%.2f %u %up %ub", ts, EXTRACT_32BITS(&sr->sr_ts), |
---|
242 | 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) |
---|
251 | printf(" %u", EXTRACT_32BITS(&rh->rh_ssrc)); |
---|
252 | break; |
---|
253 | case RTCP_PT_SDES: |
---|
254 | printf(" sdes %d", len); |
---|
255 | if (vflag) |
---|
256 | 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) |
---|
262 | 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) |
---|
278 | printf(" %u", EXTRACT_32BITS(&rr->rr_srcid)); |
---|
279 | ts = (double)(EXTRACT_32BITS(&rr->rr_lsr)) / 65536.; |
---|
280 | dts = (double)(EXTRACT_32BITS(&rr->rr_dlsr)) / 65536.; |
---|
281 | printf(" %ul %us %uj @%.2f+%.2f", |
---|
282 | EXTRACT_32BITS(&rr->rr_nl) & 0x00ffffff, |
---|
283 | EXTRACT_32BITS(&rr->rr_ls), |
---|
284 | EXTRACT_32BITS(&rr->rr_dv), ts, dts); |
---|
285 | } |
---|
286 | return (hdr + len); |
---|
287 | } |
---|
288 | |
---|
289 | static int udp_cksum(register const struct ip *ip, |
---|
290 | register const struct udphdr *up, |
---|
291 | register u_int len) |
---|
292 | { |
---|
293 | return (nextproto4_cksum(ip, (const u_int8_t *)(void *)up, len, |
---|
294 | IPPROTO_UDP)); |
---|
295 | } |
---|
296 | |
---|
297 | #ifdef INET6 |
---|
298 | static int udp6_cksum(const struct ip6_hdr *ip6, const struct udphdr *up, |
---|
299 | u_int len) |
---|
300 | { |
---|
301 | return (nextproto6_cksum(ip6, (const u_int8_t *)(void *)up, len, |
---|
302 | IPPROTO_UDP)); |
---|
303 | } |
---|
304 | #endif |
---|
305 | |
---|
306 | static void |
---|
307 | udpipaddr_print(const struct ip *ip, int sport, int dport) |
---|
308 | { |
---|
309 | #ifdef INET6 |
---|
310 | const struct ip6_hdr *ip6; |
---|
311 | |
---|
312 | if (IP_V(ip) == 6) |
---|
313 | ip6 = (const struct ip6_hdr *)ip; |
---|
314 | else |
---|
315 | ip6 = NULL; |
---|
316 | |
---|
317 | if (ip6) { |
---|
318 | if (ip6->ip6_nxt == IPPROTO_UDP) { |
---|
319 | if (sport == -1) { |
---|
320 | (void)printf("%s > %s: ", |
---|
321 | ip6addr_string(&ip6->ip6_src), |
---|
322 | ip6addr_string(&ip6->ip6_dst)); |
---|
323 | } else { |
---|
324 | (void)printf("%s.%s > %s.%s: ", |
---|
325 | ip6addr_string(&ip6->ip6_src), |
---|
326 | udpport_string(sport), |
---|
327 | ip6addr_string(&ip6->ip6_dst), |
---|
328 | udpport_string(dport)); |
---|
329 | } |
---|
330 | } else { |
---|
331 | if (sport != -1) { |
---|
332 | (void)printf("%s > %s: ", |
---|
333 | udpport_string(sport), |
---|
334 | udpport_string(dport)); |
---|
335 | } |
---|
336 | } |
---|
337 | } else |
---|
338 | #endif /*INET6*/ |
---|
339 | { |
---|
340 | if (ip->ip_p == IPPROTO_UDP) { |
---|
341 | if (sport == -1) { |
---|
342 | (void)printf("%s > %s: ", |
---|
343 | ipaddr_string(&ip->ip_src), |
---|
344 | ipaddr_string(&ip->ip_dst)); |
---|
345 | } else { |
---|
346 | (void)printf("%s.%s > %s.%s: ", |
---|
347 | ipaddr_string(&ip->ip_src), |
---|
348 | udpport_string(sport), |
---|
349 | ipaddr_string(&ip->ip_dst), |
---|
350 | udpport_string(dport)); |
---|
351 | } |
---|
352 | } else { |
---|
353 | if (sport != -1) { |
---|
354 | (void)printf("%s > %s: ", |
---|
355 | udpport_string(sport), |
---|
356 | udpport_string(dport)); |
---|
357 | } |
---|
358 | } |
---|
359 | } |
---|
360 | } |
---|
361 | |
---|
362 | void |
---|
363 | udp_print(register const u_char *bp, u_int length, |
---|
364 | register const u_char *bp2, int fragmented) |
---|
365 | { |
---|
366 | register const struct udphdr *up; |
---|
367 | register const struct ip *ip; |
---|
368 | register const u_char *cp; |
---|
369 | register const u_char *ep = bp + length; |
---|
370 | u_int16_t sport, dport, ulen; |
---|
371 | #ifdef INET6 |
---|
372 | register const struct ip6_hdr *ip6; |
---|
373 | #endif |
---|
374 | |
---|
375 | if (ep > snapend) |
---|
376 | ep = snapend; |
---|
377 | up = (struct udphdr *)bp; |
---|
378 | ip = (struct ip *)bp2; |
---|
379 | #ifdef INET6 |
---|
380 | if (IP_V(ip) == 6) |
---|
381 | ip6 = (struct ip6_hdr *)bp2; |
---|
382 | else |
---|
383 | ip6 = NULL; |
---|
384 | #endif /*INET6*/ |
---|
385 | cp = (u_char *)(up + 1); |
---|
386 | if (!TTEST(up->uh_dport)) { |
---|
387 | udpipaddr_print(ip, -1, -1); |
---|
388 | (void)printf("[|udp]"); |
---|
389 | return; |
---|
390 | } |
---|
391 | |
---|
392 | sport = EXTRACT_16BITS(&up->uh_sport); |
---|
393 | dport = EXTRACT_16BITS(&up->uh_dport); |
---|
394 | |
---|
395 | if (length < sizeof(struct udphdr)) { |
---|
396 | udpipaddr_print(ip, sport, dport); |
---|
397 | (void)printf("truncated-udp %d", length); |
---|
398 | return; |
---|
399 | } |
---|
400 | length -= sizeof(struct udphdr); |
---|
401 | |
---|
402 | if (cp > snapend) { |
---|
403 | udpipaddr_print(ip, sport, dport); |
---|
404 | (void)printf("[|udp]"); |
---|
405 | return; |
---|
406 | } |
---|
407 | |
---|
408 | ulen = EXTRACT_16BITS(&up->uh_ulen); |
---|
409 | if (ulen < 8) { |
---|
410 | udpipaddr_print(ip, sport, dport); |
---|
411 | (void)printf("truncated-udplength %d", ulen); |
---|
412 | return; |
---|
413 | } |
---|
414 | if (packettype) { |
---|
415 | register struct sunrpc_msg *rp; |
---|
416 | enum sunrpc_msg_type direction; |
---|
417 | |
---|
418 | switch (packettype) { |
---|
419 | |
---|
420 | case PT_VAT: |
---|
421 | udpipaddr_print(ip, sport, dport); |
---|
422 | vat_print((void *)(up + 1), up); |
---|
423 | break; |
---|
424 | |
---|
425 | case PT_WB: |
---|
426 | udpipaddr_print(ip, sport, dport); |
---|
427 | wb_print((void *)(up + 1), length); |
---|
428 | break; |
---|
429 | |
---|
430 | case PT_RPC: |
---|
431 | rp = (struct sunrpc_msg *)(up + 1); |
---|
432 | direction = (enum sunrpc_msg_type)EXTRACT_32BITS(&rp->rm_direction); |
---|
433 | #ifndef __rtems__ |
---|
434 | if (direction == SUNRPC_CALL) |
---|
435 | sunrpcrequest_print((u_char *)rp, length, |
---|
436 | (u_char *)ip); |
---|
437 | else |
---|
438 | #endif |
---|
439 | nfsreply_print((u_char *)rp, length, |
---|
440 | (u_char *)ip); /*XXX*/ |
---|
441 | break; |
---|
442 | |
---|
443 | case PT_RTP: |
---|
444 | udpipaddr_print(ip, sport, dport); |
---|
445 | rtp_print((void *)(up + 1), length, up); |
---|
446 | break; |
---|
447 | |
---|
448 | case PT_RTCP: |
---|
449 | udpipaddr_print(ip, sport, dport); |
---|
450 | while (cp < ep) |
---|
451 | cp = rtcp_print(cp, ep); |
---|
452 | break; |
---|
453 | |
---|
454 | case PT_SNMP: |
---|
455 | udpipaddr_print(ip, sport, dport); |
---|
456 | snmp_print((const u_char *)(up + 1), length); |
---|
457 | break; |
---|
458 | |
---|
459 | case PT_CNFP: |
---|
460 | udpipaddr_print(ip, sport, dport); |
---|
461 | cnfp_print(cp, (const u_char *)ip); |
---|
462 | break; |
---|
463 | |
---|
464 | case PT_TFTP: |
---|
465 | udpipaddr_print(ip, sport, dport); |
---|
466 | tftp_print(cp, length); |
---|
467 | break; |
---|
468 | |
---|
469 | case PT_AODV: |
---|
470 | udpipaddr_print(ip, sport, dport); |
---|
471 | aodv_print((const u_char *)(up + 1), length, |
---|
472 | #ifdef INET6 |
---|
473 | ip6 != NULL); |
---|
474 | #else |
---|
475 | 0); |
---|
476 | #endif |
---|
477 | break; |
---|
478 | |
---|
479 | case PT_RADIUS: |
---|
480 | udpipaddr_print(ip, sport, dport); |
---|
481 | radius_print(cp, length); |
---|
482 | break; |
---|
483 | |
---|
484 | case PT_VXLAN: |
---|
485 | udpipaddr_print(ip, sport, dport); |
---|
486 | vxlan_print((const u_char *)(up + 1), length); |
---|
487 | break; |
---|
488 | } |
---|
489 | return; |
---|
490 | } |
---|
491 | |
---|
492 | if (!qflag) { |
---|
493 | register struct sunrpc_msg *rp; |
---|
494 | enum sunrpc_msg_type direction; |
---|
495 | |
---|
496 | rp = (struct sunrpc_msg *)(up + 1); |
---|
497 | if (TTEST(rp->rm_direction)) { |
---|
498 | direction = (enum sunrpc_msg_type)EXTRACT_32BITS(&rp->rm_direction); |
---|
499 | if (dport == NFS_PORT && direction == SUNRPC_CALL) { |
---|
500 | nfsreq_print((u_char *)rp, length, |
---|
501 | (u_char *)ip); |
---|
502 | return; |
---|
503 | } |
---|
504 | if (sport == NFS_PORT && direction == SUNRPC_REPLY) { |
---|
505 | nfsreply_print((u_char *)rp, length, |
---|
506 | (u_char *)ip); |
---|
507 | return; |
---|
508 | } |
---|
509 | #ifdef notdef |
---|
510 | if (dport == SUNRPC_PORT && direction == SUNRPC_CALL) { |
---|
511 | sunrpcrequest_print((u_char *)rp, length, (u_char *)ip); |
---|
512 | return; |
---|
513 | } |
---|
514 | #endif |
---|
515 | } |
---|
516 | if (TTEST(((struct LAP *)cp)->type) && |
---|
517 | ((struct LAP *)cp)->type == lapDDP && |
---|
518 | (atalk_port(sport) || atalk_port(dport))) { |
---|
519 | if (vflag) |
---|
520 | fputs("kip ", stdout); |
---|
521 | llap_print(cp, length); |
---|
522 | return; |
---|
523 | } |
---|
524 | } |
---|
525 | udpipaddr_print(ip, sport, dport); |
---|
526 | |
---|
527 | if (vflag && !Kflag && !fragmented) { |
---|
528 | /* Check the checksum, if possible. */ |
---|
529 | u_int16_t sum, udp_sum; |
---|
530 | |
---|
531 | /* |
---|
532 | * XXX - do this even if vflag == 1? |
---|
533 | * TCP does, and we do so for UDP-over-IPv6. |
---|
534 | */ |
---|
535 | if (IP_V(ip) == 4 && (vflag > 1)) { |
---|
536 | udp_sum = EXTRACT_16BITS(&up->uh_sum); |
---|
537 | if (udp_sum == 0) { |
---|
538 | (void)printf("[no cksum] "); |
---|
539 | } else if (TTEST2(cp[0], length)) { |
---|
540 | sum = udp_cksum(ip, up, length + sizeof(struct udphdr)); |
---|
541 | |
---|
542 | if (sum != 0) { |
---|
543 | (void)printf("[bad udp cksum 0x%04x -> 0x%04x!] ", |
---|
544 | udp_sum, |
---|
545 | in_cksum_shouldbe(udp_sum, sum)); |
---|
546 | } else |
---|
547 | (void)printf("[udp sum ok] "); |
---|
548 | } |
---|
549 | } |
---|
550 | #ifdef INET6 |
---|
551 | else if (IP_V(ip) == 6 && ip6->ip6_plen) { |
---|
552 | /* for IPv6, UDP checksum is mandatory */ |
---|
553 | if (TTEST2(cp[0], length)) { |
---|
554 | sum = udp6_cksum(ip6, up, length + sizeof(struct udphdr)); |
---|
555 | udp_sum = EXTRACT_16BITS(&up->uh_sum); |
---|
556 | |
---|
557 | if (sum != 0) { |
---|
558 | (void)printf("[bad udp cksum 0x%04x -> 0x%04x!] ", |
---|
559 | udp_sum, |
---|
560 | in_cksum_shouldbe(udp_sum, sum)); |
---|
561 | } else |
---|
562 | (void)printf("[udp sum ok] "); |
---|
563 | } |
---|
564 | } |
---|
565 | #endif |
---|
566 | } |
---|
567 | |
---|
568 | if (!qflag) { |
---|
569 | #define ISPORT(p) (dport == (p) || sport == (p)) |
---|
570 | if (ISPORT(NAMESERVER_PORT)) |
---|
571 | ns_print((const u_char *)(up + 1), length, 0); |
---|
572 | else if (ISPORT(MULTICASTDNS_PORT)) |
---|
573 | ns_print((const u_char *)(up + 1), length, 1); |
---|
574 | else if (ISPORT(TIMED_PORT)) |
---|
575 | timed_print((const u_char *)(up + 1)); |
---|
576 | else if (ISPORT(TFTP_PORT)) |
---|
577 | tftp_print((const u_char *)(up + 1), length); |
---|
578 | else if (ISPORT(IPPORT_BOOTPC) || ISPORT(IPPORT_BOOTPS)) |
---|
579 | bootp_print((const u_char *)(up + 1), length); |
---|
580 | else if (ISPORT(RIP_PORT)) |
---|
581 | rip_print((const u_char *)(up + 1), length); |
---|
582 | else if (ISPORT(AODV_PORT)) |
---|
583 | aodv_print((const u_char *)(up + 1), length, |
---|
584 | #ifdef INET6 |
---|
585 | ip6 != NULL); |
---|
586 | #else |
---|
587 | 0); |
---|
588 | #endif |
---|
589 | else if (ISPORT(ISAKMP_PORT)) |
---|
590 | isakmp_print(gndo, (const u_char *)(up + 1), length, bp2); |
---|
591 | else if (ISPORT(ISAKMP_PORT_NATT)) |
---|
592 | isakmp_rfc3948_print(gndo, (const u_char *)(up + 1), length, bp2); |
---|
593 | #if 1 /*???*/ |
---|
594 | else if (ISPORT(ISAKMP_PORT_USER1) || ISPORT(ISAKMP_PORT_USER2)) |
---|
595 | isakmp_print(gndo, (const u_char *)(up + 1), length, bp2); |
---|
596 | #endif |
---|
597 | else if (ISPORT(SNMP_PORT) || ISPORT(SNMPTRAP_PORT)) |
---|
598 | snmp_print((const u_char *)(up + 1), length); |
---|
599 | else if (ISPORT(NTP_PORT)) |
---|
600 | ntp_print((const u_char *)(up + 1), length); |
---|
601 | else if (ISPORT(KERBEROS_PORT) || ISPORT(KERBEROS_SEC_PORT)) |
---|
602 | krb_print((const void *)(up + 1)); |
---|
603 | else if (ISPORT(L2TP_PORT)) |
---|
604 | l2tp_print((const u_char *)(up + 1), length); |
---|
605 | #ifdef TCPDUMP_DO_SMB |
---|
606 | else if (ISPORT(NETBIOS_NS_PORT)) |
---|
607 | nbt_udp137_print((const u_char *)(up + 1), length); |
---|
608 | else if (ISPORT(NETBIOS_DGRAM_PORT)) |
---|
609 | nbt_udp138_print((const u_char *)(up + 1), length); |
---|
610 | #endif |
---|
611 | else if (dport == 3456) |
---|
612 | vat_print((const void *)(up + 1), up); |
---|
613 | else if (ISPORT(ZEPHYR_SRV_PORT) || ISPORT(ZEPHYR_CLT_PORT)) |
---|
614 | zephyr_print((const void *)(up + 1), length); |
---|
615 | /* |
---|
616 | * Since there are 10 possible ports to check, I think |
---|
617 | * a <> test would be more efficient |
---|
618 | */ |
---|
619 | else if ((sport >= RX_PORT_LOW && sport <= RX_PORT_HIGH) || |
---|
620 | (dport >= RX_PORT_LOW && dport <= RX_PORT_HIGH)) |
---|
621 | rx_print((const void *)(up + 1), length, sport, dport, |
---|
622 | (u_char *) ip); |
---|
623 | #ifdef INET6 |
---|
624 | else if (ISPORT(RIPNG_PORT)) |
---|
625 | ripng_print((const u_char *)(up + 1), length); |
---|
626 | else if (ISPORT(DHCP6_SERV_PORT) || ISPORT(DHCP6_CLI_PORT)) |
---|
627 | dhcp6_print((const u_char *)(up + 1), length); |
---|
628 | else if (ISPORT(BABEL_PORT) || ISPORT(BABEL_PORT_OLD)) |
---|
629 | babel_print((const u_char *)(up + 1), length); |
---|
630 | #endif /*INET6*/ |
---|
631 | /* |
---|
632 | * Kludge in test for whiteboard packets. |
---|
633 | */ |
---|
634 | else if (dport == 4567) |
---|
635 | wb_print((const void *)(up + 1), length); |
---|
636 | else if (ISPORT(CISCO_AUTORP_PORT)) |
---|
637 | cisco_autorp_print((const void *)(up + 1), length); |
---|
638 | else if (ISPORT(RADIUS_PORT) || |
---|
639 | ISPORT(RADIUS_NEW_PORT) || |
---|
640 | ISPORT(RADIUS_ACCOUNTING_PORT) || |
---|
641 | ISPORT(RADIUS_NEW_ACCOUNTING_PORT) ) |
---|
642 | radius_print((const u_char *)(up+1), length); |
---|
643 | else if (dport == HSRP_PORT) |
---|
644 | hsrp_print((const u_char *)(up + 1), length); |
---|
645 | else if (ISPORT(LWRES_PORT)) |
---|
646 | lwres_print((const u_char *)(up + 1), length); |
---|
647 | else if (ISPORT(LDP_PORT)) |
---|
648 | ldp_print((const u_char *)(up + 1), length); |
---|
649 | else if (ISPORT(OLSR_PORT)) |
---|
650 | olsr_print((const u_char *)(up + 1), length, |
---|
651 | #if INET6 |
---|
652 | (IP_V(ip) == 6) ? 1 : 0); |
---|
653 | #else |
---|
654 | 0); |
---|
655 | #endif |
---|
656 | else if (ISPORT(MPLS_LSP_PING_PORT)) |
---|
657 | lspping_print((const u_char *)(up + 1), length); |
---|
658 | else if (dport == BFD_CONTROL_PORT || |
---|
659 | dport == BFD_ECHO_PORT ) |
---|
660 | bfd_print((const u_char *)(up+1), length, dport); |
---|
661 | else if (ISPORT(LMP_PORT)) |
---|
662 | lmp_print((const u_char *)(up + 1), length); |
---|
663 | else if (ISPORT(VQP_PORT)) |
---|
664 | vqp_print((const u_char *)(up + 1), length); |
---|
665 | else if (ISPORT(SFLOW_PORT)) |
---|
666 | sflow_print((const u_char *)(up + 1), length); |
---|
667 | else if (dport == LWAPP_CONTROL_PORT) |
---|
668 | lwapp_control_print((const u_char *)(up + 1), length, 1); |
---|
669 | else if (sport == LWAPP_CONTROL_PORT) |
---|
670 | lwapp_control_print((const u_char *)(up + 1), length, 0); |
---|
671 | else if (ISPORT(LWAPP_DATA_PORT)) |
---|
672 | lwapp_data_print((const u_char *)(up + 1), length); |
---|
673 | else if (ISPORT(SIP_PORT)) |
---|
674 | sip_print((const u_char *)(up + 1), length); |
---|
675 | else if (ISPORT(SYSLOG_PORT)) |
---|
676 | syslog_print((const u_char *)(up + 1), length); |
---|
677 | else if (ISPORT(OTV_PORT)) |
---|
678 | otv_print((const u_char *)(up + 1), length); |
---|
679 | else |
---|
680 | (void)printf("UDP, length %u", |
---|
681 | (u_int32_t)(ulen - sizeof(*up))); |
---|
682 | #undef ISPORT |
---|
683 | } else |
---|
684 | (void)printf("UDP, length %u", (u_int32_t)(ulen - sizeof(*up))); |
---|
685 | } |
---|
686 | |
---|
687 | |
---|
688 | /* |
---|
689 | * Local Variables: |
---|
690 | * c-style: whitesmith |
---|
691 | * c-basic-offset: 8 |
---|
692 | * End: |
---|
693 | */ |
---|