]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-igmp.c
Add SunATM support, based on code from Yen Yen Lim at North Dakota State
[tcpdump] / print-igmp.c
index 59560df5408aa07a7dc333ab746f4c432520e600..1e10d0b74d4dba7d6562e46b442bc73e2ca123e0 100644 (file)
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-igmp.c,v 1.2 2000-11-02 18:02:52 fenner Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-igmp.c,v 1.7 2002-06-11 17:08:49 itojun Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -32,8 +32,6 @@ static const char rcsid[] =
 #include <sys/socket.h>
 
 #include <netinet/in.h>
-#include <netinet/in_systm.h>
-#include <netinet/ip.h>
 
 #include <stdio.h>
 #include <string.h>
@@ -111,10 +109,10 @@ static struct tok igmpv3report2str[] = {
        { 0,    NULL }
 };
 
-static void 
+static void
 print_mtrace(register const u_char *bp, register u_int len)
 {
-    register struct tr_query *tr = (struct tr_query *)(bp + 8);
+    register const struct tr_query *tr = (const struct tr_query *)(bp + 8);
 
     printf("mtrace %lu: %s to %s reply-to %s",
         (u_long)TR_GETQID(ntohl(tr->tr_rttlqid)),
@@ -124,10 +122,10 @@ print_mtrace(register const u_char *bp, register u_int len)
         printf(" with-ttl %d", TR_GETTTL(ntohl(tr->tr_rttlqid)));
 }
 
-static void 
+static void
 print_mresp(register const u_char *bp, register u_int len)
 {
-    register struct tr_query *tr = (struct tr_query *)(bp + 8);
+    register const struct tr_query *tr = (const struct tr_query *)(bp + 8);
 
     printf("mresp %lu: %s to %s reply-to %s",
         (u_long)TR_GETQID(ntohl(tr->tr_rttlqid)),
@@ -137,24 +135,23 @@ print_mresp(register const u_char *bp, register u_int len)
         printf(" with-ttl %d", TR_GETTTL(ntohl(tr->tr_rttlqid)));
 }
 
-static void 
-print_igmpv3_report(register const u_char *bp, register u_int len,
-       register const u_char *bp2)
+static void
+print_igmpv3_report(register const u_char *bp, register u_int len)
 {
-    int group, nsrcs, ngroups;
-    register int i, j;
+    u_int group, nsrcs, ngroups;
+    register u_int i, j;
 
     /* Minimum len is 16, and should be a multiple of 4 */
     if (len < 16 || len & 0x03) {
-       (void)printf(" [invalid len %d]", len);
-       return;
+       (void)printf(" [invalid len %d]", len);
+       return;
     }
     TCHECK2(bp[6], 2);
     ngroups = EXTRACT_16BITS(&bp[6]);
-    (void)printf(", %d group record(s)", ngroups); 
+    (void)printf(", %d group record(s)", ngroups);
     if (vflag > 0) {
        /* Print the group records */
-       group = 8;
+       group = 8;
         for (i=0; i<ngroups; i++) {
            if (len < group+8) {
                (void)printf(" [invalid number of groups]");
@@ -193,17 +190,29 @@ trunc:
 }
 
 static void
-print_igmpv3_query(register const u_char *bp, register u_int len,
-       register const u_char *bp2)
+print_igmpv3_query(register const u_char *bp, register u_int len)
 {
-    int nsrcs;
-    register int i;
+    u_int mrc;
+    int mrt;
+    u_int nsrcs;
+    register u_int i;
 
     (void)printf(" v3");
     /* Minimum len is 12, and should be a multiple of 4 */
     if (len < 12 || len & 0x03) {
-       (void)printf(" [invalid len %d]", len);
-       return;
+       (void)printf(" [invalid len %d]", len);
+       return;
+    }
+    mrc = bp[1];
+    if (mrc < 128) {
+       mrt = mrc;
+    } else {
+        mrt = ((mrc & 0x0f) | 0x10) << (((mrc & 0x70) >> 4) + 3);
+    }
+    if (mrc != 100) {
+       (void)printf(" [max resp time ");
+       relts_print(mrt);
+       (void)printf("]");
     }
     TCHECK2(bp[4], 4);
     if (EXTRACT_32BITS(&bp[4]) == 0)
@@ -232,16 +241,8 @@ trunc:
 }
 
 void
-igmp_print(register const u_char *bp, register u_int len,
-       register const u_char *bp2)
+igmp_print(register const u_char *bp, register u_int len)
 {
-    register const struct ip *ip;
-
-    ip = (const struct ip *)bp2;
-    (void)printf("%s > %s: ",
-        ipaddr_string(&ip->ip_src),
-        ipaddr_string(&ip->ip_dst));
-
     if (qflag) {
         (void)printf("igmp");
         return;
@@ -252,7 +253,7 @@ igmp_print(register const u_char *bp, register u_int len,
     case 0x11:
         (void)printf("igmp query");
        if (len >= 12)
-           print_igmpv3_query(bp, len, bp2);
+           print_igmpv3_query(bp, len);
        else {
            if (bp[1]) {
                (void)printf(" v2");
@@ -260,7 +261,7 @@ igmp_print(register const u_char *bp, register u_int len,
                    (void)printf(" [max resp time %d]", bp[1]);
            } else
                (void)printf(" v1");
-                   if (EXTRACT_32BITS(&bp[4]))
+           if (EXTRACT_32BITS(&bp[4]))
                 (void)printf(" [gaddr %s]", ipaddr_string(&bp[4]));
             if (len != 8)
                 (void)printf(" [len %d]", len);
@@ -276,7 +277,7 @@ igmp_print(register const u_char *bp, register u_int len,
         break;
     case 0x22:
         (void)printf("igmp v3 report");
-       print_igmpv3_report(bp, len, bp2);
+       print_igmpv3_report(bp, len);
         break;
     case 0x17:
         (void)printf("igmp leave %s", ipaddr_string(&bp[4]));