summaryrefslogtreecommitdiff
path: root/usr.sbin/tcpdump/print-bootp.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/tcpdump/print-bootp.c')
-rw-r--r--usr.sbin/tcpdump/print-bootp.c76
1 files changed, 30 insertions, 46 deletions
diff --git a/usr.sbin/tcpdump/print-bootp.c b/usr.sbin/tcpdump/print-bootp.c
index 3deff920d10..f983089d7be 100644
--- a/usr.sbin/tcpdump/print-bootp.c
+++ b/usr.sbin/tcpdump/print-bootp.c
@@ -1,5 +1,3 @@
-/* $OpenBSD: print-bootp.c,v 1.4 1996/07/13 11:01:16 mickey Exp $ */
-
/*
* Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996
* The Regents of the University of California. All rights reserved.
@@ -23,13 +21,12 @@
* Format and print bootp packets.
*/
#ifndef lint
-static char rcsid[] =
- "@(#) Header: print-bootp.c,v 1.38 96/06/23 02:11:45 leres Exp (LBL)";
+static const char rcsid[] =
+ "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-bootp.c,v 1.5 1996/12/12 16:22:41 bitblt Exp $ (LBL)";
#endif
#include <sys/param.h>
#include <sys/time.h>
-#include <sys/types.h>
#include <sys/socket.h>
#if __STDC__
@@ -49,8 +46,8 @@ struct rtentry;
#include "addrtoname.h"
#include "bootp.h"
-static void rfc1048_print(const u_char *, int);
-static void cmu_print(const u_char *, int);
+static void rfc1048_print(const u_char *, u_int);
+static void cmu_print(const u_char *, u_int);
static char tstr[] = " [|bootp]";
@@ -58,21 +55,15 @@ static char tstr[] = " [|bootp]";
* Print bootp requests
*/
void
-bootp_print(register const u_char *cp, int length,
+bootp_print(register const u_char *cp, u_int length,
u_short sport, u_short dport)
{
register const struct bootp *bp;
static u_char vm_cmu[4] = VM_CMU;
static u_char vm_rfc1048[4] = VM_RFC1048;
- const u_char *ep;
-
-#define TCHECK(var, l) if ((u_char *)&(var) > ep - l) goto trunc
bp = (struct bootp *)cp;
- /* 'ep' points to the end of available data. */
- ep = snapend;
-
- TCHECK(bp->bp_op, sizeof(bp->bp_op));
+ TCHECK(bp->bp_op);
switch (bp->bp_op) {
case BOOTREQUEST:
@@ -91,7 +82,7 @@ bootp_print(register const u_char *cp, int length,
printf(" bootp-#%d", bp->bp_op);
}
- TCHECK(bp->bp_secs, sizeof(bp->bp_secs));
+ TCHECK(bp->bp_secs);
/* The usual hardware address type is 1 (10Mb Ethernet) */
if (bp->bp_htype != 1)
@@ -110,22 +101,22 @@ bootp_print(register const u_char *cp, int length,
printf(" secs:%d", ntohs(bp->bp_secs));
/* Client's ip address */
- TCHECK(bp->bp_ciaddr, sizeof(bp->bp_ciaddr));
+ TCHECK(bp->bp_ciaddr);
if (bp->bp_ciaddr.s_addr)
printf(" C:%s", ipaddr_string(&bp->bp_ciaddr));
/* 'your' ip address (bootp client) */
- TCHECK(bp->bp_yiaddr, sizeof(bp->bp_yiaddr));
+ TCHECK(bp->bp_yiaddr);
if (bp->bp_yiaddr.s_addr)
printf(" Y:%s", ipaddr_string(&bp->bp_yiaddr));
/* Server's ip address */
- TCHECK(bp->bp_siaddr, sizeof(bp->bp_siaddr));
+ TCHECK(bp->bp_siaddr);
if (bp->bp_siaddr.s_addr)
printf(" S:%s", ipaddr_string(&bp->bp_siaddr));
/* Gateway's ip address */
- TCHECK(bp->bp_giaddr, sizeof(bp->bp_giaddr));
+ TCHECK(bp->bp_giaddr);
if (bp->bp_giaddr.s_addr)
printf(" G:%s", ipaddr_string(&bp->bp_giaddr));
@@ -134,7 +125,7 @@ bootp_print(register const u_char *cp, int length,
register const struct ether_header *eh;
register const char *e;
- TCHECK(bp->bp_chaddr[0], 6);
+ TCHECK2(bp->bp_chaddr[0], 6);
eh = (struct ether_header *)packetp;
if (bp->bp_op == BOOTREQUEST)
e = (const char *)ESRC(eh);
@@ -146,25 +137,27 @@ bootp_print(register const u_char *cp, int length,
printf(" ether %s", etheraddr_string(bp->bp_chaddr));
}
- TCHECK(bp->bp_sname[0], 1); /* check first char only */
+ TCHECK2(bp->bp_sname[0], 1); /* check first char only */
if (*bp->bp_sname) {
- printf(" sname ");
- if (fn_print(bp->bp_sname, ep)) {
+ printf(" sname \"");
+ if (fn_print(bp->bp_sname, snapend)) {
+ putchar('"');
fputs(tstr + 1, stdout);
return;
}
}
- TCHECK(bp->bp_sname[0], 1); /* check first char only */
+ TCHECK2(bp->bp_sname[0], 1); /* check first char only */
if (*bp->bp_file) {
- printf(" file ");
- if (fn_print(bp->bp_file, ep)) {
+ printf(" file \"");
+ if (fn_print(bp->bp_file, snapend)) {
+ putchar('"');
fputs(tstr + 1, stdout);
return;
}
}
/* Decode the vendor buffer */
- TCHECK(bp->bp_vend[0], sizeof(bp->bp_vend));
+ TCHECK(bp->bp_vend[0]);
length -= sizeof(*bp) - sizeof(bp->bp_vend);
if (memcmp((char *)bp->bp_vend, (char *)vm_rfc1048,
sizeof(u_int32_t)) == 0)
@@ -183,7 +176,6 @@ bootp_print(register const u_char *cp, int length,
return;
trunc:
fputs(tstr, stdout);
-#undef TCHECK
}
/* The first character specifies the format to print */
@@ -214,10 +206,9 @@ static struct tok tag2str[] = {
};
static void
-rfc1048_print(register const u_char *bp, register int length)
+rfc1048_print(register const u_char *bp, register u_int length)
{
register u_char tag;
- register const u_char *ep;
register u_int len, size;
register const char *cp;
register char c;
@@ -227,14 +218,11 @@ rfc1048_print(register const u_char *bp, register int length)
printf(" vend-rfc1048");
- /* Setup end pointer */
- ep = bp + length;
-
/* Step over magic cookie */
bp += sizeof(int32_t);
/* Loop while we there is a tag left in the buffer */
- while (bp + 1 < ep) {
+ while (bp + 1 < snapend) {
tag = *bp++;
if (tag == TAG_PAD)
continue;
@@ -245,12 +233,12 @@ rfc1048_print(register const u_char *bp, register int length)
printf(" %s:", cp);
/* Get the length; check for truncation */
- if (bp + 1 >= ep) {
+ if (bp + 1 >= snapend) {
fputs(tstr, stdout);
return;
}
len = *bp++;
- if (bp + len >= ep) {
+ if (bp + len >= snapend) {
fputs(tstr, stdout);
return;
}
@@ -271,7 +259,9 @@ rfc1048_print(register const u_char *bp, register int length)
case 'a':
/* ascii strings */
+ putchar('"');
(void)fn_printn(bp, size, NULL);
+ putchar('"');
bp += size;
size = 0;
break;
@@ -326,25 +316,20 @@ rfc1048_print(register const u_char *bp, register int length)
}
static void
-cmu_print(register const u_char *bp, register int length)
+cmu_print(register const u_char *bp, register u_int length)
{
register const struct cmu_vend *cmu;
- register const u_char *ep;
char *fmt = " %s:%s";
-#define TCHECK(var, l) if ((u_char *)&(var) > ep - l) goto trunc
-#define PRINTCMUADDR(m, s) { TCHECK(cmu->m, sizeof(cmu->m)); \
+#define PRINTCMUADDR(m, s) { TCHECK(cmu->m); \
if (cmu->m.s_addr != 0) \
printf(fmt, s, ipaddr_string(&cmu->m.s_addr)); }
- /* Setup end pointer */
- ep = bp + length;
-
printf(" vend-cmu");
cmu = (struct cmu_vend *)bp;
/* Only print if there are unknown bits */
- TCHECK(cmu->v_flags, sizeof(cmu->v_flags));
+ TCHECK(cmu->v_flags);
if ((cmu->v_flags & ~(VF_SMASK)) != 0)
printf(" F:0x%x", cmu->v_flags);
PRINTCMUADDR(v_dgate, "DG");
@@ -359,6 +344,5 @@ cmu_print(register const u_char *bp, register int length)
trunc:
fputs(tstr, stdout);
-#undef TCHECK
#undef PRINTCMUADDR
}