* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
-#ifndef lint
-static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/tcpdump/print-dvmrp.c,v 1.15 1999-10-30 05:11:12 itojun Exp $ (LBL)";
-#endif
-
-#include <sys/param.h>
-#include <sys/time.h>
-#include <sys/socket.h>
+/* \summary: Distance Vector Multicast Routing Protocol printer */
-#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>
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
+#include "netdissect-stdinc.h"
-#include "interface.h"
+#include "netdissect.h"
+#include "extract.h"
#include "addrtoname.h"
/*
+ * See: RFC 1075 and draft-ietf-idmr-dvmrp-v3
+ *
* DVMRP message types and flag values shamelessly stolen from
* mrouted/dvmrp.h.
*/
#define DVMRP_PROBE 1 /* for finding neighbors */
#define DVMRP_REPORT 2 /* for reporting some or all routes */
#define DVMRP_ASK_NEIGHBORS 3 /* sent by mapper, asking for a list */
- /*
- * of this router's neighbors
- */
+ /* of this router's neighbors */
#define DVMRP_NEIGHBORS 4 /* response to such a request */
#define DVMRP_ASK_NEIGHBORS2 5 /* as above, want new format reply */
#define DVMRP_NEIGHBORS2 6
#define DVMRP_NF_DISABLED 0x20 /* administratively disabled */
#define DVMRP_NF_QUERIER 0x40 /* I am the subnet's querier */
-static void print_probe(const u_char *, const u_char *, u_int);
-static void print_report(const u_char *, const u_char *, u_int);
-static void print_neighbors(const u_char *, const u_char *, u_int);
-static void print_neighbors2(const u_char *, const u_char *, u_int);
-static void print_prune(const u_char *, const u_char *, u_int);
-static void print_graft(const u_char *, const u_char *, u_int);
-static void print_graft_ack(const u_char *, const u_char *, u_int);
-
-static u_int32_t target_level;
+static int print_probe(netdissect_options *, const u_char *, const u_char *, u_int);
+static int print_report(netdissect_options *, const u_char *, const u_char *, u_int);
+static int print_neighbors(netdissect_options *, const u_char *, const u_char *, u_int);
+static int print_neighbors2(netdissect_options *, const u_char *, const u_char *, u_int, uint8_t, uint8_t);
+static int print_prune(netdissect_options *, const u_char *);
+static int print_graft(netdissect_options *, const u_char *);
+static int print_graft_ack(netdissect_options *, const u_char *);
void
-dvmrp_print(register const u_char *bp, register u_int len)
+dvmrp_print(netdissect_options *ndo,
+ const u_char *bp, u_int len)
{
- register const u_char *ep;
- register u_char type;
+ const u_char *ep;
+ u_char type;
+ uint8_t major_version, minor_version;
- ep = (const u_char *)snapend;
+ ndo->ndo_protocol = "dvmrp";
+ ep = ndo->ndo_snapend;
if (bp >= ep)
return;
- type = bp[1];
- bp += 8;
- /*
- * Skip IGMP header
- */
+ ND_TCHECK_1(bp + 1);
+ type = GET_U_1(bp + 1);
+ /* Skip IGMP header */
+ bp += 8;
len -= 8;
switch (type) {
case DVMRP_PROBE:
- printf(" Probe");
- if (vflag)
- print_probe(bp, ep, len);
+ ND_PRINT(" Probe");
+ if (ndo->ndo_vflag) {
+ if (print_probe(ndo, bp, ep, len) < 0)
+ goto trunc;
+ }
break;
case DVMRP_REPORT:
- printf(" Report");
- if (vflag)
- print_report(bp, ep, len);
+ ND_PRINT(" Report");
+ if (ndo->ndo_vflag > 1) {
+ if (print_report(ndo, bp, ep, len) < 0)
+ goto trunc;
+ }
break;
case DVMRP_ASK_NEIGHBORS:
- printf(" Ask-neighbors(old)");
+ ND_PRINT(" Ask-neighbors(old)");
break;
case DVMRP_NEIGHBORS:
- printf(" Neighbors(old)");
- print_neighbors(bp, ep, len);
+ ND_PRINT(" Neighbors(old)");
+ if (print_neighbors(ndo, bp, ep, len) < 0)
+ goto trunc;
break;
case DVMRP_ASK_NEIGHBORS2:
- printf(" Ask-neighbors2");
+ ND_PRINT(" Ask-neighbors2");
break;
case DVMRP_NEIGHBORS2:
- printf(" Neighbors2");
+ ND_PRINT(" Neighbors2");
/*
- * extract version and capabilities from IGMP group
- * address field
+ * extract version from IGMP group address field
*/
bp -= 4;
- target_level = (bp[0] << 24) | (bp[1] << 16) |
- (bp[2] << 8) | bp[3];
+ ND_TCHECK_4(bp);
+ major_version = GET_U_1(bp + 3);
+ minor_version = GET_U_1(bp + 2);
bp += 4;
- print_neighbors2(bp, ep, len);
+ if (print_neighbors2(ndo, bp, ep, len, major_version,
+ minor_version) < 0)
+ goto trunc;
break;
case DVMRP_PRUNE:
- printf(" Prune");
- print_prune(bp, ep, len);
+ ND_PRINT(" Prune");
+ if (print_prune(ndo, bp) < 0)
+ goto trunc;
break;
case DVMRP_GRAFT:
- printf(" Graft");
- print_graft(bp, ep, len);
+ ND_PRINT(" Graft");
+ if (print_graft(ndo, bp) < 0)
+ goto trunc;
break;
case DVMRP_GRAFT_ACK:
- printf(" Graft-ACK");
- print_graft_ack(bp, ep, len);
+ ND_PRINT(" Graft-ACK");
+ if (print_graft_ack(ndo, bp) < 0)
+ goto trunc;
break;
default:
- printf(" [type %d]", type);
+ ND_PRINT(" [type %u]", type);
break;
}
+ return;
+
+trunc:
+ nd_print_trunc(ndo);
+ return;
}
-static void
-print_report(register const u_char *bp, register const u_char *ep,
- register u_int len)
+static int
+print_report(netdissect_options *ndo,
+ const u_char *bp, const u_char *ep,
+ u_int len)
{
- register u_int32_t mask, origin;
- register int metric, i, width, done;
+ uint32_t mask, origin;
+ u_int metric, done;
+ u_int i, width;
while (len > 0) {
if (len < 3) {
- printf(" [|]");
- return;
+ ND_PRINT(" [|]");
+ return (0);
}
- mask = (u_int32_t)0xff << 24 | bp[0] << 16 | bp[1] << 8 | bp[2];
+ ND_TCHECK_3(bp);
+ mask = (uint32_t)0xff << 24 | GET_U_1(bp) << 16 |
+ GET_U_1(bp + 1) << 8 | GET_U_1(bp + 2);
width = 1;
- if (bp[0])
+ if (GET_U_1(bp))
width = 2;
- if (bp[1])
+ if (GET_U_1(bp + 1))
width = 3;
- if (bp[2])
+ if (GET_U_1(bp + 2))
width = 4;
- printf("\n\tMask %s", intoa(htonl(mask)));
+ ND_PRINT("\n\tMask %s", intoa(htonl(mask)));
bp += 3;
len -= 3;
do {
if (bp + width + 1 > ep) {
- printf(" [|]");
- return;
+ ND_PRINT(" [|]");
+ return (0);
}
if (len < width + 1) {
- printf("\n\t [Truncated Report]");
- return;
+ ND_PRINT("\n\t [Truncated Report]");
+ return (0);
}
origin = 0;
- for (i = 0; i < width; ++i)
- origin = origin << 8 | *bp++;
+ for (i = 0; i < width; ++i) {
+ ND_TCHECK_1(bp);
+ origin = origin << 8 | GET_U_1(bp);
+ bp++;
+ }
for ( ; i < 4; ++i)
origin <<= 8;
- metric = *bp++;
+ ND_TCHECK_1(bp);
+ metric = GET_U_1(bp);
+ bp++;
done = metric & 0x80;
metric &= 0x7f;
- printf("\n\t %s metric %d", intoa(htonl(origin)),
+ ND_PRINT("\n\t %s metric %u", intoa(htonl(origin)),
metric);
len -= width + 1;
} while (!done);
}
+ return (0);
+trunc:
+ return (-1);
}
-#define GET_ADDR(to) (memcpy((char *)to, (char *)bp, 4), bp += 4)
-
-static void
-print_probe(register const u_char *bp, register const u_char *ep,
- register u_int len)
+static int
+print_probe(netdissect_options *ndo,
+ const u_char *bp, const u_char *ep,
+ u_int len)
{
- register u_int32_t genid;
- u_char neighbor[4];
+ uint32_t genid;
+ ND_TCHECK_4(bp);
if ((len < 4) || ((bp + 4) > ep)) {
/* { (ctags) */
- printf(" [|}");
- return;
+ ND_PRINT(" [|}");
+ return (0);
}
- genid = (bp[0] << 24) | (bp[1] << 16) | (bp[2] << 8) | bp[3];
+ genid = GET_BE_U_4(bp);
bp += 4;
len -= 4;
- printf("\n\tgenid %u", genid);
+ ND_PRINT(ndo->ndo_vflag > 1 ? "\n\t" : " ");
+ ND_PRINT("genid %u", genid);
+ if (ndo->ndo_vflag < 2)
+ return (0);
while ((len > 0) && (bp < ep)) {
- if ((len < 4) || ((bp + 4) > ep)) {
- printf(" [|]");
- return;
- }
- GET_ADDR(neighbor);
- len -= 4;
- printf("\n\tneighbor %s", ipaddr_string(neighbor));
+ ND_TCHECK_4(bp);
+ ND_PRINT("\n\tneighbor %s", ipaddr_string(ndo, bp));
+ bp += 4; len -= 4;
}
+ return (0);
+trunc:
+ return (-1);
}
-static void
-print_neighbors(register const u_char *bp, register const u_char *ep,
- register u_int len)
+static int
+print_neighbors(netdissect_options *ndo,
+ const u_char *bp, const u_char *ep,
+ u_int len)
{
- u_char laddr[4], neighbor[4];
- register u_char metric;
- register u_char thresh;
- register int ncount;
+ const u_char *laddr;
+ u_char metric;
+ u_char thresh;
+ int ncount;
while (len > 0 && bp < ep) {
- if (len < 7 || (bp + 7) >= ep) {
- printf(" [|]");
- return;
- }
- GET_ADDR(laddr);
- metric = *bp++;
- thresh = *bp++;
- ncount = *bp++;
+ ND_TCHECK_7(bp);
+ laddr = bp;
+ bp += 4;
+ metric = GET_U_1(bp);
+ bp++;
+ thresh = GET_U_1(bp);
+ bp++;
+ ncount = GET_U_1(bp);
+ bp++;
len -= 7;
- while (--ncount >= 0 && (len >= 4) && (bp + 4) < ep) {
- GET_ADDR(neighbor);
- printf(" [%s ->", ipaddr_string(laddr));
- printf(" %s, (%d/%d)]",
- ipaddr_string(neighbor), metric, thresh);
+ while (--ncount >= 0) {
+ ND_TCHECK_4(bp);
+ ND_PRINT(" [%s ->", ipaddr_string(ndo, laddr));
+ ND_PRINT(" %s, (%u/%u)]",
+ ipaddr_string(ndo, bp), metric, thresh);
+ bp += 4;
len -= 4;
}
}
+ return (0);
+trunc:
+ return (-1);
}
-static void
-print_neighbors2(register const u_char *bp, register const u_char *ep,
- register u_int len)
+static int
+print_neighbors2(netdissect_options *ndo,
+ const u_char *bp, const u_char *ep,
+ u_int len, uint8_t major_version,
+ uint8_t minor_version)
{
- u_char laddr[4], neighbor[4];
- register u_char metric, thresh, flags;
- register int ncount;
+ const u_char *laddr;
+ u_char metric, thresh, flags;
+ int ncount;
- printf(" (v %d.%d):",
- (int)target_level & 0xff,
- (int)(target_level >> 8) & 0xff);
+ ND_PRINT(" (v %u.%u):", major_version, minor_version);
while (len > 0 && bp < ep) {
- if (len < 8 || (bp + 8) >= ep) {
- printf(" [|]");
- return;
- }
- GET_ADDR(laddr);
- metric = *bp++;
- thresh = *bp++;
- flags = *bp++;
- ncount = *bp++;
+ ND_TCHECK_8(bp);
+ laddr = bp;
+ bp += 4;
+ metric = GET_U_1(bp);
+ bp++;
+ thresh = GET_U_1(bp);
+ bp++;
+ flags = GET_U_1(bp);
+ bp++;
+ ncount = GET_U_1(bp);
+ bp++;
len -= 8;
while (--ncount >= 0 && (len >= 4) && (bp + 4) <= ep) {
- GET_ADDR(neighbor);
- printf(" [%s -> ", ipaddr_string(laddr));
- printf("%s (%d/%d", ipaddr_string(neighbor),
+ ND_PRINT(" [%s -> ", ipaddr_string(ndo, laddr));
+ ND_PRINT("%s (%u/%u", ipaddr_string(ndo, bp),
metric, thresh);
if (flags & DVMRP_NF_TUNNEL)
- printf("/tunnel");
+ ND_PRINT("/tunnel");
if (flags & DVMRP_NF_SRCRT)
- printf("/srcrt");
+ ND_PRINT("/srcrt");
if (flags & DVMRP_NF_QUERIER)
- printf("/querier");
+ ND_PRINT("/querier");
if (flags & DVMRP_NF_DISABLED)
- printf("/disabled");
+ ND_PRINT("/disabled");
if (flags & DVMRP_NF_DOWN)
- printf("/down");
- printf(")]");
+ ND_PRINT("/down");
+ ND_PRINT(")]");
+ bp += 4;
len -= 4;
}
if (ncount != -1) {
- printf(" [|]");
- return;
+ ND_PRINT(" [|]");
+ return (0);
}
}
+ return (0);
+trunc:
+ return (-1);
}
-static void
-print_prune(register const u_char *bp, register const u_char *ep,
- register u_int len)
+static int
+print_prune(netdissect_options *ndo,
+ const u_char *bp)
{
- union a {
- u_char b[4];
- u_int32_t i;
- } prune_timer;
-
- if (len < 12 || (bp + 12) > ep) {
- printf(" [|]");
- return;
- }
- printf(" src %s grp %s", ipaddr_string(bp), ipaddr_string(bp + 4));
+ ND_TCHECK_LEN(bp, 12);
+ ND_PRINT(" src %s grp %s", ipaddr_string(ndo, bp), ipaddr_string(ndo, bp + 4));
bp += 8;
- GET_ADDR(prune_timer.b);
- printf(" timer %d", (int)ntohl(prune_timer.i));
+ ND_PRINT(" timer ");
+ unsigned_relts_print(ndo, GET_BE_U_4(bp));
+ return (0);
+trunc:
+ return (-1);
}
-static void
-print_graft(register const u_char *bp, register const u_char *ep,
- register u_int len)
+static int
+print_graft(netdissect_options *ndo,
+ const u_char *bp)
{
-
- if (len < 8 || (bp + 8) > ep) {
- printf(" [|]");
- return;
- }
- printf(" src %s grp %s", ipaddr_string(bp), ipaddr_string(bp + 4));
+ ND_TCHECK_8(bp);
+ ND_PRINT(" src %s grp %s", ipaddr_string(ndo, bp), ipaddr_string(ndo, bp + 4));
+ return (0);
+trunc:
+ return (-1);
}
-static void
-print_graft_ack(register const u_char *bp, register const u_char *ep,
- register u_int len)
+static int
+print_graft_ack(netdissect_options *ndo,
+ const u_char *bp)
{
-
- if (len < 8 || (bp + 8) > ep) {
- printf(" [|]");
- return;
- }
- printf(" src %s grp %s", ipaddr_string(bp), ipaddr_string(bp + 4));
+ ND_TCHECK_8(bp);
+ ND_PRINT(" src %s grp %s", ipaddr_string(ndo, bp), ipaddr_string(ndo, bp + 4));
+ return (0);
+trunc:
+ return (-1);
}