diff options
author | Denis Ovsienko <infrastation@yandex.ru> | 2014-03-20 14:39:44 +0400 |
---|---|---|
committer | Denis Ovsienko <infrastation@yandex.ru> | 2014-03-20 15:17:35 +0400 |
commit | 90692fcf9745a67fff68350b88acd56e4ddcb23b (patch) | |
tree | 31430b376bc2d643da3c31733ca320040a9ab5f7 /print-wb.c | |
parent | 94b28f43b5c95af7591305e65b07471f230c9371 (diff) | |
download | tcpdump-90692fcf9745a67fff68350b88acd56e4ddcb23b.tar.gz |
NDOize ATM, MPTCP, NTP, VTP & Whiteboard decoders
Diffstat (limited to 'print-wb.c')
-rw-r--r-- | print-wb.c | 143 |
1 files changed, 76 insertions, 67 deletions
@@ -19,18 +19,19 @@ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ +#define NETDISSECT_REWORKED #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <tcpdump-stdinc.h> -#include <stdio.h> - #include "interface.h" #include "addrtoname.h" #include "extract.h" +static const char tstr[] = "[|wb]"; + /* XXX need to add byte-swapping macros! */ /* XXX - you mean like the ones in "extract.h"? */ @@ -175,7 +176,8 @@ struct pkt_prep { }; static int -wb_id(const struct pkt_id *id, u_int len) +wb_id(netdissect_options *ndo, + const struct pkt_id *id, u_int len) { int i; const char *cp; @@ -183,80 +185,83 @@ wb_id(const struct pkt_id *id, u_int len) char c; int nid; - printf(" wb-id:"); - if (len < sizeof(*id) || (u_char *)(id + 1) > snapend) + ND_PRINT((ndo, " wb-id:")); + if (len < sizeof(*id) || (u_char *)(id + 1) > ndo->ndo_snapend) return (-1); len -= sizeof(*id); - printf(" %u/%s:%u (max %u/%s:%u) ", + ND_PRINT((ndo, " %u/%s:%u (max %u/%s:%u) ", EXTRACT_32BITS(&id->pi_ps.slot), ipaddr_string(&id->pi_ps.page.p_sid), EXTRACT_32BITS(&id->pi_ps.page.p_uid), EXTRACT_32BITS(&id->pi_mslot), ipaddr_string(&id->pi_mpage.p_sid), - EXTRACT_32BITS(&id->pi_mpage.p_uid)); + EXTRACT_32BITS(&id->pi_mpage.p_uid))); nid = EXTRACT_16BITS(&id->pi_ps.nid); len -= sizeof(*io) * nid; io = (struct id_off *)(id + 1); cp = (char *)(io + nid); - if ((u_char *)cp + len <= snapend) { - putchar('"'); + if ((u_char *)cp + len <= ndo->ndo_snapend) { + ND_PRINT((ndo, "\"")); (void)fn_print((u_char *)cp, (u_char *)cp + len); - putchar('"'); + ND_PRINT((ndo, "\"")); } c = '<'; - for (i = 0; i < nid && (u_char *)(io + 1) <= snapend; ++io, ++i) { - printf("%c%s:%u", - c, ipaddr_string(&io->id), EXTRACT_32BITS(&io->off)); + for (i = 0; i < nid && (u_char *)(io + 1) <= ndo->ndo_snapend; ++io, ++i) { + ND_PRINT((ndo, "%c%s:%u", + c, ipaddr_string(&io->id), EXTRACT_32BITS(&io->off))); c = ','; } if (i >= nid) { - printf(">"); + ND_PRINT((ndo, ">")); return (0); } return (-1); } static int -wb_rreq(const struct pkt_rreq *rreq, u_int len) +wb_rreq(netdissect_options *ndo, + const struct pkt_rreq *rreq, u_int len) { - printf(" wb-rreq:"); - if (len < sizeof(*rreq) || (u_char *)(rreq + 1) > snapend) + ND_PRINT((ndo, " wb-rreq:")); + if (len < sizeof(*rreq) || (u_char *)(rreq + 1) > ndo->ndo_snapend) return (-1); - printf(" please repair %s %s:%u<%u:%u>", + ND_PRINT((ndo, " please repair %s %s:%u<%u:%u>", ipaddr_string(&rreq->pr_id), ipaddr_string(&rreq->pr_page.p_sid), EXTRACT_32BITS(&rreq->pr_page.p_uid), EXTRACT_32BITS(&rreq->pr_sseq), - EXTRACT_32BITS(&rreq->pr_eseq)); + EXTRACT_32BITS(&rreq->pr_eseq))); return (0); } static int -wb_preq(const struct pkt_preq *preq, u_int len) +wb_preq(netdissect_options *ndo, + const struct pkt_preq *preq, u_int len) { - printf(" wb-preq:"); - if (len < sizeof(*preq) || (u_char *)(preq + 1) > snapend) + ND_PRINT((ndo, " wb-preq:")); + if (len < sizeof(*preq) || (u_char *)(preq + 1) > ndo->ndo_snapend) return (-1); - printf(" need %u/%s:%u", + ND_PRINT((ndo, " need %u/%s:%u", EXTRACT_32BITS(&preq->pp_low), ipaddr_string(&preq->pp_page.p_sid), - EXTRACT_32BITS(&preq->pp_page.p_uid)); + EXTRACT_32BITS(&preq->pp_page.p_uid))); return (0); } static int -wb_prep(const struct pkt_prep *prep, u_int len) +wb_prep(netdissect_options *ndo, + const struct pkt_prep *prep, u_int len) { int n; const struct pgstate *ps; - const u_char *ep = snapend; + const u_char *ep = ndo->ndo_snapend; - printf(" wb-prep:"); + ND_PRINT((ndo, " wb-prep:")); if (len < sizeof(*prep)) { return (-1); } @@ -266,17 +271,17 @@ wb_prep(const struct pkt_prep *prep, u_int len) const struct id_off *io, *ie; char c = '<'; - printf(" %u/%s:%u", + ND_PRINT((ndo, " %u/%s:%u", EXTRACT_32BITS(&ps->slot), ipaddr_string(&ps->page.p_sid), - EXTRACT_32BITS(&ps->page.p_uid)); + EXTRACT_32BITS(&ps->page.p_uid))); io = (struct id_off *)(ps + 1); for (ie = io + ps->nid; io < ie && (u_char *)(io + 1) <= ep; ++io) { - printf("%c%s:%u", c, ipaddr_string(&io->id), - EXTRACT_32BITS(&io->off)); + ND_PRINT((ndo, "%c%s:%u", c, ipaddr_string(&io->id), + EXTRACT_32BITS(&io->off))); c = ','; } - printf(">"); + ND_PRINT((ndo, ">")); ps = (struct pgstate *)io; } return ((u_char *)ps <= ep? 0 : -1); @@ -303,21 +308,22 @@ static const char *dopstr[] = { }; static int -wb_dops(const struct dophdr *dh, u_int32_t ss, u_int32_t es) +wb_dops(netdissect_options *ndo, + const struct dophdr *dh, u_int32_t ss, u_int32_t es) { - printf(" <"); + ND_PRINT((ndo, " <")); for ( ; ss <= es; ++ss) { register int t = dh->dh_type; if (t > DT_MAXTYPE) - printf(" dop-%d!", t); + ND_PRINT((ndo, " dop-%d!", t)); else { - printf(" %s", dopstr[t]); + ND_PRINT((ndo, " %s", dopstr[t])); if (t == DT_SKIP || t == DT_HOLE) { u_int32_t ts = EXTRACT_32BITS(&dh->dh_ts); - printf("%d", ts - ss + 1); + ND_PRINT((ndo, "%d", ts - ss + 1)); if (ss > ts || ts > es) { - printf("[|]"); + ND_PRINT((ndo, "[|]")); if (ts < ss) return (0); } @@ -325,55 +331,57 @@ wb_dops(const struct dophdr *dh, u_int32_t ss, u_int32_t es) } } dh = DOP_NEXT(dh); - if ((u_char *)dh > snapend) { - printf("[|wb]"); + if ((u_char *)dh > ndo->ndo_snapend) { + ND_PRINT((ndo, tstr)); break; } } - printf(" >"); + ND_PRINT((ndo, " >")); return (0); } static int -wb_rrep(const struct pkt_rrep *rrep, u_int len) +wb_rrep(netdissect_options *ndo, + const struct pkt_rrep *rrep, u_int len) { const struct pkt_dop *dop = &rrep->pr_dop; - printf(" wb-rrep:"); - if (len < sizeof(*rrep) || (u_char *)(rrep + 1) > snapend) + ND_PRINT((ndo, " wb-rrep:")); + if (len < sizeof(*rrep) || (u_char *)(rrep + 1) > ndo->ndo_snapend) return (-1); len -= sizeof(*rrep); - printf(" for %s %s:%u<%u:%u>", + ND_PRINT((ndo, " for %s %s:%u<%u:%u>", ipaddr_string(&rrep->pr_id), ipaddr_string(&dop->pd_page.p_sid), EXTRACT_32BITS(&dop->pd_page.p_uid), EXTRACT_32BITS(&dop->pd_sseq), - EXTRACT_32BITS(&dop->pd_eseq)); + EXTRACT_32BITS(&dop->pd_eseq))); - if (vflag) - return (wb_dops((const struct dophdr *)(dop + 1), + if (ndo->ndo_vflag) + return (wb_dops(ndo, (const struct dophdr *)(dop + 1), EXTRACT_32BITS(&dop->pd_sseq), EXTRACT_32BITS(&dop->pd_eseq))); return (0); } static int -wb_drawop(const struct pkt_dop *dop, u_int len) +wb_drawop(netdissect_options *ndo, + const struct pkt_dop *dop, u_int len) { - printf(" wb-dop:"); - if (len < sizeof(*dop) || (u_char *)(dop + 1) > snapend) + ND_PRINT((ndo, " wb-dop:")); + if (len < sizeof(*dop) || (u_char *)(dop + 1) > ndo->ndo_snapend) return (-1); len -= sizeof(*dop); - printf(" %s:%u<%u:%u>", + ND_PRINT((ndo, " %s:%u<%u:%u>", ipaddr_string(&dop->pd_page.p_sid), EXTRACT_32BITS(&dop->pd_page.p_uid), EXTRACT_32BITS(&dop->pd_sseq), - EXTRACT_32BITS(&dop->pd_eseq)); + EXTRACT_32BITS(&dop->pd_eseq))); - if (vflag) - return (wb_dops((const struct dophdr *)(dop + 1), + if (ndo->ndo_vflag) + return (wb_dops(ndo, (const struct dophdr *)(dop + 1), EXTRACT_32BITS(&dop->pd_sseq), EXTRACT_32BITS(&dop->pd_eseq))); return (0); @@ -383,57 +391,58 @@ wb_drawop(const struct pkt_dop *dop, u_int len) * Print whiteboard multicast packets. */ void -wb_print(register const void *hdr, register u_int len) +wb_print(netdissect_options *ndo, + register const void *hdr, register u_int len) { register const struct pkt_hdr *ph; ph = (const struct pkt_hdr *)hdr; - if (len < sizeof(*ph) || (u_char *)(ph + 1) > snapend) { - printf("[|wb]"); + if (len < sizeof(*ph) || (u_char *)(ph + 1) > ndo->ndo_snapend) { + ND_PRINT((ndo, tstr)); return; } len -= sizeof(*ph); if (ph->ph_flags) - printf("*"); + ND_PRINT((ndo, "*")); switch (ph->ph_type) { case PT_KILL: - printf(" wb-kill"); + ND_PRINT((ndo, " wb-kill")); return; case PT_ID: - if (wb_id((struct pkt_id *)(ph + 1), len) >= 0) + if (wb_id(ndo, (struct pkt_id *)(ph + 1), len) >= 0) return; break; case PT_RREQ: - if (wb_rreq((struct pkt_rreq *)(ph + 1), len) >= 0) + if (wb_rreq(ndo, (struct pkt_rreq *)(ph + 1), len) >= 0) return; break; case PT_RREP: - if (wb_rrep((struct pkt_rrep *)(ph + 1), len) >= 0) + if (wb_rrep(ndo, (struct pkt_rrep *)(ph + 1), len) >= 0) return; break; case PT_DRAWOP: - if (wb_drawop((struct pkt_dop *)(ph + 1), len) >= 0) + if (wb_drawop(ndo, (struct pkt_dop *)(ph + 1), len) >= 0) return; break; case PT_PREQ: - if (wb_preq((struct pkt_preq *)(ph + 1), len) >= 0) + if (wb_preq(ndo, (struct pkt_preq *)(ph + 1), len) >= 0) return; break; case PT_PREP: - if (wb_prep((struct pkt_prep *)(ph + 1), len) >= 0) + if (wb_prep(ndo, (struct pkt_prep *)(ph + 1), len) >= 0) return; break; default: - printf(" wb-%d!", ph->ph_type); + ND_PRINT((ndo, " wb-%d!", ph->ph_type)); return; } } |