]> The Tcpdump Group git mirrors - tcpdump/commitdiff
fix pim printing. type/version field is 4bit+4bit in 8bit.
authoritojun <itojun>
Wed, 19 Jan 2000 04:57:12 +0000 (04:57 +0000)
committeritojun <itojun>
Wed, 19 Jan 2000 04:57:12 +0000 (04:57 +0000)
- using u_int for this bitfield would make them occupy 32bits.
- use of char as bitfield type is illegal either
so I've avoided use of bitfield (use mask and shift).

print-pim.c

index 5c8d2230f4ede3017aecdcb296a5af1772c68585..ec5d24e540daca312eefafca29e040708dafc137 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.16 2000-01-19 04:57:12 itojun Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -46,25 +46,20 @@ static const char rcsid[] =
  * 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: 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
+                        */
+                       /* lower 4bit: PIM version number; 2 for PIMv2 */
+#define PIM_TYPE(x)    (((x) & 0xf0) >> 4)
+#define PIM_VER(x)     ((x) & 0x0f)
        u_char  pim_rsv;        /* Reserved */
        u_short pim_cksum;      /* IP style check sum */
 };
-#endif 
 
 
 #include <stdio.h>
@@ -369,13 +364,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");
                pimv2_print(bp, len);
                break;
         default:
-               (void)printf("v%d", pim->pim_ver);
+               (void)printf("v%d", PIM_VER(pim->pim_typever));
                break;
        }
        return;
@@ -573,7 +568,7 @@ pimv2_print(register const u_char *bp, register u_int len)
        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 +687,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 +699,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 +714,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 +934,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;
        }