#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
#include <sys/socket.h>
#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>
#include "addrtoname.h"
#include "extract.h"
+#include "ip.h"
+
static void pimv2_print(register const u_char *bp, register u_int len);
static void
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");
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;
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;
if (bp >= ep)
break;
ip = (struct ip *)bp;
- switch(ip->ip_v) {
+ switch (IP_V(ip)) {
case 4: /* IPv4 */
printf(" ");
ip_print(bp, len);
break;
#endif
default:
- (void)printf(" IP ver %d", ip->ip_v);
+ (void)printf(" IP ver %d", IP_V(ip));
break;
}
break;
u_int16_t nprune;
int i, j;
- switch (pim->pim_type) {
+ switch (PIM_TYPE(pim->pim_typever)) {
case 3:
(void)printf(" Join/Prune");
break;
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=");
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");
(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++) {
default:
- (void)printf(" [type %d]", pim->pim_type);
+ (void)printf(" [type %d]", PIM_TYPE(pim->pim_typever));
break;
}