X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/46f2e906622856f962f34fd5e3b08b113fd07fa5..2c3ee827aeb173c78f88ea032cf1405c92281a10:/print-pim.c diff --git a/print-pim.c b/print-pim.c index 5c8d2230..ca886239 100644 --- a/print-pim.c +++ b/print-pim.c @@ -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.23 2000-10-03 02:55:00 itojun Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -33,38 +33,25 @@ static const char rcsid[] = #include #include -#include -#include -/* -#include -#include -#include -#include -*/ /* * 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 -#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 @@ -75,6 +62,8 @@ struct pim { #include "addrtoname.h" #include "extract.h" +#include "ip.h" + static void pimv2_print(register const u_char *bp, register u_int len); static void @@ -327,7 +316,7 @@ cisco_autorp_print(register const u_char *bp, register u_int len) TCHECK2(bp[0], 4); (void)printf(" RP %s", ipaddr_string(bp)); TCHECK(bp[4]); - switch(bp[4] & 0x3) { + switch (bp[4] & 0x3) { case 0: printf(" PIMv?"); break; case 1: printf(" PIMv1"); @@ -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; @@ -643,7 +634,7 @@ pimv2_print(register const u_char *bp, register u_int len) if (bp >= ep) break; ip = (struct ip *)bp; - switch(ip->ip_v) { + switch (IP_V(ip)) { case 4: /* IPv4 */ printf(" "); ip_print(bp, len); @@ -655,7 +646,7 @@ pimv2_print(register const u_char *bp, register u_int len) break; #endif default: - (void)printf(" IP ver %d", ip->ip_v); + (void)printf(" IP ver %d", IP_V(ip)); break; } break; @@ -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"); @@ -808,12 +799,12 @@ pimv2_print(register const u_char *bp, register u_int len) (void)printf("...)"); goto bs_done; } - (void)printf(" RPcnt=%d", frpcnt = bp[0]); + (void)printf(" RPcnt=%d", bp[0]); if (bp + 1 >= ep) { (void)printf("...)"); goto bs_done; } - (void)printf(" FRPcnt=%d", bp[1]); + (void)printf(" FRPcnt=%d", frpcnt = bp[1]); bp += 4; for (j = 0; j < frpcnt && bp < ep; j++) { @@ -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; }