xref: /dragonfly/contrib/tcpdump/print-udp.c (revision c880cbaf)
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
9  * this paragraph in its entirety in the documentation or other materials
10  * provided with the distribution, and (3) all advertising materials mentioning
11  * features or use of this software display the following acknowledgement:
12  * ``This product includes software developed by the University of California,
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 
22 /* \summary: UDP printer */
23 
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27 
28 #include <netdissect-stdinc.h>
29 
30 #include "netdissect.h"
31 #include "addrtoname.h"
32 #include "extract.h"
33 #include "appletalk.h"
34 
35 #include "udp.h"
36 
37 #include "ip.h"
38 #include "ip6.h"
39 #include "ipproto.h"
40 #include "rpc_auth.h"
41 #include "rpc_msg.h"
42 
43 #include "nfs.h"
44 
45 static const char vat_tstr[] = " [|vat]";
46 static const char rtp_tstr[] = " [|rtp]";
47 static const char rtcp_tstr[] = " [|rtcp]";
48 static const char udp_tstr[] = " [|udp]";
49 
50 struct rtcphdr {
51 	uint16_t rh_flags;	/* T:2 P:1 CNT:5 PT:8 */
52 	uint16_t rh_len;	/* length of message (in words) */
53 	uint32_t rh_ssrc;	/* synchronization src id */
54 };
55 
56 typedef struct {
57 	uint32_t upper;	/* more significant 32 bits */
58 	uint32_t lower;	/* less significant 32 bits */
59 } ntp64;
60 
61 /*
62  * Sender report.
63  */
64 struct rtcp_sr {
65 	ntp64 sr_ntp;		/* 64-bit ntp timestamp */
66 	uint32_t sr_ts;	/* reference media timestamp */
67 	uint32_t sr_np;	/* no. packets sent */
68 	uint32_t sr_nb;	/* no. bytes sent */
69 };
70 
71 /*
72  * Receiver report.
73  * Time stamps are middle 32-bits of ntp timestamp.
74  */
75 struct rtcp_rr {
76 	uint32_t rr_srcid;	/* sender being reported */
77 	uint32_t rr_nl;	/* no. packets lost */
78 	uint32_t rr_ls;	/* extended last seq number received */
79 	uint32_t rr_dv;	/* jitter (delay variance) */
80 	uint32_t rr_lsr;	/* orig. ts from last rr from this src  */
81 	uint32_t rr_dlsr;	/* time from recpt of last rr to xmit time */
82 };
83 
84 /*XXX*/
85 #define RTCP_PT_SR	200
86 #define RTCP_PT_RR	201
87 #define RTCP_PT_SDES	202
88 #define 	RTCP_SDES_CNAME	1
89 #define 	RTCP_SDES_NAME	2
90 #define 	RTCP_SDES_EMAIL	3
91 #define 	RTCP_SDES_PHONE	4
92 #define 	RTCP_SDES_LOC	5
93 #define 	RTCP_SDES_TOOL	6
94 #define 	RTCP_SDES_NOTE	7
95 #define 	RTCP_SDES_PRIV	8
96 #define RTCP_PT_BYE	203
97 #define RTCP_PT_APP	204
98 
99 static void
100 vat_print(netdissect_options *ndo, const void *hdr, register const struct udphdr *up)
101 {
102 	/* vat/vt audio */
103 	u_int ts;
104 
105 	ND_TCHECK_16BITS((const u_int *)hdr);
106 	ts = EXTRACT_16BITS(hdr);
107 	if ((ts & 0xf060) != 0) {
108 		/* probably vt */
109 		ND_TCHECK_16BITS(&up->uh_ulen);
110 		ND_PRINT((ndo, "udp/vt %u %d / %d",
111 			     (uint32_t)(EXTRACT_16BITS(&up->uh_ulen) - sizeof(*up)),
112 			     ts & 0x3ff, ts >> 10));
113 	} else {
114 		/* probably vat */
115 		uint32_t i0, i1;
116 
117 		ND_TCHECK_32BITS(&((const u_int *)hdr)[0]);
118 		i0 = EXTRACT_32BITS(&((const u_int *)hdr)[0]);
119 		ND_TCHECK_32BITS(&((const u_int *)hdr)[1]);
120 		i1 = EXTRACT_32BITS(&((const u_int *)hdr)[1]);
121 		ND_TCHECK_16BITS(&up->uh_ulen);
122 		ND_PRINT((ndo, "udp/vat %u c%d %u%s",
123 			(uint32_t)(EXTRACT_16BITS(&up->uh_ulen) - sizeof(*up) - 8),
124 			i0 & 0xffff,
125 			i1, i0 & 0x800000? "*" : ""));
126 		/* audio format */
127 		if (i0 & 0x1f0000)
128 			ND_PRINT((ndo, " f%d", (i0 >> 16) & 0x1f));
129 		if (i0 & 0x3f000000)
130 			ND_PRINT((ndo, " s%d", (i0 >> 24) & 0x3f));
131 	}
132 
133 trunc:
134 	ND_PRINT((ndo, "%s", vat_tstr));
135 }
136 
137 static void
138 rtp_print(netdissect_options *ndo, const void *hdr, u_int len,
139           register const struct udphdr *up)
140 {
141 	/* rtp v1 or v2 */
142 	const u_int *ip = (const u_int *)hdr;
143 	u_int hasopt, hasext, contype, hasmarker, dlen;
144 	uint32_t i0, i1;
145 	const char * ptype;
146 
147 	ND_TCHECK_32BITS(&((const u_int *)hdr)[0]);
148 	i0 = EXTRACT_32BITS(&((const u_int *)hdr)[0]);
149 	ND_TCHECK_32BITS(&((const u_int *)hdr)[1]);
150 	i1 = EXTRACT_32BITS(&((const u_int *)hdr)[1]);
151 	ND_TCHECK_16BITS(&up->uh_ulen);
152 	dlen = EXTRACT_16BITS(&up->uh_ulen) - sizeof(*up) - 8;
153 	ip += 2;
154 	len >>= 2;
155 	len -= 2;
156 	hasopt = 0;
157 	hasext = 0;
158 	if ((i0 >> 30) == 1) {
159 		/* rtp v1 - draft-ietf-avt-rtp-04 */
160 		hasopt = i0 & 0x800000;
161 		contype = (i0 >> 16) & 0x3f;
162 		hasmarker = i0 & 0x400000;
163 		ptype = "rtpv1";
164 	} else {
165 		/* rtp v2 - RFC 3550 */
166 		hasext = i0 & 0x10000000;
167 		contype = (i0 >> 16) & 0x7f;
168 		hasmarker = i0 & 0x800000;
169 		dlen -= 4;
170 		ptype = "rtp";
171 		ip += 1;
172 		len -= 1;
173 	}
174 	ND_PRINT((ndo, "udp/%s %d c%d %s%s %d %u",
175 		ptype,
176 		dlen,
177 		contype,
178 		(hasopt || hasext)? "+" : "",
179 		hasmarker? "*" : "",
180 		i0 & 0xffff,
181 		i1));
182 	if (ndo->ndo_vflag) {
183 		ND_TCHECK_32BITS(&((const u_int *)hdr)[2]);
184 		ND_PRINT((ndo, " %u", EXTRACT_32BITS(&((const u_int *)hdr)[2])));
185 		if (hasopt) {
186 			u_int i2, optlen;
187 			do {
188 				ND_TCHECK_32BITS(ip);
189 				i2 = EXTRACT_32BITS(ip);
190 				optlen = (i2 >> 16) & 0xff;
191 				if (optlen == 0 || optlen > len) {
192 					ND_PRINT((ndo, " !opt"));
193 					return;
194 				}
195 				ip += optlen;
196 				len -= optlen;
197 			} while ((int)i2 >= 0);
198 		}
199 		if (hasext) {
200 			u_int i2, extlen;
201 			ND_TCHECK_32BITS(ip);
202 			i2 = EXTRACT_32BITS(ip);
203 			extlen = (i2 & 0xffff) + 1;
204 			if (extlen > len) {
205 				ND_PRINT((ndo, " !ext"));
206 				return;
207 			}
208 			ip += extlen;
209 		}
210 		ND_TCHECK_32BITS(ip);
211 		if (contype == 0x1f) /*XXX H.261 */
212 			ND_PRINT((ndo, " 0x%04x", EXTRACT_32BITS(ip) >> 16));
213 	}
214 
215 trunc:
216 	ND_PRINT((ndo, "%s", rtp_tstr));
217 }
218 
219 static const u_char *
220 rtcp_print(netdissect_options *ndo, const u_char *hdr, const u_char *ep)
221 {
222 	/* rtp v2 control (rtcp) */
223 	const struct rtcp_rr *rr = 0;
224 	const struct rtcp_sr *sr;
225 	const struct rtcphdr *rh = (const struct rtcphdr *)hdr;
226 	u_int len;
227 	uint16_t flags;
228 	int cnt;
229 	double ts, dts;
230 	if ((const u_char *)(rh + 1) > ep)
231 		goto trunc;
232 	ND_TCHECK(*rh);
233 	len = (EXTRACT_16BITS(&rh->rh_len) + 1) * 4;
234 	flags = EXTRACT_16BITS(&rh->rh_flags);
235 	cnt = (flags >> 8) & 0x1f;
236 	switch (flags & 0xff) {
237 	case RTCP_PT_SR:
238 		sr = (const struct rtcp_sr *)(rh + 1);
239 		ND_PRINT((ndo, " sr"));
240 		if (len != cnt * sizeof(*rr) + sizeof(*sr) + sizeof(*rh))
241 			ND_PRINT((ndo, " [%d]", len));
242 		if (ndo->ndo_vflag)
243 			ND_PRINT((ndo, " %u", EXTRACT_32BITS(&rh->rh_ssrc)));
244 		if ((const u_char *)(sr + 1) > ep)
245 			goto trunc;
246 		ND_TCHECK(*sr);
247 		ts = (double)(EXTRACT_32BITS(&sr->sr_ntp.upper)) +
248 		    ((double)(EXTRACT_32BITS(&sr->sr_ntp.lower)) /
249 		    4294967296.0);
250 		ND_PRINT((ndo, " @%.2f %u %up %ub", ts, EXTRACT_32BITS(&sr->sr_ts),
251 		    EXTRACT_32BITS(&sr->sr_np), EXTRACT_32BITS(&sr->sr_nb)));
252 		rr = (const struct rtcp_rr *)(sr + 1);
253 		break;
254 	case RTCP_PT_RR:
255 		ND_PRINT((ndo, " rr"));
256 		if (len != cnt * sizeof(*rr) + sizeof(*rh))
257 			ND_PRINT((ndo, " [%d]", len));
258 		rr = (const struct rtcp_rr *)(rh + 1);
259 		if (ndo->ndo_vflag)
260 			ND_PRINT((ndo, " %u", EXTRACT_32BITS(&rh->rh_ssrc)));
261 		break;
262 	case RTCP_PT_SDES:
263 		ND_PRINT((ndo, " sdes %d", len));
264 		if (ndo->ndo_vflag)
265 			ND_PRINT((ndo, " %u", EXTRACT_32BITS(&rh->rh_ssrc)));
266 		cnt = 0;
267 		break;
268 	case RTCP_PT_BYE:
269 		ND_PRINT((ndo, " bye %d", len));
270 		if (ndo->ndo_vflag)
271 			ND_PRINT((ndo, " %u", EXTRACT_32BITS(&rh->rh_ssrc)));
272 		cnt = 0;
273 		break;
274 	default:
275 		ND_PRINT((ndo, " type-0x%x %d", flags & 0xff, len));
276 		cnt = 0;
277 		break;
278 	}
279 	if (cnt > 1)
280 		ND_PRINT((ndo, " c%d", cnt));
281 	while (--cnt >= 0) {
282 		if ((const u_char *)(rr + 1) > ep)
283 			goto trunc;
284 		ND_TCHECK(*rr);
285 		if (ndo->ndo_vflag)
286 			ND_PRINT((ndo, " %u", EXTRACT_32BITS(&rr->rr_srcid)));
287 		ts = (double)(EXTRACT_32BITS(&rr->rr_lsr)) / 65536.;
288 		dts = (double)(EXTRACT_32BITS(&rr->rr_dlsr)) / 65536.;
289 		ND_PRINT((ndo, " %ul %us %uj @%.2f+%.2f",
290 		    EXTRACT_32BITS(&rr->rr_nl) & 0x00ffffff,
291 		    EXTRACT_32BITS(&rr->rr_ls),
292 		    EXTRACT_32BITS(&rr->rr_dv), ts, dts));
293 	}
294 	return (hdr + len);
295 
296 trunc:
297 	ND_PRINT((ndo, "%s", rtcp_tstr));
298 	return ep;
299 }
300 
301 static int udp_cksum(netdissect_options *ndo, register const struct ip *ip,
302 		     register const struct udphdr *up,
303 		     register u_int len)
304 {
305 	return nextproto4_cksum(ndo, ip, (const uint8_t *)(const void *)up, len, len,
306 				IPPROTO_UDP);
307 }
308 
309 static int udp6_cksum(netdissect_options *ndo, const struct ip6_hdr *ip6,
310 		      const struct udphdr *up, u_int len)
311 {
312 	return nextproto6_cksum(ndo, ip6, (const uint8_t *)(const void *)up, len, len,
313 				IPPROTO_UDP);
314 }
315 
316 static void
317 udpipaddr_print(netdissect_options *ndo, const struct ip *ip, int sport, int dport)
318 {
319 	const struct ip6_hdr *ip6;
320 
321 	if (IP_V(ip) == 6)
322 		ip6 = (const struct ip6_hdr *)ip;
323 	else
324 		ip6 = NULL;
325 
326 	if (ip6) {
327 		if (ip6->ip6_nxt == IPPROTO_UDP) {
328 			if (sport == -1) {
329 				ND_PRINT((ndo, "%s > %s: ",
330 					ip6addr_string(ndo, &ip6->ip6_src),
331 					ip6addr_string(ndo, &ip6->ip6_dst)));
332 			} else {
333 				ND_PRINT((ndo, "%s.%s > %s.%s: ",
334 					ip6addr_string(ndo, &ip6->ip6_src),
335 					udpport_string(ndo, sport),
336 					ip6addr_string(ndo, &ip6->ip6_dst),
337 					udpport_string(ndo, dport)));
338 			}
339 		} else {
340 			if (sport != -1) {
341 				ND_PRINT((ndo, "%s > %s: ",
342 					udpport_string(ndo, sport),
343 					udpport_string(ndo, dport)));
344 			}
345 		}
346 	} else {
347 		if (ip->ip_p == IPPROTO_UDP) {
348 			if (sport == -1) {
349 				ND_PRINT((ndo, "%s > %s: ",
350 					ipaddr_string(ndo, &ip->ip_src),
351 					ipaddr_string(ndo, &ip->ip_dst)));
352 			} else {
353 				ND_PRINT((ndo, "%s.%s > %s.%s: ",
354 					ipaddr_string(ndo, &ip->ip_src),
355 					udpport_string(ndo, sport),
356 					ipaddr_string(ndo, &ip->ip_dst),
357 					udpport_string(ndo, dport)));
358 			}
359 		} else {
360 			if (sport != -1) {
361 				ND_PRINT((ndo, "%s > %s: ",
362 					udpport_string(ndo, sport),
363 					udpport_string(ndo, dport)));
364 			}
365 		}
366 	}
367 }
368 
369 void
370 udp_print(netdissect_options *ndo, register const u_char *bp, u_int length,
371 	  register const u_char *bp2, int fragmented)
372 {
373 	register const struct udphdr *up;
374 	register const struct ip *ip;
375 	register const u_char *cp;
376 	register const u_char *ep = bp + length;
377 	uint16_t sport, dport, ulen;
378 	register const struct ip6_hdr *ip6;
379 
380 	if (ep > ndo->ndo_snapend)
381 		ep = ndo->ndo_snapend;
382 	up = (const struct udphdr *)bp;
383 	ip = (const struct ip *)bp2;
384 	if (IP_V(ip) == 6)
385 		ip6 = (const struct ip6_hdr *)bp2;
386 	else
387 		ip6 = NULL;
388 	if (!ND_TTEST(up->uh_dport)) {
389 		udpipaddr_print(ndo, ip, -1, -1);
390 		goto trunc;
391 	}
392 
393 	sport = EXTRACT_16BITS(&up->uh_sport);
394 	dport = EXTRACT_16BITS(&up->uh_dport);
395 
396 	if (length < sizeof(struct udphdr)) {
397 		udpipaddr_print(ndo, ip, sport, dport);
398 		ND_PRINT((ndo, "truncated-udp %d", length));
399 		return;
400 	}
401 	if (!ND_TTEST(up->uh_ulen)) {
402 		udpipaddr_print(ndo, ip, sport, dport);
403 		goto trunc;
404 	}
405 	ulen = EXTRACT_16BITS(&up->uh_ulen);
406 	if (ulen < sizeof(struct udphdr)) {
407 		udpipaddr_print(ndo, ip, sport, dport);
408 		ND_PRINT((ndo, "truncated-udplength %d", ulen));
409 		return;
410 	}
411 	ulen -= sizeof(struct udphdr);
412 	length -= sizeof(struct udphdr);
413 	if (ulen < length)
414 		length = ulen;
415 
416 	cp = (const u_char *)(up + 1);
417 	if (cp > ndo->ndo_snapend) {
418 		udpipaddr_print(ndo, ip, sport, dport);
419 		goto trunc;
420 	}
421 
422 	if (ndo->ndo_packettype) {
423 		register const struct sunrpc_msg *rp;
424 		enum sunrpc_msg_type direction;
425 
426 		switch (ndo->ndo_packettype) {
427 
428 		case PT_VAT:
429 			udpipaddr_print(ndo, ip, sport, dport);
430 			vat_print(ndo, (const void *)(up + 1), up);
431 			break;
432 
433 		case PT_WB:
434 			udpipaddr_print(ndo, ip, sport, dport);
435 			wb_print(ndo, (const void *)(up + 1), length);
436 			break;
437 
438 		case PT_RPC:
439 			rp = (const struct sunrpc_msg *)(up + 1);
440 			direction = (enum sunrpc_msg_type)EXTRACT_32BITS(&rp->rm_direction);
441 			if (direction == SUNRPC_CALL)
442 				sunrpcrequest_print(ndo, (const u_char *)rp, length,
443 				    (const u_char *)ip);
444 			else
445 				nfsreply_print(ndo, (const u_char *)rp, length,
446 				    (const u_char *)ip);			/*XXX*/
447 			break;
448 
449 		case PT_RTP:
450 			udpipaddr_print(ndo, ip, sport, dport);
451 			rtp_print(ndo, (const void *)(up + 1), length, up);
452 			break;
453 
454 		case PT_RTCP:
455 			udpipaddr_print(ndo, ip, sport, dport);
456 			while (cp < ep)
457 				cp = rtcp_print(ndo, cp, ep);
458 			break;
459 
460 		case PT_SNMP:
461 			udpipaddr_print(ndo, ip, sport, dport);
462 			snmp_print(ndo, (const u_char *)(up + 1), length);
463 			break;
464 
465 		case PT_CNFP:
466 			udpipaddr_print(ndo, ip, sport, dport);
467 			cnfp_print(ndo, cp);
468 			break;
469 
470 		case PT_TFTP:
471 			udpipaddr_print(ndo, ip, sport, dport);
472 			tftp_print(ndo, cp, length);
473 			break;
474 
475 		case PT_AODV:
476 			udpipaddr_print(ndo, ip, sport, dport);
477 			aodv_print(ndo, (const u_char *)(up + 1), length,
478 			    ip6 != NULL);
479 			break;
480 
481 		case PT_RADIUS:
482 			udpipaddr_print(ndo, ip, sport, dport);
483 			radius_print(ndo, cp, length);
484 			break;
485 
486 		case PT_VXLAN:
487 			udpipaddr_print(ndo, ip, sport, dport);
488 			vxlan_print(ndo, (const u_char *)(up + 1), length);
489 			break;
490 
491 		case PT_PGM:
492 		case PT_PGM_ZMTP1:
493 			udpipaddr_print(ndo, ip, sport, dport);
494 			pgm_print(ndo, cp, length, bp2);
495 			break;
496 		case PT_LMP:
497 			udpipaddr_print(ndo, ip, sport, dport);
498 			lmp_print(ndo, cp, length);
499 			break;
500 		}
501 		return;
502 	}
503 
504 	udpipaddr_print(ndo, ip, sport, dport);
505 	if (!ndo->ndo_qflag) {
506 		register const struct sunrpc_msg *rp;
507 		enum sunrpc_msg_type direction;
508 
509 		rp = (const struct sunrpc_msg *)(up + 1);
510 		if (ND_TTEST(rp->rm_direction)) {
511 			direction = (enum sunrpc_msg_type)EXTRACT_32BITS(&rp->rm_direction);
512 			if (dport == NFS_PORT && direction == SUNRPC_CALL) {
513 				ND_PRINT((ndo, "NFS request xid %u ", EXTRACT_32BITS(&rp->rm_xid)));
514 				nfsreq_print_noaddr(ndo, (const u_char *)rp, length,
515 				    (const u_char *)ip);
516 				return;
517 			}
518 			if (sport == NFS_PORT && direction == SUNRPC_REPLY) {
519 				ND_PRINT((ndo, "NFS reply xid %u ", EXTRACT_32BITS(&rp->rm_xid)));
520 				nfsreply_print_noaddr(ndo, (const u_char *)rp, length,
521 				    (const u_char *)ip);
522 				return;
523 			}
524 #ifdef notdef
525 			if (dport == SUNRPC_PORT && direction == SUNRPC_CALL) {
526 				sunrpcrequest_print((const u_char *)rp, length, (const u_char *)ip);
527 				return;
528 			}
529 #endif
530 		}
531 	}
532 
533 	if (ndo->ndo_vflag && !ndo->ndo_Kflag && !fragmented) {
534                 /* Check the checksum, if possible. */
535                 uint16_t sum, udp_sum;
536 
537 		/*
538 		 * XXX - do this even if vflag == 1?
539 		 * TCP does, and we do so for UDP-over-IPv6.
540 		 */
541 	        if (IP_V(ip) == 4 && (ndo->ndo_vflag > 1)) {
542 			udp_sum = EXTRACT_16BITS(&up->uh_sum);
543 			if (udp_sum == 0) {
544 				ND_PRINT((ndo, "[no cksum] "));
545 			} else if (ND_TTEST2(cp[0], length)) {
546 				sum = udp_cksum(ndo, ip, up, length + sizeof(struct udphdr));
547 
548 	                        if (sum != 0) {
549 					ND_PRINT((ndo, "[bad udp cksum 0x%04x -> 0x%04x!] ",
550 					    udp_sum,
551 					    in_cksum_shouldbe(udp_sum, sum)));
552 				} else
553 					ND_PRINT((ndo, "[udp sum ok] "));
554 			}
555 		}
556 		else if (IP_V(ip) == 6 && ip6->ip6_plen) {
557 			/* for IPv6, UDP checksum is mandatory */
558 			if (ND_TTEST2(cp[0], length)) {
559 				sum = udp6_cksum(ndo, ip6, up, length + sizeof(struct udphdr));
560 				udp_sum = EXTRACT_16BITS(&up->uh_sum);
561 
562 	                        if (sum != 0) {
563 					ND_PRINT((ndo, "[bad udp cksum 0x%04x -> 0x%04x!] ",
564 					    udp_sum,
565 					    in_cksum_shouldbe(udp_sum, sum)));
566 				} else
567 					ND_PRINT((ndo, "[udp sum ok] "));
568 			}
569 		}
570 	}
571 
572 	if (!ndo->ndo_qflag) {
573 		if (IS_SRC_OR_DST_PORT(NAMESERVER_PORT))
574 			ns_print(ndo, (const u_char *)(up + 1), length, 0);
575 		else if (IS_SRC_OR_DST_PORT(MULTICASTDNS_PORT))
576 			ns_print(ndo, (const u_char *)(up + 1), length, 1);
577 		else if (IS_SRC_OR_DST_PORT(TIMED_PORT))
578 			timed_print(ndo, (const u_char *)(up + 1));
579 		else if (IS_SRC_OR_DST_PORT(TFTP_PORT))
580 			tftp_print(ndo, (const u_char *)(up + 1), length);
581 		else if (IS_SRC_OR_DST_PORT(BOOTPC_PORT) || IS_SRC_OR_DST_PORT(BOOTPS_PORT))
582 			bootp_print(ndo, (const u_char *)(up + 1), length);
583 		else if (IS_SRC_OR_DST_PORT(RIP_PORT))
584 			rip_print(ndo, (const u_char *)(up + 1), length);
585 		else if (IS_SRC_OR_DST_PORT(AODV_PORT))
586 			aodv_print(ndo, (const u_char *)(up + 1), length,
587 			    ip6 != NULL);
588 	        else if (IS_SRC_OR_DST_PORT(ISAKMP_PORT))
589 			 isakmp_print(ndo, (const u_char *)(up + 1), length, bp2);
590 	        else if (IS_SRC_OR_DST_PORT(ISAKMP_PORT_NATT))
591 			 isakmp_rfc3948_print(ndo, (const u_char *)(up + 1), length, bp2);
592 #if 1 /*???*/
593 	        else if (IS_SRC_OR_DST_PORT(ISAKMP_PORT_USER1) || IS_SRC_OR_DST_PORT(ISAKMP_PORT_USER2))
594 			isakmp_print(ndo, (const u_char *)(up + 1), length, bp2);
595 #endif
596 		else if (IS_SRC_OR_DST_PORT(SNMP_PORT) || IS_SRC_OR_DST_PORT(SNMPTRAP_PORT))
597 			snmp_print(ndo, (const u_char *)(up + 1), length);
598 		else if (IS_SRC_OR_DST_PORT(NTP_PORT))
599 			ntp_print(ndo, (const u_char *)(up + 1), length);
600 		else if (IS_SRC_OR_DST_PORT(KERBEROS_PORT) || IS_SRC_OR_DST_PORT(KERBEROS_SEC_PORT))
601 			krb_print(ndo, (const void *)(up + 1));
602 		else if (IS_SRC_OR_DST_PORT(L2TP_PORT))
603 			l2tp_print(ndo, (const u_char *)(up + 1), length);
604 #ifdef ENABLE_SMB
605 		else if (IS_SRC_OR_DST_PORT(NETBIOS_NS_PORT))
606 			nbt_udp137_print(ndo, (const u_char *)(up + 1), length);
607 		else if (IS_SRC_OR_DST_PORT(NETBIOS_DGRAM_PORT))
608 			nbt_udp138_print(ndo, (const u_char *)(up + 1), length);
609 #endif
610 		else if (dport == VAT_PORT)
611 			vat_print(ndo, (const void *)(up + 1), up);
612 		else if (IS_SRC_OR_DST_PORT(ZEPHYR_SRV_PORT) || IS_SRC_OR_DST_PORT(ZEPHYR_CLT_PORT))
613 			zephyr_print(ndo, (const void *)(up + 1), length);
614 		/*
615 		 * Since there are 10 possible ports to check, I think
616 		 * a <> test would be more efficient
617 		 */
618 		else if ((sport >= RX_PORT_LOW && sport <= RX_PORT_HIGH) ||
619 			 (dport >= RX_PORT_LOW && dport <= RX_PORT_HIGH))
620 			rx_print(ndo, (const void *)(up + 1), length, sport, dport,
621 				 (const u_char *) ip);
622 		else if (IS_SRC_OR_DST_PORT(RIPNG_PORT))
623 			ripng_print(ndo, (const u_char *)(up + 1), length);
624 		else if (IS_SRC_OR_DST_PORT(DHCP6_SERV_PORT) || IS_SRC_OR_DST_PORT(DHCP6_CLI_PORT))
625 			dhcp6_print(ndo, (const u_char *)(up + 1), length);
626 		else if (IS_SRC_OR_DST_PORT(AHCP_PORT))
627 			ahcp_print(ndo, (const u_char *)(up + 1), length);
628 		else if (IS_SRC_OR_DST_PORT(BABEL_PORT) || IS_SRC_OR_DST_PORT(BABEL_PORT_OLD))
629 			babel_print(ndo, (const u_char *)(up + 1), length);
630 		else if (IS_SRC_OR_DST_PORT(HNCP_PORT))
631 			hncp_print(ndo, (const u_char *)(up + 1), length);
632 		/*
633 		 * Kludge in test for whiteboard packets.
634 		 */
635 		else if (dport == WB_PORT)
636 			wb_print(ndo, (const void *)(up + 1), length);
637 		else if (IS_SRC_OR_DST_PORT(CISCO_AUTORP_PORT))
638 			cisco_autorp_print(ndo, (const void *)(up + 1), length);
639 		else if (IS_SRC_OR_DST_PORT(RADIUS_PORT) ||
640 			 IS_SRC_OR_DST_PORT(RADIUS_NEW_PORT) ||
641 			 IS_SRC_OR_DST_PORT(RADIUS_ACCOUNTING_PORT) ||
642 			 IS_SRC_OR_DST_PORT(RADIUS_NEW_ACCOUNTING_PORT) ||
643 			 IS_SRC_OR_DST_PORT(RADIUS_CISCO_COA_PORT) ||
644 			 IS_SRC_OR_DST_PORT(RADIUS_COA_PORT) )
645 			radius_print(ndo, (const u_char *)(up+1), length);
646 		else if (dport == HSRP_PORT)
647 			hsrp_print(ndo, (const u_char *)(up + 1), length);
648 		else if (IS_SRC_OR_DST_PORT(LWRES_PORT))
649 			lwres_print(ndo, (const u_char *)(up + 1), length);
650 		else if (IS_SRC_OR_DST_PORT(LDP_PORT))
651 			ldp_print(ndo, (const u_char *)(up + 1), length);
652 		else if (IS_SRC_OR_DST_PORT(OLSR_PORT))
653 			olsr_print(ndo, (const u_char *)(up + 1), length,
654 					(IP_V(ip) == 6) ? 1 : 0);
655 		else if (IS_SRC_OR_DST_PORT(MPLS_LSP_PING_PORT))
656 			lspping_print(ndo, (const u_char *)(up + 1), length);
657 		else if (dport == BFD_CONTROL_PORT ||
658 			 dport == BFD_ECHO_PORT )
659 			bfd_print(ndo, (const u_char *)(up+1), length, dport);
660                 else if (IS_SRC_OR_DST_PORT(LMP_PORT))
661 			lmp_print(ndo, (const u_char *)(up + 1), length);
662 		else if (IS_SRC_OR_DST_PORT(VQP_PORT))
663 			vqp_print(ndo, (const u_char *)(up + 1), length);
664                 else if (IS_SRC_OR_DST_PORT(SFLOW_PORT))
665                         sflow_print(ndo, (const u_char *)(up + 1), length);
666 	        else if (dport == LWAPP_CONTROL_PORT)
667 			lwapp_control_print(ndo, (const u_char *)(up + 1), length, 1);
668                 else if (sport == LWAPP_CONTROL_PORT)
669                         lwapp_control_print(ndo, (const u_char *)(up + 1), length, 0);
670                 else if (IS_SRC_OR_DST_PORT(LWAPP_DATA_PORT))
671                         lwapp_data_print(ndo, (const u_char *)(up + 1), length);
672                 else if (IS_SRC_OR_DST_PORT(SIP_PORT))
673 			sip_print(ndo, (const u_char *)(up + 1), length);
674                 else if (IS_SRC_OR_DST_PORT(SYSLOG_PORT))
675 			syslog_print(ndo, (const u_char *)(up + 1), length);
676                 else if (IS_SRC_OR_DST_PORT(OTV_PORT))
677 			otv_print(ndo, (const u_char *)(up + 1), length);
678                 else if (IS_SRC_OR_DST_PORT(VXLAN_PORT))
679 			vxlan_print(ndo, (const u_char *)(up + 1), length);
680                 else if (IS_SRC_OR_DST_PORT(GENEVE_PORT))
681 			geneve_print(ndo, (const u_char *)(up + 1), length);
682 		else if (IS_SRC_OR_DST_PORT(LISP_CONTROL_PORT))
683 			lisp_print(ndo, (const u_char *)(up + 1), length);
684 		else if (IS_SRC_OR_DST_PORT(VXLAN_GPE_PORT))
685 			vxlan_gpe_print(ndo, (const u_char *)(up + 1), length);
686 		else if (ND_TTEST(((const struct LAP *)cp)->type) &&
687 		    ((const struct LAP *)cp)->type == lapDDP &&
688 		    (atalk_port(sport) || atalk_port(dport))) {
689 			if (ndo->ndo_vflag)
690 				ND_PRINT((ndo, "kip "));
691 			llap_print(ndo, cp, length);
692 		} else {
693 			if (ulen > length)
694 				ND_PRINT((ndo, "UDP, bad length %u > %u",
695 				    ulen, length));
696 			else
697 				ND_PRINT((ndo, "UDP, length %u", ulen));
698 		}
699 	} else {
700 		if (ulen > length)
701 			ND_PRINT((ndo, "UDP, bad length %u > %u",
702 			    ulen, length));
703 		else
704 			ND_PRINT((ndo, "UDP, length %u", ulen));
705 	}
706 	return;
707 
708 trunc:
709 	ND_PRINT((ndo, "%s", udp_tstr));
710 }
711 
712 
713 /*
714  * Local Variables:
715  * c-style: whitesmith
716  * c-basic-offset: 8
717  * End:
718  */
719