summaryrefslogtreecommitdiff
path: root/usr.sbin/tcpdump/print-wb.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/tcpdump/print-wb.c')
-rw-r--r--usr.sbin/tcpdump/print-wb.c276
1 files changed, 130 insertions, 146 deletions
diff --git a/usr.sbin/tcpdump/print-wb.c b/usr.sbin/tcpdump/print-wb.c
index 6185802cc3b..5bde81009e2 100644
--- a/usr.sbin/tcpdump/print-wb.c
+++ b/usr.sbin/tcpdump/print-wb.c
@@ -1,8 +1,7 @@
-/**//* $OpenBSD: print-wb.c,v 1.3 1996/06/10 07:47:53 deraadt Exp $ */
-/* $NetBSD: print-wb.c,v 1.2 1995/03/06 19:11:37 mycroft Exp $ */
+/* $OpenBSD: print-wb.c,v 1.4 1996/07/13 11:01:33 mickey Exp $ */
/*
- * Copyright (c) 1993, 1994
+ * Copyright (c) 1993, 1994, 1995
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -24,7 +23,7 @@
#ifndef lint
static char rcsid[] =
- "@(#) Header: print-wb.c,v 1.14 94/06/14 20:18:50 leres Exp (LBL)";
+ "@(#) Header: print-wb.c,v 1.18 95/10/18 22:21:27 leres Exp (LBL)";
#endif
#include <sys/types.h>
@@ -60,8 +59,8 @@ static char rcsid[] =
* The transport level header.
*/
struct pkt_hdr {
- u_int32 ph_src; /* site id of source */
- u_int32 ph_ts; /* time stamp (for skew computation) */
+ u_int32_t ph_src; /* site id of source */
+ u_int32_t ph_ts; /* time stamp (for skew computation) */
u_short ph_version; /* version number */
u_char ph_type; /* message type */
u_char ph_flags; /* message flags */
@@ -81,12 +80,12 @@ struct pkt_hdr {
#define PF_VIS 0x02 /* only visible ops wanted */
struct PageID {
- u_int32 p_sid; /* session id of initiator */
- u_int32 p_uid; /* page number */
+ u_int32_t p_sid; /* session id of initiator */
+ u_int32_t p_uid; /* page number */
};
struct dophdr {
- u_int32 dh_ts; /* sender's timestamp */
+ u_int32_t dh_ts; /* sender's timestamp */
u_short dh_len; /* body length */
u_char dh_flags;
u_char dh_type; /* body type */
@@ -116,8 +115,8 @@ struct dophdr {
*/
struct pkt_dop {
struct PageID pd_page; /* page that operations apply to */
- u_int32 pd_sseq; /* start sequence number */
- u_int32 pd_eseq; /* end sequence number */
+ u_int32_t pd_sseq; /* start sequence number */
+ u_int32_t pd_eseq; /* end sequence number */
/* drawing ops follow */
};
@@ -125,28 +124,28 @@ struct pkt_dop {
* A repair request.
*/
struct pkt_rreq {
- u_int32 pr_id; /* source id of drawops to be repaired */
+ u_int32_t pr_id; /* source id of drawops to be repaired */
struct PageID pr_page; /* page of drawops */
- u_int32 pr_sseq; /* start seqno */
- u_int32 pr_eseq; /* end seqno*/
+ u_int32_t pr_sseq; /* start seqno */
+ u_int32_t pr_eseq; /* end seqno*/
};
/*
* A repair reply.
*/
struct pkt_rrep {
- u_int32 pr_id; /* original site id of ops */
+ u_int32_t pr_id; /* original site id of ops */
struct pkt_dop pr_dop;
/* drawing ops follow */
};
struct id_off {
- u_int32 id;
- u_int32 off;
+ u_int32_t id;
+ u_int32_t off;
};
struct pgstate {
- u_int32 slot;
+ u_int32_t slot;
struct PageID page;
u_short nid;
u_short rsvd;
@@ -157,7 +156,7 @@ struct pgstate {
* An announcement packet.
*/
struct pkt_id {
- u_int32 pi_mslot;
+ u_int32_t pi_mslot;
struct PageID pi_mpage; /* current page */
struct pgstate pi_ps;
/* seqptr's */
@@ -166,12 +165,12 @@ struct pkt_id {
struct pkt_preq {
struct PageID pp_page;
- u_int32 pp_low;
- u_int32 pp_high;
+ u_int32_t pp_low;
+ u_int32_t pp_high;
};
struct pkt_prep {
- u_int32 pp_n; /* size of pageid array */
+ u_int32_t pp_n; /* size of pageid array */
/* pgstate's follow */
};
@@ -184,77 +183,66 @@ wb_id(const struct pkt_id *id, int len)
char c;
int nid;
+ printf(" wb-id:");
len -= sizeof(*id);
- if (len < 0) {
- printf(" truncated-wb-id!");
- return (0);
- }
- if ((u_char *)(id + 1) > snapend)
- return (-1);
- nid = ntohs(id->pi_ps.nid);
- len -= sizeof(*io) * nid;
- if (len < 0) {
- printf(" truncated-wb-id!");
- return (0);
- }
- io = (struct id_off *)(id + 1);
- cp = (char *)(io + nid);
- if ((u_char *)cp + len > snapend)
+ if (len < 0 || (u_char *)(id + 1) > snapend)
return (-1);
- printf(" wb-id: %d/%s:%d (max %d/%s:%d) ",
- ntohl(id->pi_ps.slot),
+ printf(" %u/%s:%u (max %u/%s:%u) ",
+ (u_int32_t)ntohl(id->pi_ps.slot),
ipaddr_string(&id->pi_ps.page.p_sid),
- ntohl(id->pi_ps.page.p_uid),
- ntohl(id->pi_mslot),
+ (u_int32_t)ntohl(id->pi_ps.page.p_uid),
+ (u_int32_t)ntohl(id->pi_mslot),
ipaddr_string(&id->pi_mpage.p_sid),
- ntohl(id->pi_mpage.p_uid));
+ (u_int32_t)ntohl(id->pi_mpage.p_uid));
- if (cp[len - 1] != '\0')
- printf("(unterm!) ");
-
- fn_print((u_char *)cp, (u_char *)cp + len);
+ nid = ntohs(id->pi_ps.nid);
+ len -= sizeof(*io) * nid;
+ io = (struct id_off *)(id + 1);
+ cp = (char *)(io + nid);
+ if ((u_char *)cp + len <= snapend)
+ fn_print((u_char *)cp, (u_char *)cp + len);
c = '<';
- for (i = 0; i < nid; ++io, ++i) {
- printf("%c%s:%d", c, ipaddr_string(&io->id), ntohl(io->off));
+ for (i = 0; i < nid && (u_char*)io < snapend; ++io, ++i) {
+ printf("%c%s:%u",
+ c, ipaddr_string(&io->id), (u_int32_t)ntohl(io->off));
c = ',';
}
- printf(">");
- return (0);
+ if (i >= nid) {
+ printf(">");
+ return (0);
+ }
+ return (-1);
}
static int
wb_rreq(const struct pkt_rreq *rreq, int len)
{
- if (len < sizeof(*rreq)) {
- printf(" truncated-wb-rreq!");
- return (0);
- }
- if ((u_char *)(rreq + 1) > snapend)
+ printf(" wb-rreq:");
+ if (len < sizeof(*rreq) || (u_char *)(rreq + 1) > snapend)
return (-1);
- printf(" wb-rreq: please repair %s %s:%ld<%ld:%ld>",
+ printf(" please repair %s %s:%u<%u:%u>",
ipaddr_string(&rreq->pr_id),
- ipaddr_string(&rreq->pr_page.p_sid), ntohl(rreq->pr_page.p_uid),
- ntohl(rreq->pr_sseq), ntohl(rreq->pr_eseq));
+ ipaddr_string(&rreq->pr_page.p_sid),
+ (u_int32_t)ntohl(rreq->pr_page.p_uid),
+ (u_int32_t)ntohl(rreq->pr_sseq),
+ (u_int32_t)ntohl(rreq->pr_eseq));
return (0);
}
static int
wb_preq(const struct pkt_preq *preq, int len)
{
- if (len < sizeof(*preq)) {
- printf(" truncated-wb-preq!");
- return (0);
- }
- if ((u_char *)(preq + 1) > snapend)
+ printf(" wb-preq:");
+ if (len < sizeof(*preq) || (u_char *)(preq + 1) > snapend)
return (-1);
- printf(" wb-preq: need %d/%s:%ld",
- ntohl(preq->pp_low),
+ printf(" need %u/%s:%u",
+ (u_int32_t)ntohl(preq->pp_low),
ipaddr_string(&preq->pp_page.p_sid),
- ntohl(preq->pp_page.p_uid));
+ (u_int32_t)ntohl(preq->pp_page.p_uid));
return (0);
}
@@ -265,24 +253,24 @@ wb_prep(const struct pkt_prep *prep, int len)
const struct pgstate* ps;
const u_char* ep = snapend;
+ printf(" wb-prep:");
if (len < sizeof(*prep)) {
- printf(" truncated-wb-prep!");
- return (0);
+ return (-1);
}
- printf(" wb-prep:");
n = ntohl(prep->pp_n);
ps = (const struct pgstate*)(prep + 1);
while (--n >= 0 && (u_char*)ps < ep) {
const struct id_off *io, *ie;
char c = '<';
- printf(" %lu/%s:%lu", ntohl(ps->slot),
- ipaddr_string(&ps->page.p_sid),
- ntohl(ps->page.p_uid));
+ printf(" %u/%s:%u",
+ (u_int32_t)ntohl(ps->slot),
+ ipaddr_string(&ps->page.p_sid),
+ (u_int32_t)ntohl(ps->page.p_uid));
io = (struct id_off*)(ps + 1);
for (ie = io + ps->nid; io < ie && (u_char*)io < ep; ++io) {
- printf("%c%s:%lu", c, ipaddr_string(&io->id),
- ntohl(io->off));
+ printf("%c%s:%u", c, ipaddr_string(&io->id),
+ (u_int32_t)ntohl(io->off));
c = ',';
}
printf(">");
@@ -312,7 +300,7 @@ char *dopstr[] = {
};
static int
-wb_dops(const struct dophdr *dh, u_int32 ss, u_int32 es)
+wb_dops(const struct dophdr *dh, u_int32_t ss, u_int32_t es)
{
printf(" <");
for ( ; ss <= es; ++ss) {
@@ -348,40 +336,42 @@ wb_rrep(const struct pkt_rrep *rrep, int len)
{
const struct pkt_dop *dop = &rrep->pr_dop;
+ printf(" wb-rrep:");
len -= sizeof(*rrep);
- if (len < 0) {
- printf(" truncated-wb-rrep!");
- return (0);
- }
- if ((u_char *)(rrep + 1) > snapend)
+ if (len < 0 || (u_char *)(rrep + 1) > snapend)
return (-1);
- printf(" wb-rrep: for %s %s:%d<%ld:%ld>",
- ipaddr_string(&rrep->pr_id),
- ipaddr_string(&dop->pd_page.p_sid), ntohl(dop->pd_page.p_uid),
- ntohl(dop->pd_sseq), ntohl(dop->pd_eseq));
+ printf(" for %s %s:%u<%u:%u>",
+ ipaddr_string(&rrep->pr_id),
+ ipaddr_string(&dop->pd_page.p_sid),
+ (u_int32_t)ntohl(dop->pd_page.p_uid),
+ (u_int32_t)ntohl(dop->pd_sseq),
+ (u_int32_t)ntohl(dop->pd_eseq));
- return (wb_dops((const struct dophdr*)(dop + 1),
- ntohl(dop->pd_sseq), ntohl(dop->pd_eseq)));
+ if (vflag)
+ return (wb_dops((const struct dophdr*)(dop + 1),
+ ntohl(dop->pd_sseq), ntohl(dop->pd_eseq)));
+ return (0);
}
static int
wb_drawop(const struct pkt_dop *dop, int len)
{
+ printf(" wb-dop:");
len -= sizeof(*dop);
- if (len < 0) {
- printf(" truncated-wb-dop!");
- return (0);
- }
- if ((u_char *)(dop + 1) > snapend)
+ if (len < 0 || (u_char *)(dop + 1) > snapend)
return (-1);
- printf(" wb-dop: %s:%d<%ld:%ld>",
- ipaddr_string(&dop->pd_page.p_sid), ntohl(dop->pd_page.p_uid),
- ntohl(dop->pd_sseq), ntohl(dop->pd_eseq));
+ printf(" %s:%u<%u:%u>",
+ ipaddr_string(&dop->pd_page.p_sid),
+ (u_int32_t)ntohl(dop->pd_page.p_uid),
+ (u_int32_t)ntohl(dop->pd_sseq),
+ (u_int32_t)ntohl(dop->pd_eseq));
- return (wb_dops((const struct dophdr*)(dop + 1),
- ntohl(dop->pd_sseq), ntohl(dop->pd_eseq)));
+ if (vflag)
+ return (wb_dops((const struct dophdr*)(dop + 1),
+ ntohl(dop->pd_sseq), ntohl(dop->pd_eseq)));
+ return (0);
}
/*
@@ -394,55 +384,49 @@ wb_print(register const void *hdr, register int len)
ph = (const struct pkt_hdr*)hdr;
len -= sizeof(*ph);
- if (len < 0) {
- printf(" truncated-wb!");
- return;
- }
- if ((u_char *)(ph + 1) > snapend) {
- trunc:
- printf("[|wb]");
- return;
- }
- if (ph->ph_flags)
- printf("*");
- switch (ph->ph_type) {
-
- case PT_KILL:
- printf(" wb-kill");
- break;
-
- case PT_ID:
- if (wb_id((struct pkt_id *)(ph + 1), len) < 0)
- goto trunc;
- break;
-
- case PT_RREQ:
- if (wb_rreq((struct pkt_rreq *)(ph + 1), len) < 0)
- goto trunc;
- break;
-
- case PT_RREP:
- if (wb_rrep((struct pkt_rrep *)(ph + 1), len) < 0)
- goto trunc;
- break;
-
- case PT_DRAWOP:
- if (wb_drawop((struct pkt_dop *)(ph + 1), len) < 0)
- goto trunc;
- break;
-
- case PT_PREQ:
- if (wb_preq((struct pkt_preq *)(ph + 1), len) < 0)
- goto trunc;
- break;
-
- case PT_PREP:
- if (wb_prep((struct pkt_prep *)(ph + 1), len) < 0)
- goto trunc;
- break;
-
- default:
- printf(" wb-%d!", ph->ph_type);
- return;
+ if (len < 0 || (u_char *)(ph + 1) <= snapend) {
+ if (ph->ph_flags)
+ printf("*");
+ switch (ph->ph_type) {
+
+ case PT_KILL:
+ printf(" wb-kill");
+ return;
+
+ case PT_ID:
+ if (wb_id((struct pkt_id *)(ph + 1), len) >= 0)
+ return;
+ break;
+
+ case PT_RREQ:
+ if (wb_rreq((struct pkt_rreq *)(ph + 1), len) >= 0)
+ return;
+ break;
+
+ case PT_RREP:
+ if (wb_rrep((struct pkt_rrep *)(ph + 1), len) >= 0)
+ return;
+ break;
+
+ case PT_DRAWOP:
+ if (wb_drawop((struct pkt_dop *)(ph + 1), len) >= 0)
+ return;
+ break;
+
+ case PT_PREQ:
+ if (wb_preq((struct pkt_preq *)(ph + 1), len) >= 0)
+ return;
+ break;
+
+ case PT_PREP:
+ if (wb_prep((struct pkt_prep *)(ph + 1), len) >= 0)
+ return;
+ break;
+
+ default:
+ printf(" wb-%d!", ph->ph_type);
+ return;
+ }
}
+ printf("[|wb]");
}