]>
The Tcpdump Group git mirrors - tcpdump/blob - print-udp.c
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.
23 static const char rcsid
[] =
24 "@(#) $Header: /tcpdump/master/tcpdump/print-udp.c,v 1.64 1999-11-17 05:45:58 assar Exp $ (LBL)";
27 #include <sys/param.h>
29 #include <sys/socket.h>
31 #include <netinet/in.h>
32 #include <netinet/in_systm.h>
33 #include <netinet/ip.h>
34 #include <netinet/ip_var.h>
35 #include <netinet/udp.h>
36 #include <netinet/udp_var.h>
39 #undef NOERROR /* Solaris sucks */
42 #undef T_UNSPEC /* SINIX does too */
44 #include <arpa/nameser.h>
48 #include <arpa/tftp.h>
55 #include <netinet/ip6.h>
58 #include "interface.h"
59 #include "addrtoname.h"
60 #include "appletalk.h"
66 u_short rh_flags
; /* T:2 P:1 CNT:5 PT:8 */
67 u_short rh_len
; /* length of message (in words) */
68 u_int rh_ssrc
; /* synchronization src id */
72 u_int upper
; /* more significant 32 bits */
73 u_int lower
; /* less significant 32 bits */
80 ntp64 sr_ntp
; /* 64-bit ntp timestamp */
81 u_int sr_ts
; /* reference media timestamp */
82 u_int sr_np
; /* no. packets sent */
83 u_int sr_nb
; /* no. bytes sent */
88 * Time stamps are middle 32-bits of ntp timestamp.
91 u_int rr_srcid
; /* sender being reported */
92 u_int rr_nl
; /* no. packets lost */
93 u_int rr_ls
; /* extended last seq number received */
94 u_int rr_dv
; /* jitter (delay variance) */
95 u_int rr_lsr
; /* orig. ts from last rr from this src */
96 u_int rr_dlsr
; /* time from recpt of last rr to xmit time */
100 #define RTCP_PT_SR 200
101 #define RTCP_PT_RR 201
102 #define RTCP_PT_SDES 202
103 #define RTCP_SDES_CNAME 1
104 #define RTCP_SDES_NAME 2
105 #define RTCP_SDES_EMAIL 3
106 #define RTCP_SDES_PHONE 4
107 #define RTCP_SDES_LOC 5
108 #define RTCP_SDES_TOOL 6
109 #define RTCP_SDES_NOTE 7
110 #define RTCP_SDES_PRIV 8
111 #define RTCP_PT_BYE 203
112 #define RTCP_PT_APP 204
115 vat_print(const void *hdr
, u_int len
, register const struct udphdr
*up
)
118 u_int ts
= *(u_short
*)hdr
;
119 if ((ts
& 0xf060) != 0) {
121 (void)printf(" udp/vt %u %d / %d",
122 (u_int32_t
)(ntohs(up
->uh_ulen
) - sizeof(*up
)),
123 ts
& 0x3ff, ts
>> 10);
126 u_int i0
= ntohl(((u_int
*)hdr
)[0]);
127 u_int i1
= ntohl(((u_int
*)hdr
)[1]);
128 printf(" udp/vat %u c%d %u%s",
129 (u_int32_t
)(ntohs(up
->uh_ulen
) - sizeof(*up
) - 8),
131 i1
, i0
& 0x800000? "*" : "");
134 printf(" f%d", (i0
>> 16) & 0x1f);
136 printf(" s%d", (i0
>> 24) & 0x3f);
141 rtp_print(const void *hdr
, u_int len
, register const struct udphdr
*up
)
144 u_int
*ip
= (u_int
*)hdr
;
145 u_int hasopt
, hasext
, contype
, hasmarker
;
146 u_int i0
= ntohl(((u_int
*)hdr
)[0]);
147 u_int i1
= ntohl(((u_int
*)hdr
)[1]);
148 u_int dlen
= ntohs(up
->uh_ulen
) - sizeof(*up
) - 8;
156 if ((i0
>> 30) == 1) {
158 hasopt
= i0
& 0x800000;
159 contype
= (i0
>> 16) & 0x3f;
160 hasmarker
= i0
& 0x400000;
164 hasext
= i0
& 0x10000000;
165 contype
= (i0
>> 16) & 0x7f;
166 hasmarker
= i0
& 0x800000;
172 printf(" udp/%s %d c%d %s%s %d %u",
176 (hasopt
|| hasext
)? "+" : "",
186 optlen
= (i2
>> 16) & 0xff;
187 if (optlen
== 0 || optlen
> len
) {
193 } while ((int)i2
>= 0);
198 extlen
= (i2
& 0xffff) + 1;
205 if (contype
== 0x1f) /*XXX H.261 */
206 printf(" 0x%04x", ip
[0] >> 16);
210 static const u_char
*
211 rtcp_print(const u_char
*hdr
, const u_char
*ep
)
213 /* rtp v2 control (rtcp) */
214 struct rtcp_rr
*rr
= 0;
216 struct rtcphdr
*rh
= (struct rtcphdr
*)hdr
;
221 if ((u_char
*)(rh
+ 1) > ep
) {
225 len
= (ntohs(rh
->rh_len
) + 1) * 4;
226 flags
= ntohs(rh
->rh_flags
);
227 cnt
= (flags
>> 8) & 0x1f;
228 switch (flags
& 0xff) {
230 sr
= (struct rtcp_sr
*)(rh
+ 1);
232 if (len
!= cnt
* sizeof(*rr
) + sizeof(*sr
) + sizeof(*rh
))
233 printf(" [%d]", len
);
235 printf(" %u", (u_int32_t
)ntohl(rh
->rh_ssrc
));
236 if ((u_char
*)(sr
+ 1) > ep
) {
240 ts
= (double)((u_int32_t
)ntohl(sr
->sr_ntp
.upper
)) +
241 ((double)((u_int32_t
)ntohl(sr
->sr_ntp
.lower
)) /
243 printf(" @%.2f %u %up %ub", ts
, (u_int32_t
)ntohl(sr
->sr_ts
),
244 (u_int32_t
)ntohl(sr
->sr_np
), (u_int32_t
)ntohl(sr
->sr_nb
));
245 rr
= (struct rtcp_rr
*)(sr
+ 1);
249 if (len
!= cnt
* sizeof(*rr
) + sizeof(*rh
))
250 printf(" [%d]", len
);
251 rr
= (struct rtcp_rr
*)(rh
+ 1);
253 printf(" %u", (u_int32_t
)ntohl(rh
->rh_ssrc
));
256 printf(" sdes %d", len
);
258 printf(" %u", (u_int32_t
)ntohl(rh
->rh_ssrc
));
262 printf(" bye %d", len
);
264 printf(" %u", (u_int32_t
)ntohl(rh
->rh_ssrc
));
268 printf(" type-0x%x %d", flags
& 0xff, len
);
275 if ((u_char
*)(rr
+ 1) > ep
) {
280 printf(" %u", (u_int32_t
)ntohl(rr
->rr_srcid
));
281 ts
= (double)((u_int32_t
)ntohl(rr
->rr_lsr
)) / 65536.;
282 dts
= (double)((u_int32_t
)ntohl(rr
->rr_dlsr
)) / 65536.;
283 printf(" %ul %us %uj @%.2f+%.2f",
284 (u_int32_t
)ntohl(rr
->rr_nl
) & 0x00ffffff,
285 (u_int32_t
)ntohl(rr
->rr_ls
),
286 (u_int32_t
)ntohl(rr
->rr_dv
), ts
, dts
);
291 /* XXX probably should use getservbyname() and cache answers */
292 #define TFTP_PORT 69 /*XXX*/
293 #define KERBEROS_PORT 88 /*XXX*/
294 #define SUNRPC_PORT 111 /*XXX*/
295 #define SNMP_PORT 161 /*XXX*/
296 #define NTP_PORT 123 /*XXX*/
297 #define SNMPTRAP_PORT 162 /*XXX*/
298 #define ISAKMP_PORT 500 /*XXX*/
299 #define RIP_PORT 520 /*XXX*/
300 #define KERBEROS_SEC_PORT 750 /*XXX*/
301 #define L2TP_PORT 1701 /*XXX*/
302 #define ISAKMP_PORT_USER1 7500 /*??? - nonstandard*/
303 #define ISAKMP_PORT_USER2 8500 /*??? - nonstandard*/
304 #define RX_PORT_LOW 7000 /*XXX*/
305 #define RX_PORT_HIGH 7009 /*XXX*/
308 #define RIPNG_PORT 521 /*XXX*/
309 #define DHCP6_SERV_PORT 546 /*XXX*/
310 #define DHCP6_CLI_PORT 547 /*XXX*/
314 udp_print(register const u_char
*bp
, u_int length
, register const u_char
*bp2
)
316 register const struct udphdr
*up
;
317 register const struct ip
*ip
;
318 register const u_char
*cp
;
319 register const u_char
*ep
= bp
+ length
;
320 u_short sport
, dport
, ulen
;
322 register const struct ip6_hdr
*ip6
;
327 up
= (struct udphdr
*)bp
;
328 ip
= (struct ip
*)bp2
;
331 ip6
= (struct ip6_hdr
*)bp2
;
335 cp
= (u_char
*)(up
+ 1);
340 if (length
< sizeof(struct udphdr
)) {
341 (void)printf(" truncated-udp %d", length
);
344 length
-= sizeof(struct udphdr
);
346 sport
= ntohs(up
->uh_sport
);
347 dport
= ntohs(up
->uh_dport
);
348 ulen
= ntohs(up
->uh_ulen
);
350 register struct rpc_msg
*rp
;
351 enum msg_type direction
;
353 switch (packettype
) {
356 (void)printf("%s.%s > %s.%s:",
357 ipaddr_string(&ip
->ip_src
),
358 udpport_string(sport
),
359 ipaddr_string(&ip
->ip_dst
),
360 udpport_string(dport
));
361 vat_print((void *)(up
+ 1), length
, up
);
365 (void)printf("%s.%s > %s.%s:",
366 ipaddr_string(&ip
->ip_src
),
367 udpport_string(sport
),
368 ipaddr_string(&ip
->ip_dst
),
369 udpport_string(dport
));
370 wb_print((void *)(up
+ 1), length
);
374 rp
= (struct rpc_msg
*)(up
+ 1);
375 direction
= (enum msg_type
)ntohl(rp
->rm_direction
);
376 if (direction
== CALL
)
377 sunrpcrequest_print((u_char
*)rp
, length
,
380 nfsreply_print((u_char
*)rp
, length
,
381 (u_char
*)ip
); /*XXX*/
385 (void)printf("%s.%s > %s.%s:",
386 ipaddr_string(&ip
->ip_src
),
387 udpport_string(sport
),
388 ipaddr_string(&ip
->ip_dst
),
389 udpport_string(dport
));
390 rtp_print((void *)(up
+ 1), length
, up
);
394 (void)printf("%s.%s > %s.%s:",
395 ipaddr_string(&ip
->ip_src
),
396 udpport_string(sport
),
397 ipaddr_string(&ip
->ip_dst
),
398 udpport_string(dport
));
400 cp
= rtcp_print(cp
, ep
);
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 snmp_print((const u_char
*)(up
+ 1), length
);
416 register struct rpc_msg
*rp
;
417 enum msg_type direction
;
419 rp
= (struct rpc_msg
*)(up
+ 1);
420 if (TTEST(rp
->rm_direction
)) {
421 direction
= (enum msg_type
)ntohl(rp
->rm_direction
);
422 if (dport
== NFS_PORT
&& direction
== CALL
) {
423 nfsreq_print((u_char
*)rp
, length
,
427 if (sport
== NFS_PORT
&& direction
== REPLY
) {
428 nfsreply_print((u_char
*)rp
, length
,
433 if (dport
== SUNRPC_PORT
&& direction
== CALL
) {
434 sunrpcrequest_print((u_char
*)rp
, length
, (u_char
*)ip
);
439 if (TTEST(((struct LAP
*)cp
)->type
) &&
440 ((struct LAP
*)cp
)->type
== lapDDP
&&
441 (atalk_port(sport
) || atalk_port(dport
))) {
443 fputs("kip ", stdout
);
444 atalk_print(cp
, length
);
449 (void)printf("%s.%s > %s.%s:",
450 ipaddr_string(&ip
->ip_src
), udpport_string(sport
),
451 ipaddr_string(&ip
->ip_dst
), udpport_string(dport
));
455 if (ip6
->ip6_nxt
== IPPROTO_UDP
) {
456 (void)printf("%s.%s > %s.%s: ",
457 ip6addr_string(&ip6
->ip6_src
),
458 udpport_string(sport
),
459 ip6addr_string(&ip6
->ip6_dst
),
460 udpport_string(dport
));
462 (void)printf("%s > %s: ",
463 udpport_string(sport
), udpport_string(dport
));
468 if (ip
->ip_p
== IPPROTO_UDP
) {
469 (void)printf("%s.%s > %s.%s: ",
470 ipaddr_string(&ip
->ip_src
),
471 udpport_string(sport
),
472 ipaddr_string(&ip
->ip_dst
),
473 udpport_string(dport
));
475 (void)printf("%s > %s: ",
476 udpport_string(sport
), udpport_string(dport
));
482 #define ISPORT(p) (dport == (p) || sport == (p))
483 if (ISPORT(NAMESERVER_PORT
))
484 ns_print((const u_char
*)(up
+ 1), length
);
485 else if (ISPORT(TFTP_PORT
))
486 tftp_print((const u_char
*)(up
+ 1), length
);
487 else if (ISPORT(IPPORT_BOOTPC
) || ISPORT(IPPORT_BOOTPS
))
488 bootp_print((const u_char
*)(up
+ 1), length
,
490 else if (ISPORT(RIP_PORT
))
491 rip_print((const u_char
*)(up
+ 1), length
);
492 else if (ISPORT(ISAKMP_PORT
))
493 isakmp_print((const u_char
*)(up
+ 1), length
, bp2
);
495 else if (ISPORT(ISAKMP_PORT_USER1
) || ISPORT(ISAKMP_PORT_USER2
))
496 isakmp_print((const u_char
*)(up
+ 1), length
, bp2
);
498 else if (ISPORT(SNMP_PORT
) || ISPORT(SNMPTRAP_PORT
))
499 snmp_print((const u_char
*)(up
+ 1), length
);
500 else if (ISPORT(NTP_PORT
))
501 ntp_print((const u_char
*)(up
+ 1), length
);
502 else if (ISPORT(KERBEROS_PORT
) || ISPORT(KERBEROS_SEC_PORT
))
503 krb_print((const void *)(up
+ 1), length
);
504 else if (ISPORT(L2TP_PORT
))
505 l2tp_print((const u_char
*)(up
+ 1), length
);
506 else if (dport
== 3456)
507 vat_print((const void *)(up
+ 1), length
, up
);
509 * Since there are 10 possible ports to check, I think
510 * a <> test would be more efficient
512 else if ((sport
>= RX_PORT_LOW
&& sport
<= RX_PORT_HIGH
) ||
513 (dport
>= RX_PORT_LOW
&& dport
<= RX_PORT_HIGH
))
514 rx_print((const void *)(up
+ 1), length
, sport
, dport
,
517 else if (ISPORT(RIPNG_PORT
))
518 ripng_print((const u_char
*)(up
+ 1), length
);
519 else if (ISPORT(DHCP6_SERV_PORT
) || ISPORT(DHCP6_CLI_PORT
)) {
520 dhcp6_print((const u_char
*)(up
+ 1), length
,
525 * Kludge in test for whiteboard packets.
527 else if (dport
== 4567)
528 wb_print((const void *)(up
+ 1), length
);
530 (void)printf(" udp %u",
531 (u_int32_t
)(ulen
- sizeof(*up
)));
534 (void)printf(" udp %u", (u_int32_t
)(ulen
- sizeof(*up
)));