summaryrefslogtreecommitdiffstats
path: root/contrib/tcpdump/print-dvmrp.c
diff options
context:
space:
mode:
authorbms <bms@FreeBSD.org>2004-03-31 09:17:26 +0000
committerbms <bms@FreeBSD.org>2004-03-31 09:17:26 +0000
commit281e9d71408deb6e8c5046c746c2e97002b0e7fe (patch)
treeeb08e08f0f875c3b16f8e1aec86091f100906f1c /contrib/tcpdump/print-dvmrp.c
parentbe6faec6d07fc3a2a54836e76d0309c36192dfad (diff)
downloadFreeBSD-src-281e9d71408deb6e8c5046c746c2e97002b0e7fe.zip
FreeBSD-src-281e9d71408deb6e8c5046c746c2e97002b0e7fe.tar.gz
Import tcpdump 3.8.3, from http://www.tcpdump.org/releases/tcpdump-3.8.3.tar.gz
Diffstat (limited to 'contrib/tcpdump/print-dvmrp.c')
-rw-r--r--contrib/tcpdump/print-dvmrp.c130
1 files changed, 73 insertions, 57 deletions
diff --git a/contrib/tcpdump/print-dvmrp.c b/contrib/tcpdump/print-dvmrp.c
index 273c7d6..5e45d55 100644
--- a/contrib/tcpdump/print-dvmrp.c
+++ b/contrib/tcpdump/print-dvmrp.c
@@ -20,24 +20,19 @@
*/
#ifndef lint
-static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/tcpdump/print-dvmrp.c,v 1.21 2001/05/10 05:30:20 fenner Exp $ (LBL)";
+static const char rcsid[] _U_ =
+ "@(#) $Header: /tcpdump/master/tcpdump/print-dvmrp.c,v 1.24.2.3 2003/11/19 09:41:28 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
-#include <sys/param.h>
-#include <sys/time.h>
-#include <sys/socket.h>
-
-#include <netinet/in.h>
+#include <tcpdump-stdinc.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
-#include <unistd.h>
#include "interface.h"
#include "extract.h"
@@ -67,13 +62,13 @@ static const char rcsid[] =
#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 int print_probe(const u_char *, const u_char *, u_int);
+static int print_report(const u_char *, const u_char *, u_int);
+static int print_neighbors(const u_char *, const u_char *, u_int);
+static int print_neighbors2(const u_char *, const u_char *, u_int);
+static int print_prune(const u_char *);
+static int print_graft(const u_char *);
+static int print_graft_ack(const u_char *);
static u_int32_t target_level;
@@ -87,6 +82,7 @@ dvmrp_print(register const u_char *bp, register u_int len)
if (bp >= ep)
return;
+ TCHECK(bp[1]);
type = bp[1];
/* Skip IGMP header */
@@ -97,14 +93,18 @@ dvmrp_print(register const u_char *bp, register u_int len)
case DVMRP_PROBE:
printf(" Probe");
- if (vflag)
- print_probe(bp, ep, len);
+ if (vflag) {
+ if (print_probe(bp, ep, len) < 0)
+ goto trunc;
+ }
break;
case DVMRP_REPORT:
printf(" Report");
- if (vflag > 1)
- print_report(bp, ep, len);
+ if (vflag > 1) {
+ if (print_report(bp, ep, len) < 0)
+ goto trunc;
+ }
break;
case DVMRP_ASK_NEIGHBORS:
@@ -113,7 +113,8 @@ dvmrp_print(register const u_char *bp, register u_int len)
case DVMRP_NEIGHBORS:
printf(" Neighbors(old)");
- print_neighbors(bp, ep, len);
+ if (print_neighbors(bp, ep, len) < 0)
+ goto trunc;
break;
case DVMRP_ASK_NEIGHBORS2:
@@ -127,45 +128,57 @@ dvmrp_print(register const u_char *bp, register u_int len)
* address field
*/
bp -= 4;
+ TCHECK2(bp[0], 4);
target_level = (bp[0] << 24) | (bp[1] << 16) |
(bp[2] << 8) | bp[3];
bp += 4;
- print_neighbors2(bp, ep, len);
+ if (print_neighbors2(bp, ep, len) < 0)
+ goto trunc;
break;
case DVMRP_PRUNE:
printf(" Prune");
- print_prune(bp, ep, len);
+ if (print_prune(bp) < 0)
+ goto trunc;
break;
case DVMRP_GRAFT:
printf(" Graft");
- print_graft(bp, ep, len);
+ if (print_graft(bp) < 0)
+ goto trunc;
break;
case DVMRP_GRAFT_ACK:
printf(" Graft-ACK");
- print_graft_ack(bp, ep, len);
+ if (print_graft_ack(bp) < 0)
+ goto trunc;
break;
default:
printf(" [type %d]", type);
break;
}
+ return;
+
+trunc:
+ printf("[|dvmrp]");
+ return;
}
-static void
+static int
print_report(register const u_char *bp, register const u_char *ep,
register u_int len)
{
register u_int32_t mask, origin;
- register int metric, i, width, done;
+ register int metric, done;
+ register u_int i, width;
while (len > 0) {
if (len < 3) {
printf(" [|]");
- return;
+ return (0);
}
+ TCHECK2(bp[0], 3);
mask = (u_int32_t)0xff << 24 | bp[0] << 16 | bp[1] << 8 | bp[2];
width = 1;
if (bp[0])
@@ -181,18 +194,21 @@ print_report(register const u_char *bp, register const u_char *ep,
do {
if (bp + width + 1 > ep) {
printf(" [|]");
- return;
+ return (0);
}
if (len < width + 1) {
printf("\n\t [Truncated Report]");
- return;
+ return (0);
}
origin = 0;
- for (i = 0; i < width; ++i)
+ for (i = 0; i < width; ++i) {
+ TCHECK(*bp);
origin = origin << 8 | *bp++;
+ }
for ( ; i < 4; ++i)
origin <<= 8;
+ TCHECK(*bp);
metric = *bp++;
done = metric & 0x80;
metric &= 0x7f;
@@ -201,9 +217,12 @@ print_report(register const u_char *bp, register const u_char *ep,
len -= width + 1;
} while (!done);
}
+ return (0);
+trunc:
+ return (-1);
}
-static void
+static int
print_probe(register const u_char *bp, register const u_char *ep,
register u_int len)
{
@@ -213,7 +232,7 @@ print_probe(register const u_char *bp, register const u_char *ep,
if ((len < 4) || ((bp + 4) > ep)) {
/* { (ctags) */
printf(" [|}");
- return;
+ return (0);
}
genid = (bp[0] << 24) | (bp[1] << 16) | (bp[2] << 8) | bp[3];
bp += 4;
@@ -224,19 +243,19 @@ print_probe(register const u_char *bp, register const u_char *ep,
printf(" ");
printf("genid %u", genid);
if (vflag < 2)
- return;
+ return (0);
while ((len > 0) && (bp < ep)) {
TCHECK2(bp[0], 4);
printf("\n\tneighbor %s", ipaddr_string(bp));
bp += 4; len -= 4;
}
- return;
+ return (0);
trunc:
- (void)printf("[|dvmrp]");
+ return (-1);
}
-static void
+static int
print_neighbors(register const u_char *bp, register const u_char *ep,
register u_int len)
{
@@ -262,12 +281,12 @@ print_neighbors(register const u_char *bp, register const u_char *ep,
len -= 4;
}
}
- return;
+ return (0);
trunc:
- (void)printf("[|dvmrp]");
+ return (-1);
}
-static void
+static int
print_neighbors2(register const u_char *bp, register const u_char *ep,
register u_int len)
{
@@ -308,46 +327,43 @@ print_neighbors2(register const u_char *bp, register const u_char *ep,
}
if (ncount != -1) {
printf(" [|]");
- return;
+ return (0);
}
}
- return;
+ return (0);
trunc:
- (void)printf("[|dvmrp]");
+ return (-1);
}
-static void
-print_prune(register const u_char *bp, register const u_char *ep,
- register u_int len)
+static int
+print_prune(register const u_char *bp)
{
TCHECK2(bp[0], 12);
printf(" src %s grp %s", ipaddr_string(bp), ipaddr_string(bp + 4));
bp += 8;
(void)printf(" timer ");
relts_print(EXTRACT_32BITS(bp));
- return;
+ return (0);
trunc:
- (void)printf("[|dvmrp]");
+ return (-1);
}
-static void
-print_graft(register const u_char *bp, register const u_char *ep,
- register u_int len)
+static int
+print_graft(register const u_char *bp)
{
TCHECK2(bp[0], 8);
printf(" src %s grp %s", ipaddr_string(bp), ipaddr_string(bp + 4));
- return;
+ return (0);
trunc:
- (void)printf("[|dvmrp]");
+ 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(register const u_char *bp)
{
TCHECK2(bp[0], 8);
printf(" src %s grp %s", ipaddr_string(bp), ipaddr_string(bp + 4));
- return;
+ return (0);
trunc:
- (void)printf("[|dvmrp]");
+ return (-1);
}
OpenPOWER on IntegriCloud