]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-pim.c
regenerated
[tcpdump] / print-pim.c
index 5c8d2230f4ede3017aecdcb296a5af1772c68585..ea875b6afec14487d5d1c7f9709d82d68646d387 100644 (file)
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-pim.c,v 1.15 1999-12-14 16:58:03 fenner Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-pim.c,v 1.18 2000-02-16 21:49:23 fenner Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -35,36 +35,25 @@ static const char rcsid[] =
 #include <netinet/in.h>
 #include <netinet/in_systm.h>
 #include <netinet/ip.h>
-/*
-#include <netinet/ip_var.h>
-#include <netinet/udp.h>
-#include <netinet/udp_var.h>
-#include <netinet/tcp.h>
-*/
 
 /*
  * XXX: We consider a case where IPv6 is not ready yet for portability,
  * but PIM dependent defintions should be independent of IPv6...
  */
-#ifdef INET6
-#include <netinet6/pim6.h>
-#else
+
 struct pim {
-#if defined(WORDS_BIGENDIAN) || (defined(BYTE_ORDER) && (BYTE_ORDER == LITTLE_ENDIAN))
-       u_int   pim_type:4, /* the PIM message type, currently they are:
-                           * Hello, Register, Register-Stop, Join/Prune,
-                           * Bootstrap, Assert, Graft (PIM-DM only),
-                           * Graft-Ack (PIM-DM only), C-RP-Adv
-                           */
-               pim_ver:4;  /* PIM version number; 2 for PIMv2 */
-#else
-       u_int   pim_ver:4,      /* PIM version */
-               pim_type:4;     /* PIM type    */
-#endif
+       u_int8_t pim_typever;
+                       /* upper 4bit: PIM version number; 2 for PIMv2 */
+                       /* lower 4bit: the PIM message type, currently they are:
+                        * Hello, Register, Register-Stop, Join/Prune,
+                        * Bootstrap, Assert, Graft (PIM-DM only),
+                        * Graft-Ack (PIM-DM only), C-RP-Adv
+                        */
+#define PIM_VER(x)     (((x) & 0xf0) >> 4)
+#define PIM_TYPE(x)    ((x) & 0x0f)
        u_char  pim_rsv;        /* Reserved */
        u_short pim_cksum;      /* IP style check sum */
 };
-#endif 
 
 
 #include <stdio.h>
@@ -369,13 +358,13 @@ pim_print(register const u_char *bp, register u_int len)
        TCHECK(pim->pim_rsv);
 #endif
 
-       switch(pim->pim_ver) {
+       switch(PIM_VER(pim->pim_typever)) {
         case 2:                /* avoid hardcoding? */
-               (void)printf("v2");
+               (void)printf("pim v2");
                pimv2_print(bp, len);
                break;
         default:
-               (void)printf("v%d", pim->pim_ver);
+               (void)printf("pim v%d", PIM_VER(pim->pim_typever));
                break;
        }
        return;
@@ -568,12 +557,14 @@ pimv2_print(register const u_char *bp, register u_int len)
        ep = (const u_char *)snapend;
        if (bp >= ep)
                return;
+       if (ep > bp + len)
+               ep = bp + len;
        TCHECK(pim->pim_rsv);
        pimv2_addr_len = pim->pim_rsv;
        if (pimv2_addr_len != 0)
                (void)printf("[RFC2117-encoding] ");
 
-       switch (pim->pim_type) {
+       switch (PIM_TYPE(pim->pim_typever)) {
         case 0:
            {
                u_int16_t otype, olen;
@@ -692,7 +683,7 @@ pimv2_print(register const u_char *bp, register u_int len)
                u_int16_t nprune;
                int i, j;
 
-               switch (pim->pim_type) {
+               switch (PIM_TYPE(pim->pim_typever)) {
                 case 3:
                        (void)printf(" Join/Prune");
                        break;
@@ -704,7 +695,7 @@ pimv2_print(register const u_char *bp, register u_int len)
                        break;
                }
                bp += 4; len -= 4;
-               if (pim->pim_type != 7) {       /*not for Graft-ACK*/
+               if (PIM_TYPE(pim->pim_typever) != 7) {  /*not for Graft-ACK*/
                        if (bp >= ep)
                                break;
                        (void)printf(" upstream-neighbor=");
@@ -719,7 +710,7 @@ pimv2_print(register const u_char *bp, register u_int len)
                ngroup = bp[1];
                holdtime = EXTRACT_16BITS(&bp[2]);
                (void)printf(" groups=%u", ngroup);
-               if (pim->pim_type != 7) {       /*not for Graft-ACK*/
+               if (PIM_TYPE(pim->pim_typever) != 7) {  /*not for Graft-ACK*/
                        (void)printf(" holdtime=");
                        if (holdtime == 0xffff)
                                (void)printf("infty");
@@ -939,7 +930,7 @@ pimv2_print(register const u_char *bp, register u_int len)
 
 
         default:
-               (void)printf(" [type %d]", pim->pim_type);
+               (void)printf(" [type %d]", PIM_TYPE(pim->pim_typever));
                break;
        }