]>
The Tcpdump Group git mirrors - tcpdump/blob - print-igmp.c
2 * Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994, 1995, 1996
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-igmp.c,v 1.8 2002-08-01 08:53:09 risso Exp $ (LBL)";
31 #include <tcpdump-stdinc.h>
36 #include "interface.h"
37 #include "addrtoname.h"
38 #include "extract.h" /* must come after interface.h */
41 #define IN_CLASSD(i) (((int32_t)(i) & 0xf0000000) == 0xe0000000)
44 /* (following from ipmulti/mrouted/prune.h) */
47 * The packet format for a traceroute request.
50 u_int tr_src
; /* traceroute source */
51 u_int tr_dst
; /* traceroute destination */
52 u_int tr_raddr
; /* traceroute response address */
53 u_int tr_rttlqid
; /* response ttl and qid */
56 #define TR_GETTTL(x) (int)(((x) >> 24) & 0xff)
57 #define TR_GETQID(x) ((x) & 0x00ffffff)
60 * Traceroute response format. A traceroute response has a tr_query at the
61 * beginning, followed by one tr_resp for each hop taken.
64 u_int tr_qarr
; /* query arrival time */
65 u_int tr_inaddr
; /* incoming interface address */
66 u_int tr_outaddr
; /* outgoing interface address */
67 u_int tr_rmtaddr
; /* parent address in source tree */
68 u_int tr_vifin
; /* input packet count on interface */
69 u_int tr_vifout
; /* output packet count on interface */
70 u_int tr_pktcnt
; /* total incoming packets for src-grp */
71 u_char tr_rproto
; /* routing proto deployed on router */
72 u_char tr_fttl
; /* ttl required to forward on outvif */
73 u_char tr_smask
; /* subnet mask for src addr */
74 u_char tr_rflags
; /* forwarding error codes */
77 /* defs within mtrace */
81 /* fields for tr_rflags (forwarding error codes) */
89 #define TR_NO_SPACE 0x81
90 #define TR_OLD_ROUTER 0x82
92 /* fields for tr_rproto (routing protocol) */
93 #define TR_PROTO_DVMRP 1
94 #define TR_PROTO_MOSPF 2
95 #define TR_PROTO_PIM 3
96 #define TR_PROTO_CBT 4
98 /* igmpv3 report types */
99 static struct tok igmpv3report2str
[] = {
110 print_mtrace(register const u_char
*bp
, register u_int len
)
112 register const struct tr_query
*tr
= (const struct tr_query
*)(bp
+ 8);
114 printf("mtrace %lu: %s to %s reply-to %s",
115 (u_long
)TR_GETQID(ntohl(tr
->tr_rttlqid
)),
116 ipaddr_string(&tr
->tr_src
), ipaddr_string(&tr
->tr_dst
),
117 ipaddr_string(&tr
->tr_raddr
));
118 if (IN_CLASSD(ntohl(tr
->tr_raddr
)))
119 printf(" with-ttl %d", TR_GETTTL(ntohl(tr
->tr_rttlqid
)));
123 print_mresp(register const u_char
*bp
, register u_int len
)
125 register const struct tr_query
*tr
= (const struct tr_query
*)(bp
+ 8);
127 printf("mresp %lu: %s to %s reply-to %s",
128 (u_long
)TR_GETQID(ntohl(tr
->tr_rttlqid
)),
129 ipaddr_string(&tr
->tr_src
), ipaddr_string(&tr
->tr_dst
),
130 ipaddr_string(&tr
->tr_raddr
));
131 if (IN_CLASSD(ntohl(tr
->tr_raddr
)))
132 printf(" with-ttl %d", TR_GETTTL(ntohl(tr
->tr_rttlqid
)));
136 print_igmpv3_report(register const u_char
*bp
, register u_int len
)
138 u_int group
, nsrcs
, ngroups
;
141 /* Minimum len is 16, and should be a multiple of 4 */
142 if (len
< 16 || len
& 0x03) {
143 (void)printf(" [invalid len %d]", len
);
147 ngroups
= EXTRACT_16BITS(&bp
[6]);
148 (void)printf(", %d group record(s)", ngroups
);
150 /* Print the group records */
152 for (i
=0; i
<ngroups
; i
++) {
154 (void)printf(" [invalid number of groups]");
157 TCHECK2(bp
[group
+4], 4);
158 (void)printf(" [gaddr %s", ipaddr_string(&bp
[group
+4]));
159 (void)printf(" %s", tok2str(igmpv3report2str
, " [v3-report-#%d]",
161 nsrcs
= EXTRACT_16BITS(&bp
[group
+2]);
162 /* Check the number of sources and print them */
163 if (len
< group
+8+(nsrcs
<<2)) {
164 (void)printf(" [invalid number of sources %d]", nsrcs
);
168 (void)printf(", %d source(s)", nsrcs
);
170 /* Print the sources */
172 for (j
=0; j
<nsrcs
; j
++) {
173 TCHECK2(bp
[group
+8+(j
<<2)], 4);
174 (void)printf(" %s", ipaddr_string(&bp
[group
+8+(j
<<2)]));
178 /* Next group record */
179 group
+= 8 + (nsrcs
<< 2);
185 (void)printf("[|igmp]");
190 print_igmpv3_query(register const u_char
*bp
, register u_int len
)
198 /* Minimum len is 12, and should be a multiple of 4 */
199 if (len
< 12 || len
& 0x03) {
200 (void)printf(" [invalid len %d]", len
);
207 mrt
= ((mrc
& 0x0f) | 0x10) << (((mrc
& 0x70) >> 4) + 3);
210 (void)printf(" [max resp time ");
215 if (EXTRACT_32BITS(&bp
[4]) == 0)
217 (void)printf(" [gaddr %s", ipaddr_string(&bp
[4]));
219 nsrcs
= EXTRACT_16BITS(&bp
[10]);
221 if (len
< 12 + (nsrcs
<< 2))
222 (void)printf(" [invalid number of sources]");
223 else if (vflag
> 1) {
225 for (i
=0; i
<nsrcs
; i
++) {
226 TCHECK2(bp
[12+(i
<<2)], 4);
227 (void)printf(" %s", ipaddr_string(&bp
[12+(i
<<2)]));
231 (void)printf(", %d source(s)", nsrcs
);
236 (void)printf("[|igmp]");
241 igmp_print(register const u_char
*bp
, register u_int len
)
244 (void)printf("igmp");
251 (void)printf("igmp query");
253 print_igmpv3_query(bp
, len
);
258 (void)printf(" [max resp time %d]", bp
[1]);
261 if (EXTRACT_32BITS(&bp
[4]))
262 (void)printf(" [gaddr %s]", ipaddr_string(&bp
[4]));
264 (void)printf(" [len %d]", len
);
268 (void)printf("igmp v1 report %s", ipaddr_string(&bp
[4]));
270 (void)printf(" [len %d]", len
);
273 (void)printf("igmp v2 report %s", ipaddr_string(&bp
[4]));
276 (void)printf("igmp v3 report");
277 print_igmpv3_report(bp
, len
);
280 (void)printf("igmp leave %s", ipaddr_string(&bp
[4]));
283 (void)printf("igmp dvmrp");
285 (void)printf(" [len %d]", len
);
287 dvmrp_print(bp
, len
);
290 (void)printf("igmp pimv1");
291 pimv1_print(bp
, len
);
294 print_mresp(bp
, len
);
297 print_mtrace(bp
, len
);
300 (void)printf("igmp-%d", bp
[0]);
304 if (vflag
&& TTEST2(bp
[0], len
)) {
305 /* Check the IGMP checksum */
306 if (in_cksum((const u_short
*)bp
, len
, 0))
307 printf(" bad igmp cksum %x!", EXTRACT_16BITS(&bp
[2]));
311 fputs("[|igmp]", stdout
);