4 * Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994, 1995, 1996
5 * The Regents of the University of California. All rights reserved.
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
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.
24 #include <sys/cdefs.h>
27 static const char rcsid
[] _U_
=
28 "@(#) Header: /tcpdump/master/tcpdump/print-igmp.c,v 1.15 2004/03/24 00:59:16 guy Exp (LBL)";
30 __RCSID("$NetBSD: tcpdump2rcsid.ex,v 1.1 2001/06/25 20:09:58 itojun Exp $");
38 #include <tcpdump-stdinc.h>
43 #include "interface.h"
44 #include "addrtoname.h"
45 #include "extract.h" /* must come after interface.h */
48 #define IN_CLASSD(i) (((int32_t)(i) & 0xf0000000) == 0xe0000000)
51 /* (following from ipmulti/mrouted/prune.h) */
54 * The packet format for a traceroute request.
57 u_int32_t tr_src
; /* traceroute source */
58 u_int32_t tr_dst
; /* traceroute destination */
59 u_int32_t tr_raddr
; /* traceroute response address */
60 u_int32_t tr_rttlqid
; /* response ttl and qid */
63 #define TR_GETTTL(x) (int)(((x) >> 24) & 0xff)
64 #define TR_GETQID(x) ((x) & 0x00ffffff)
67 * Traceroute response format. A traceroute response has a tr_query at the
68 * beginning, followed by one tr_resp for each hop taken.
71 u_int32_t tr_qarr
; /* query arrival time */
72 u_int32_t tr_inaddr
; /* incoming interface address */
73 u_int32_t tr_outaddr
; /* outgoing interface address */
74 u_int32_t tr_rmtaddr
; /* parent address in source tree */
75 u_int32_t tr_vifin
; /* input packet count on interface */
76 u_int32_t tr_vifout
; /* output packet count on interface */
77 u_int32_t tr_pktcnt
; /* total incoming packets for src-grp */
78 u_int8_t tr_rproto
; /* routing proto deployed on router */
79 u_int8_t tr_fttl
; /* ttl required to forward on outvif */
80 u_int8_t tr_smask
; /* subnet mask for src addr */
81 u_int8_t tr_rflags
; /* forwarding error codes */
84 /* defs within mtrace */
88 /* fields for tr_rflags (forwarding error codes) */
96 #define TR_NO_SPACE 0x81
97 #define TR_OLD_ROUTER 0x82
99 /* fields for tr_rproto (routing protocol) */
100 #define TR_PROTO_DVMRP 1
101 #define TR_PROTO_MOSPF 2
102 #define TR_PROTO_PIM 3
103 #define TR_PROTO_CBT 4
105 /* igmpv3 report types */
106 static struct tok igmpv3report2str
[] = {
117 print_mtrace(register const u_char
*bp
, register u_int len
)
119 register const struct tr_query
*tr
= (const struct tr_query
*)(bp
+ 8);
122 if (len
< 8 + sizeof (struct tr_query
)) {
123 (void)printf(" [invalid len %d]", len
);
126 printf("mtrace %u: %s to %s reply-to %s",
127 TR_GETQID(EXTRACT_32BITS(&tr
->tr_rttlqid
)),
128 ipaddr_string(&tr
->tr_src
), ipaddr_string(&tr
->tr_dst
),
129 ipaddr_string(&tr
->tr_raddr
));
130 if (IN_CLASSD(EXTRACT_32BITS(&tr
->tr_raddr
)))
131 printf(" with-ttl %d", TR_GETTTL(EXTRACT_32BITS(&tr
->tr_rttlqid
)));
134 (void)printf("[|igmp]");
139 print_mresp(register const u_char
*bp
, register u_int len
)
141 register const struct tr_query
*tr
= (const struct tr_query
*)(bp
+ 8);
144 if (len
< 8 + sizeof (struct tr_query
)) {
145 (void)printf(" [invalid len %d]", len
);
148 printf("mresp %lu: %s to %s reply-to %s",
149 (u_long
)TR_GETQID(EXTRACT_32BITS(&tr
->tr_rttlqid
)),
150 ipaddr_string(&tr
->tr_src
), ipaddr_string(&tr
->tr_dst
),
151 ipaddr_string(&tr
->tr_raddr
));
152 if (IN_CLASSD(EXTRACT_32BITS(&tr
->tr_raddr
)))
153 printf(" with-ttl %d", TR_GETTTL(EXTRACT_32BITS(&tr
->tr_rttlqid
)));
156 (void)printf("[|igmp]");
161 print_igmpv3_report(register const u_char
*bp
, register u_int len
)
163 u_int group
, nsrcs
, ngroups
;
166 /* Minimum len is 16, and should be a multiple of 4 */
167 if (len
< 16 || len
& 0x03) {
168 (void)printf(" [invalid len %d]", len
);
172 ngroups
= EXTRACT_16BITS(&bp
[6]);
173 (void)printf(", %d group record(s)", ngroups
);
175 /* Print the group records */
177 for (i
=0; i
<ngroups
; i
++) {
179 (void)printf(" [invalid number of groups]");
182 TCHECK2(bp
[group
+4], 4);
183 (void)printf(" [gaddr %s", ipaddr_string(&bp
[group
+4]));
184 (void)printf(" %s", tok2str(igmpv3report2str
, " [v3-report-#%d]",
186 nsrcs
= EXTRACT_16BITS(&bp
[group
+2]);
187 /* Check the number of sources and print them */
188 if (len
< group
+8+(nsrcs
<<2)) {
189 (void)printf(" [invalid number of sources %d]", nsrcs
);
193 (void)printf(", %d source(s)", nsrcs
);
195 /* Print the sources */
197 for (j
=0; j
<nsrcs
; j
++) {
198 TCHECK2(bp
[group
+8+(j
<<2)], 4);
199 (void)printf(" %s", ipaddr_string(&bp
[group
+8+(j
<<2)]));
203 /* Next group record */
204 group
+= 8 + (nsrcs
<< 2);
210 (void)printf("[|igmp]");
215 print_igmpv3_query(register const u_char
*bp
, register u_int len
)
223 /* Minimum len is 12, and should be a multiple of 4 */
224 if (len
< 12 || len
& 0x03) {
225 (void)printf(" [invalid len %d]", len
);
233 mrt
= ((mrc
& 0x0f) | 0x10) << (((mrc
& 0x70) >> 4) + 3);
236 (void)printf(" [max resp time ");
241 if (EXTRACT_32BITS(&bp
[4]) == 0)
243 (void)printf(" [gaddr %s", ipaddr_string(&bp
[4]));
245 nsrcs
= EXTRACT_16BITS(&bp
[10]);
247 if (len
< 12 + (nsrcs
<< 2))
248 (void)printf(" [invalid number of sources]");
249 else if (vflag
> 1) {
251 for (i
=0; i
<nsrcs
; i
++) {
252 TCHECK2(bp
[12+(i
<<2)], 4);
253 (void)printf(" %s", ipaddr_string(&bp
[12+(i
<<2)]));
257 (void)printf(", %d source(s)", nsrcs
);
262 (void)printf("[|igmp]");
267 igmp_print(register const u_char
*bp
, register u_int len
)
270 (void)printf("igmp");
277 (void)printf("igmp query");
279 print_igmpv3_query(bp
, len
);
285 (void)printf(" [max resp time %d]", bp
[1]);
289 if (EXTRACT_32BITS(&bp
[4]))
290 (void)printf(" [gaddr %s]", ipaddr_string(&bp
[4]));
292 (void)printf(" [len %d]", len
);
297 (void)printf("igmp v1 report %s", ipaddr_string(&bp
[4]));
299 (void)printf(" [len %d]", len
);
303 (void)printf("igmp v2 report %s", ipaddr_string(&bp
[4]));
306 (void)printf("igmp v3 report");
307 print_igmpv3_report(bp
, len
);
311 (void)printf("igmp leave %s", ipaddr_string(&bp
[4]));
314 (void)printf("igmp dvmrp");
316 (void)printf(" [len %d]", len
);
318 dvmrp_print(bp
, len
);
321 (void)printf("igmp pimv1");
322 pimv1_print(bp
, len
);
325 print_mresp(bp
, len
);
328 print_mtrace(bp
, len
);
331 (void)printf("igmp-%d", bp
[0]);
335 if (vflag
&& TTEST2(bp
[0], len
)) {
336 /* Check the IGMP checksum */
337 if (in_cksum((const u_short
*)bp
, len
, 0))
338 printf(" bad igmp cksum %x!", EXTRACT_16BITS(&bp
[2]));
342 fputs("[|igmp]", stdout
);