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.5.4.1 2002/06/02 18:25:05 guy Exp $ (LBL)";
31 #include <sys/param.h>
32 #include <sys/socket.h>
34 #include <netinet/in.h>
39 #include "interface.h"
40 #include "addrtoname.h"
41 #include "extract.h" /* must come after interface.h */
44 #define IN_CLASSD(i) (((int32_t)(i) & 0xf0000000) == 0xe0000000)
47 /* (following from ipmulti/mrouted/prune.h) */
50 * The packet format for a traceroute request.
53 u_int tr_src; /* traceroute source */
54 u_int tr_dst; /* traceroute destination */
55 u_int tr_raddr; /* traceroute response address */
56 u_int tr_rttlqid; /* response ttl and qid */
59 #define TR_GETTTL(x) (int)(((x) >> 24) & 0xff)
60 #define TR_GETQID(x) ((x) & 0x00ffffff)
63 * Traceroute response format. A traceroute response has a tr_query at the
64 * beginning, followed by one tr_resp for each hop taken.
67 u_int tr_qarr; /* query arrival time */
68 u_int tr_inaddr; /* incoming interface address */
69 u_int tr_outaddr; /* outgoing interface address */
70 u_int tr_rmtaddr; /* parent address in source tree */
71 u_int tr_vifin; /* input packet count on interface */
72 u_int tr_vifout; /* output packet count on interface */
73 u_int tr_pktcnt; /* total incoming packets for src-grp */
74 u_char tr_rproto; /* routing proto deployed on router */
75 u_char tr_fttl; /* ttl required to forward on outvif */
76 u_char tr_smask; /* subnet mask for src addr */
77 u_char tr_rflags; /* forwarding error codes */
80 /* defs within mtrace */
84 /* fields for tr_rflags (forwarding error codes) */
92 #define TR_NO_SPACE 0x81
93 #define TR_OLD_ROUTER 0x82
95 /* fields for tr_rproto (routing protocol) */
96 #define TR_PROTO_DVMRP 1
97 #define TR_PROTO_MOSPF 2
98 #define TR_PROTO_PIM 3
99 #define TR_PROTO_CBT 4
101 /* igmpv3 report types */
102 static struct tok igmpv3report2str[] = {
113 print_mtrace(register const u_char *bp, register u_int len)
115 register const struct tr_query *tr = (const struct tr_query *)(bp + 8);
117 printf("mtrace %lu: %s to %s reply-to %s",
118 (u_long)TR_GETQID(ntohl(tr->tr_rttlqid)),
119 ipaddr_string(&tr->tr_src), ipaddr_string(&tr->tr_dst),
120 ipaddr_string(&tr->tr_raddr));
121 if (IN_CLASSD(ntohl(tr->tr_raddr)))
122 printf(" with-ttl %d", TR_GETTTL(ntohl(tr->tr_rttlqid)));
126 print_mresp(register const u_char *bp, register u_int len)
128 register const struct tr_query *tr = (const struct tr_query *)(bp + 8);
130 printf("mresp %lu: %s to %s reply-to %s",
131 (u_long)TR_GETQID(ntohl(tr->tr_rttlqid)),
132 ipaddr_string(&tr->tr_src), ipaddr_string(&tr->tr_dst),
133 ipaddr_string(&tr->tr_raddr));
134 if (IN_CLASSD(ntohl(tr->tr_raddr)))
135 printf(" with-ttl %d", TR_GETTTL(ntohl(tr->tr_rttlqid)));
139 print_igmpv3_report(register const u_char *bp, register u_int len)
141 u_int group, nsrcs, ngroups;
144 /* Minimum len is 16, and should be a multiple of 4 */
145 if (len < 16 || len & 0x03) {
146 (void)printf(" [invalid len %d]", len);
150 ngroups = EXTRACT_16BITS(&bp[6]);
151 (void)printf(", %d group record(s)", ngroups);
153 /* Print the group records */
155 for (i=0; i<ngroups; i++) {
157 (void)printf(" [invalid number of groups]");
160 TCHECK2(bp[group+4], 4);
161 (void)printf(" [gaddr %s", ipaddr_string(&bp[group+4]));
162 (void)printf(" %s", tok2str(igmpv3report2str, " [v3-report-#%d]",
164 nsrcs = EXTRACT_16BITS(&bp[group+2]);
165 /* Check the number of sources and print them */
166 if (len < group+8+(nsrcs<<2)) {
167 (void)printf(" [invalid number of sources %d]", nsrcs);
171 (void)printf(", %d source(s)", nsrcs);
173 /* Print the sources */
175 for (j=0; j<nsrcs; j++) {
176 TCHECK2(bp[group+8+(j<<2)], 4);
177 (void)printf(" %s", ipaddr_string(&bp[group+8+(j<<2)]));
181 /* Next group record */
182 group += 8 + (nsrcs << 2);
188 (void)printf("[|igmp]");
193 print_igmpv3_query(register const u_char *bp, register u_int len)
201 /* Minimum len is 12, and should be a multiple of 4 */
202 if (len < 12 || len & 0x03) {
203 (void)printf(" [invalid len %d]", len);
210 mrt = ((mrc & 0x0f) | 0x10) << (((mrc & 0x70) >> 4) + 3);
213 (void)printf(" [max resp time ");
218 if (EXTRACT_32BITS(&bp[4]) == 0)
220 (void)printf(" [gaddr %s", ipaddr_string(&bp[4]));
222 nsrcs = EXTRACT_16BITS(&bp[10]);
224 if (len < 12 + (nsrcs << 2))
225 (void)printf(" [invalid number of sources]");
226 else if (vflag > 1) {
228 for (i=0; i<nsrcs; i++) {
229 TCHECK2(bp[12+(i<<2)], 4);
230 (void)printf(" %s", ipaddr_string(&bp[12+(i<<2)]));
234 (void)printf(", %d source(s)", nsrcs);
239 (void)printf("[|igmp]");
244 igmp_print(register const u_char *bp, register u_int len)
247 (void)printf("igmp");
254 (void)printf("igmp query");
256 print_igmpv3_query(bp, len);
261 (void)printf(" [max resp time %d]", bp[1]);
264 if (EXTRACT_32BITS(&bp[4]))
265 (void)printf(" [gaddr %s]", ipaddr_string(&bp[4]));
267 (void)printf(" [len %d]", len);
271 (void)printf("igmp v1 report %s", ipaddr_string(&bp[4]));
273 (void)printf(" [len %d]", len);
276 (void)printf("igmp v2 report %s", ipaddr_string(&bp[4]));
279 (void)printf("igmp v3 report");
280 print_igmpv3_report(bp, len);
283 (void)printf("igmp leave %s", ipaddr_string(&bp[4]));
286 (void)printf("igmp dvmrp");
288 (void)printf(" [len %d]", len);
290 dvmrp_print(bp, len);
293 (void)printf("igmp pimv1");
294 pimv1_print(bp, len);
297 print_mresp(bp, len);
300 print_mtrace(bp, len);
303 (void)printf("igmp-%d", bp[0]);
307 if (vflag && TTEST2(bp[0], len)) {
308 /* Check the IGMP checksum */
309 if (in_cksum((const u_short*)bp, len, 0))
310 printf(" bad igmp cksum %x!", EXTRACT_16BITS(&bp[2]));
314 fputs("[|igmp]", stdout);