2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
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
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.
26 #include <tcpdump-stdinc.h>
35 #include "interface.h"
36 #include "addrtoname.h"
38 #include "appletalk.h"
55 u_int16_t rh_flags
; /* T:2 P:1 CNT:5 PT:8 */
56 u_int16_t rh_len
; /* length of message (in words) */
57 u_int32_t rh_ssrc
; /* synchronization src id */
61 u_int32_t upper
; /* more significant 32 bits */
62 u_int32_t lower
; /* less significant 32 bits */
69 ntp64 sr_ntp
; /* 64-bit ntp timestamp */
70 u_int32_t sr_ts
; /* reference media timestamp */
71 u_int32_t sr_np
; /* no. packets sent */
72 u_int32_t sr_nb
; /* no. bytes sent */
77 * Time stamps are middle 32-bits of ntp timestamp.
80 u_int32_t rr_srcid
; /* sender being reported */
81 u_int32_t rr_nl
; /* no. packets lost */
82 u_int32_t rr_ls
; /* extended last seq number received */
83 u_int32_t rr_dv
; /* jitter (delay variance) */
84 u_int32_t rr_lsr
; /* orig. ts from last rr from this src */
85 u_int32_t rr_dlsr
; /* time from recpt of last rr to xmit time */
89 #define RTCP_PT_SR 200
90 #define RTCP_PT_RR 201
91 #define RTCP_PT_SDES 202
92 #define RTCP_SDES_CNAME 1
93 #define RTCP_SDES_NAME 2
94 #define RTCP_SDES_EMAIL 3
95 #define RTCP_SDES_PHONE 4
96 #define RTCP_SDES_LOC 5
97 #define RTCP_SDES_TOOL 6
98 #define RTCP_SDES_NOTE 7
99 #define RTCP_SDES_PRIV 8
100 #define RTCP_PT_BYE 203
101 #define RTCP_PT_APP 204
104 vat_print(const void *hdr
, register const struct udphdr
*up
)
107 u_int ts
= *(u_int16_t
*)hdr
;
108 if ((ts
& 0xf060) != 0) {
110 (void)printf("udp/vt %u %d / %d",
111 (u_int32_t
)(EXTRACT_16BITS(&up
->uh_ulen
) - sizeof(*up
)),
112 ts
& 0x3ff, ts
>> 10);
115 u_int32_t i0
= EXTRACT_32BITS(&((u_int
*)hdr
)[0]);
116 u_int32_t i1
= EXTRACT_32BITS(&((u_int
*)hdr
)[1]);
117 printf("udp/vat %u c%d %u%s",
118 (u_int32_t
)(EXTRACT_16BITS(&up
->uh_ulen
) - sizeof(*up
) - 8),
120 i1
, i0
& 0x800000? "*" : "");
123 printf(" f%d", (i0
>> 16) & 0x1f);
125 printf(" s%d", (i0
>> 24) & 0x3f);
130 rtp_print(const void *hdr
, u_int len
, register const struct udphdr
*up
)
133 u_int
*ip
= (u_int
*)hdr
;
134 u_int hasopt
, hasext
, contype
, hasmarker
;
135 u_int32_t i0
= EXTRACT_32BITS(&((u_int
*)hdr
)[0]);
136 u_int32_t i1
= EXTRACT_32BITS(&((u_int
*)hdr
)[1]);
137 u_int dlen
= EXTRACT_16BITS(&up
->uh_ulen
) - sizeof(*up
) - 8;
145 if ((i0
>> 30) == 1) {
147 hasopt
= i0
& 0x800000;
148 contype
= (i0
>> 16) & 0x3f;
149 hasmarker
= i0
& 0x400000;
153 hasext
= i0
& 0x10000000;
154 contype
= (i0
>> 16) & 0x7f;
155 hasmarker
= i0
& 0x800000;
161 printf("udp/%s %d c%d %s%s %d %u",
165 (hasopt
|| hasext
)? "+" : "",
170 printf(" %u", EXTRACT_32BITS(&((u_int
*)hdr
)[2]));
175 optlen
= (i2
>> 16) & 0xff;
176 if (optlen
== 0 || optlen
> len
) {
182 } while ((int)i2
>= 0);
187 extlen
= (i2
& 0xffff) + 1;
194 if (contype
== 0x1f) /*XXX H.261 */
195 printf(" 0x%04x", ip
[0] >> 16);
199 static const u_char
*
200 rtcp_print(const u_char
*hdr
, const u_char
*ep
)
202 /* rtp v2 control (rtcp) */
203 struct rtcp_rr
*rr
= 0;
205 struct rtcphdr
*rh
= (struct rtcphdr
*)hdr
;
210 if ((u_char
*)(rh
+ 1) > ep
) {
214 len
= (EXTRACT_16BITS(&rh
->rh_len
) + 1) * 4;
215 flags
= EXTRACT_16BITS(&rh
->rh_flags
);
216 cnt
= (flags
>> 8) & 0x1f;
217 switch (flags
& 0xff) {
219 sr
= (struct rtcp_sr
*)(rh
+ 1);
221 if (len
!= cnt
* sizeof(*rr
) + sizeof(*sr
) + sizeof(*rh
))
222 printf(" [%d]", len
);
224 printf(" %u", EXTRACT_32BITS(&rh
->rh_ssrc
));
225 if ((u_char
*)(sr
+ 1) > ep
) {
229 ts
= (double)(EXTRACT_32BITS(&sr
->sr_ntp
.upper
)) +
230 ((double)(EXTRACT_32BITS(&sr
->sr_ntp
.lower
)) /
232 printf(" @%.2f %u %up %ub", ts
, EXTRACT_32BITS(&sr
->sr_ts
),
233 EXTRACT_32BITS(&sr
->sr_np
), EXTRACT_32BITS(&sr
->sr_nb
));
234 rr
= (struct rtcp_rr
*)(sr
+ 1);
238 if (len
!= cnt
* sizeof(*rr
) + sizeof(*rh
))
239 printf(" [%d]", len
);
240 rr
= (struct rtcp_rr
*)(rh
+ 1);
242 printf(" %u", EXTRACT_32BITS(&rh
->rh_ssrc
));
245 printf(" sdes %d", len
);
247 printf(" %u", EXTRACT_32BITS(&rh
->rh_ssrc
));
251 printf(" bye %d", len
);
253 printf(" %u", EXTRACT_32BITS(&rh
->rh_ssrc
));
257 printf(" type-0x%x %d", flags
& 0xff, len
);
264 if ((u_char
*)(rr
+ 1) > ep
) {
269 printf(" %u", EXTRACT_32BITS(&rr
->rr_srcid
));
270 ts
= (double)(EXTRACT_32BITS(&rr
->rr_lsr
)) / 65536.;
271 dts
= (double)(EXTRACT_32BITS(&rr
->rr_dlsr
)) / 65536.;
272 printf(" %ul %us %uj @%.2f+%.2f",
273 EXTRACT_32BITS(&rr
->rr_nl
) & 0x00ffffff,
274 EXTRACT_32BITS(&rr
->rr_ls
),
275 EXTRACT_32BITS(&rr
->rr_dv
), ts
, dts
);
280 static int udp_cksum(register const struct ip
*ip
,
281 register const struct udphdr
*up
,
284 return nextproto4_cksum(ip
, (const u_int8_t
*)(void *)up
, len
, len
,
289 static int udp6_cksum(const struct ip6_hdr
*ip6
, const struct udphdr
*up
,
292 return (nextproto6_cksum(ip6
, (const u_int8_t
*)(void *)up
, len
,
298 udpipaddr_print(const struct ip
*ip
, int sport
, int dport
)
301 const struct ip6_hdr
*ip6
;
304 ip6
= (const struct ip6_hdr
*)ip
;
309 if (ip6
->ip6_nxt
== IPPROTO_UDP
) {
311 (void)printf("%s > %s: ",
312 ip6addr_string(&ip6
->ip6_src
),
313 ip6addr_string(&ip6
->ip6_dst
));
315 (void)printf("%s.%s > %s.%s: ",
316 ip6addr_string(&ip6
->ip6_src
),
317 udpport_string(sport
),
318 ip6addr_string(&ip6
->ip6_dst
),
319 udpport_string(dport
));
323 (void)printf("%s > %s: ",
324 udpport_string(sport
),
325 udpport_string(dport
));
331 if (ip
->ip_p
== IPPROTO_UDP
) {
333 (void)printf("%s > %s: ",
334 ipaddr_string(&ip
->ip_src
),
335 ipaddr_string(&ip
->ip_dst
));
337 (void)printf("%s.%s > %s.%s: ",
338 ipaddr_string(&ip
->ip_src
),
339 udpport_string(sport
),
340 ipaddr_string(&ip
->ip_dst
),
341 udpport_string(dport
));
345 (void)printf("%s > %s: ",
346 udpport_string(sport
),
347 udpport_string(dport
));
354 udp_print(register const u_char
*bp
, u_int length
,
355 register const u_char
*bp2
, int fragmented
)
357 register const struct udphdr
*up
;
358 register const struct ip
*ip
;
359 register const u_char
*cp
;
360 register const u_char
*ep
= bp
+ length
;
361 u_int16_t sport
, dport
, ulen
;
363 register const struct ip6_hdr
*ip6
;
368 up
= (struct udphdr
*)bp
;
369 ip
= (struct ip
*)bp2
;
372 ip6
= (struct ip6_hdr
*)bp2
;
376 cp
= (u_char
*)(up
+ 1);
377 if (!TTEST(up
->uh_dport
)) {
378 udpipaddr_print(ip
, -1, -1);
379 (void)printf("[|udp]");
383 sport
= EXTRACT_16BITS(&up
->uh_sport
);
384 dport
= EXTRACT_16BITS(&up
->uh_dport
);
386 if (length
< sizeof(struct udphdr
)) {
387 udpipaddr_print(ip
, sport
, dport
);
388 (void)printf("truncated-udp %d", length
);
391 length
-= sizeof(struct udphdr
);
394 udpipaddr_print(ip
, sport
, dport
);
395 (void)printf("[|udp]");
399 ulen
= EXTRACT_16BITS(&up
->uh_ulen
);
401 udpipaddr_print(ip
, sport
, dport
);
402 (void)printf("truncated-udplength %d", ulen
);
406 register struct sunrpc_msg
*rp
;
407 enum sunrpc_msg_type direction
;
409 switch (packettype
) {
412 udpipaddr_print(ip
, sport
, dport
);
413 vat_print((void *)(up
+ 1), up
);
417 udpipaddr_print(ip
, sport
, dport
);
418 wb_print((void *)(up
+ 1), length
);
422 rp
= (struct sunrpc_msg
*)(up
+ 1);
423 direction
= (enum sunrpc_msg_type
)EXTRACT_32BITS(&rp
->rm_direction
);
424 if (direction
== SUNRPC_CALL
)
425 sunrpcrequest_print((u_char
*)rp
, length
,
428 nfsreply_print((u_char
*)rp
, length
,
429 (u_char
*)ip
); /*XXX*/
433 udpipaddr_print(ip
, sport
, dport
);
434 rtp_print((void *)(up
+ 1), length
, up
);
438 udpipaddr_print(ip
, sport
, dport
);
440 cp
= rtcp_print(cp
, ep
);
444 udpipaddr_print(ip
, sport
, dport
);
445 snmp_print((const u_char
*)(up
+ 1), length
);
449 udpipaddr_print(ip
, sport
, dport
);
450 cnfp_print(cp
, (const u_char
*)ip
);
454 udpipaddr_print(ip
, sport
, dport
);
455 tftp_print(cp
, length
);
459 udpipaddr_print(ip
, sport
, dport
);
460 aodv_print((const u_char
*)(up
+ 1), length
,
469 udpipaddr_print(ip
, sport
, dport
);
470 radius_print(cp
, length
);
474 udpipaddr_print(ip
, sport
, dport
);
475 vxlan_print((const u_char
*)(up
+ 1), length
);
480 udpipaddr_print(ip
, sport
, dport
);
481 pgm_print(cp
, length
, bp2
);
484 udpipaddr_print(ip
, sport
, dport
);
485 lmp_print(cp
, length
);
492 register struct sunrpc_msg
*rp
;
493 enum sunrpc_msg_type direction
;
495 rp
= (struct sunrpc_msg
*)(up
+ 1);
496 if (TTEST(rp
->rm_direction
)) {
497 direction
= (enum sunrpc_msg_type
)EXTRACT_32BITS(&rp
->rm_direction
);
498 if (dport
== NFS_PORT
&& direction
== SUNRPC_CALL
) {
499 nfsreq_print((u_char
*)rp
, length
,
503 if (sport
== NFS_PORT
&& direction
== SUNRPC_REPLY
) {
504 nfsreply_print((u_char
*)rp
, length
,
509 if (dport
== SUNRPC_PORT
&& direction
== SUNRPC_CALL
) {
510 sunrpcrequest_print((u_char
*)rp
, length
, (u_char
*)ip
);
515 if (TTEST(((struct LAP
*)cp
)->type
) &&
516 ((struct LAP
*)cp
)->type
== lapDDP
&&
517 (atalk_port(sport
) || atalk_port(dport
))) {
519 fputs("kip ", stdout
);
520 llap_print(cp
, length
);
524 udpipaddr_print(ip
, sport
, dport
);
526 if (vflag
&& !Kflag
&& !fragmented
) {
527 /* Check the checksum, if possible. */
528 u_int16_t sum
, udp_sum
;
531 * XXX - do this even if vflag == 1?
532 * TCP does, and we do so for UDP-over-IPv6.
534 if (IP_V(ip
) == 4 && (vflag
> 1)) {
535 udp_sum
= EXTRACT_16BITS(&up
->uh_sum
);
537 (void)printf("[no cksum] ");
538 } else if (TTEST2(cp
[0], length
)) {
539 sum
= udp_cksum(ip
, up
, length
+ sizeof(struct udphdr
));
542 (void)printf("[bad udp cksum 0x%04x -> 0x%04x!] ",
544 in_cksum_shouldbe(udp_sum
, sum
));
546 (void)printf("[udp sum ok] ");
550 else if (IP_V(ip
) == 6 && ip6
->ip6_plen
) {
551 /* for IPv6, UDP checksum is mandatory */
552 if (TTEST2(cp
[0], length
)) {
553 sum
= udp6_cksum(ip6
, up
, length
+ sizeof(struct udphdr
));
554 udp_sum
= EXTRACT_16BITS(&up
->uh_sum
);
557 (void)printf("[bad udp cksum 0x%04x -> 0x%04x!] ",
559 in_cksum_shouldbe(udp_sum
, sum
));
561 (void)printf("[udp sum ok] ");
568 #define ISPORT(p) (dport == (p) || sport == (p))
569 if (ISPORT(NAMESERVER_PORT
))
570 ns_print((const u_char
*)(up
+ 1), length
, 0);
571 else if (ISPORT(MULTICASTDNS_PORT
))
572 ns_print((const u_char
*)(up
+ 1), length
, 1);
573 else if (ISPORT(TIMED_PORT
))
574 timed_print((const u_char
*)(up
+ 1));
575 else if (ISPORT(TFTP_PORT
))
576 tftp_print((const u_char
*)(up
+ 1), length
);
577 else if (ISPORT(IPPORT_BOOTPC
) || ISPORT(IPPORT_BOOTPS
))
578 bootp_print((const u_char
*)(up
+ 1), length
);
579 else if (ISPORT(RIP_PORT
))
580 rip_print((const u_char
*)(up
+ 1), length
);
581 else if (ISPORT(AODV_PORT
))
582 aodv_print((const u_char
*)(up
+ 1), length
,
588 else if (ISPORT(ISAKMP_PORT
))
589 isakmp_print(gndo
, (const u_char
*)(up
+ 1), length
, bp2
);
590 else if (ISPORT(ISAKMP_PORT_NATT
))
591 isakmp_rfc3948_print(gndo
, (const u_char
*)(up
+ 1), length
, bp2
);
593 else if (ISPORT(ISAKMP_PORT_USER1
) || ISPORT(ISAKMP_PORT_USER2
))
594 isakmp_print(gndo
, (const u_char
*)(up
+ 1), length
, bp2
);
596 else if (ISPORT(SNMP_PORT
) || ISPORT(SNMPTRAP_PORT
))
597 snmp_print((const u_char
*)(up
+ 1), length
);
598 else if (ISPORT(NTP_PORT
))
599 ntp_print((const u_char
*)(up
+ 1), length
);
600 else if (ISPORT(KERBEROS_PORT
) || ISPORT(KERBEROS_SEC_PORT
))
601 krb_print((const void *)(up
+ 1));
602 else if (ISPORT(L2TP_PORT
))
603 l2tp_print((const u_char
*)(up
+ 1), length
);
604 #ifdef TCPDUMP_DO_SMB
605 else if (ISPORT(NETBIOS_NS_PORT
))
606 nbt_udp137_print((const u_char
*)(up
+ 1), length
);
607 else if (ISPORT(NETBIOS_DGRAM_PORT
))
608 nbt_udp138_print((const u_char
*)(up
+ 1), length
);
610 else if (dport
== VAT_PORT
)
611 vat_print((const void *)(up
+ 1), up
);
612 else if (ISPORT(ZEPHYR_SRV_PORT
) || ISPORT(ZEPHYR_CLT_PORT
))
613 zephyr_print((const void *)(up
+ 1), length
);
615 * Since there are 10 possible ports to check, I think
616 * a <> test would be more efficient
618 else if ((sport
>= RX_PORT_LOW
&& sport
<= RX_PORT_HIGH
) ||
619 (dport
>= RX_PORT_LOW
&& dport
<= RX_PORT_HIGH
))
620 rx_print((const void *)(up
+ 1), length
, sport
, dport
,
623 else if (ISPORT(RIPNG_PORT
))
624 ripng_print((const u_char
*)(up
+ 1), length
);
625 else if (ISPORT(DHCP6_SERV_PORT
) || ISPORT(DHCP6_CLI_PORT
))
626 dhcp6_print((const u_char
*)(up
+ 1), length
);
627 else if (ISPORT(AHCP_PORT
))
628 ahcp_print((const u_char
*)(up
+ 1), length
);
629 else if (ISPORT(BABEL_PORT
) || ISPORT(BABEL_PORT_OLD
))
630 babel_print((const u_char
*)(up
+ 1), length
);
633 * Kludge in test for whiteboard packets.
635 else if (dport
== WB_PORT
)
636 wb_print((const void *)(up
+ 1), length
);
637 else if (ISPORT(CISCO_AUTORP_PORT
))
638 cisco_autorp_print((const void *)(up
+ 1), length
);
639 else if (ISPORT(RADIUS_PORT
) ||
640 ISPORT(RADIUS_NEW_PORT
) ||
641 ISPORT(RADIUS_ACCOUNTING_PORT
) ||
642 ISPORT(RADIUS_NEW_ACCOUNTING_PORT
) )
643 radius_print((const u_char
*)(up
+1), length
);
644 else if (dport
== HSRP_PORT
)
645 hsrp_print((const u_char
*)(up
+ 1), length
);
646 else if (ISPORT(LWRES_PORT
))
647 lwres_print((const u_char
*)(up
+ 1), length
);
648 else if (ISPORT(LDP_PORT
))
649 ldp_print((const u_char
*)(up
+ 1), length
);
650 else if (ISPORT(OLSR_PORT
))
651 olsr_print((const u_char
*)(up
+ 1), length
,
653 (IP_V(ip
) == 6) ? 1 : 0);
657 else if (ISPORT(MPLS_LSP_PING_PORT
))
658 lspping_print((const u_char
*)(up
+ 1), length
);
659 else if (dport
== BFD_CONTROL_PORT
||
660 dport
== BFD_ECHO_PORT
)
661 bfd_print((const u_char
*)(up
+1), length
, dport
);
662 else if (ISPORT(LMP_PORT
))
663 lmp_print((const u_char
*)(up
+ 1), length
);
664 else if (ISPORT(VQP_PORT
))
665 vqp_print((const u_char
*)(up
+ 1), length
);
666 else if (ISPORT(SFLOW_PORT
))
667 sflow_print((const u_char
*)(up
+ 1), length
);
668 else if (dport
== LWAPP_CONTROL_PORT
)
669 lwapp_control_print((const u_char
*)(up
+ 1), length
, 1);
670 else if (sport
== LWAPP_CONTROL_PORT
)
671 lwapp_control_print((const u_char
*)(up
+ 1), length
, 0);
672 else if (ISPORT(LWAPP_DATA_PORT
))
673 lwapp_data_print((const u_char
*)(up
+ 1), length
);
674 else if (ISPORT(SIP_PORT
))
675 sip_print((const u_char
*)(up
+ 1), length
);
676 else if (ISPORT(SYSLOG_PORT
))
677 syslog_print((const u_char
*)(up
+ 1), length
);
678 else if (ISPORT(OTV_PORT
))
679 otv_print((const u_char
*)(up
+ 1), length
);
680 else if (ISPORT(VXLAN_PORT
))
681 vxlan_print((const u_char
*)(up
+ 1), length
);
683 (void)printf("UDP, length %u",
684 (u_int32_t
)(ulen
- sizeof(*up
)));
687 (void)printf("UDP, length %u", (u_int32_t
)(ulen
- sizeof(*up
)));
693 * c-style: whitesmith