]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-wb.c
The third argument to linkaddr_string is one of the LINKADDR_ enums.
[tcpdump] / print-wb.c
index edbd5e4cb13aff854ca6203d5180ed19e8dc300e..24520e67796d42a8fde267851f3a1baacfe12196 100644 (file)
@@ -22,7 +22,7 @@
 /* \summary: White Board printer */
 
 #ifdef HAVE_CONFIG_H
-#include "config.h"
+#include <config.h>
 #endif
 
 #include "netdissect-stdinc.h"
@@ -31,7 +31,6 @@
 #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"? */
@@ -47,10 +46,10 @@ static const char tstr[] = "[|wb]";
  * an even multiple of DOP_ALIGN bytes, which must be a power of two.
  */
 #define DOP_ALIGN 4
-#define DOP_ROUNDUP(x) ((((int)(x)) + (DOP_ALIGN - 1)) & ~(DOP_ALIGN - 1))
+#define DOP_ROUNDUP(x) roundup2(x, DOP_ALIGN)
 #define DOP_NEXT(d)\
        ((const struct dophdr *)((const u_char *)(d) + \
-                               DOP_ROUNDUP(EXTRACT_BE_U_2((d)->dh_len) + sizeof(*(d)))))
+                               DOP_ROUNDUP(GET_BE_U_2((d)->dh_len) + sizeof(*(d)))))
 
 /*
  * Format of the whiteboard packet header.
@@ -192,27 +191,27 @@ wb_id(netdissect_options *ndo,
        len -= sizeof(*id);
 
        ND_PRINT(" %u/%s:%u (max %u/%s:%u) ",
-              EXTRACT_BE_U_4(id->pi_ps.slot),
-              ipaddr_string(ndo, &id->pi_ps.page.p_sid),
-              EXTRACT_BE_U_4(id->pi_ps.page.p_uid),
-              EXTRACT_BE_U_4(id->pi_mslot),
-              ipaddr_string(ndo, &id->pi_mpage.p_sid),
-              EXTRACT_BE_U_4(id->pi_mpage.p_uid));
-
-       nid = EXTRACT_BE_U_2(id->pi_ps.nid);
+              GET_BE_U_4(id->pi_ps.slot),
+              ipaddr_string(ndo, id->pi_ps.page.p_sid),
+              GET_BE_U_4(id->pi_ps.page.p_uid),
+              GET_BE_U_4(id->pi_mslot),
+              ipaddr_string(ndo, id->pi_mpage.p_sid),
+              GET_BE_U_4(id->pi_mpage.p_uid));
+
+       nid = GET_BE_U_2(id->pi_ps.nid);
        len -= sizeof(*io) * nid;
        io = (const struct id_off *)(id + 1);
        cp = (const char *)(io + nid);
        if (ND_TTEST_LEN(cp, len)) {
                ND_PRINT("\"");
-               fn_print(ndo, (const u_char *)cp, (const u_char *)cp + len);
+               nd_print(ndo, (const u_char *)cp, (const u_char *)cp + len);
                ND_PRINT("\"");
        }
 
        c = '<';
        for (i = 0; i < nid && ND_TTEST_SIZE(io); ++io, ++i) {
                ND_PRINT("%c%s:%u",
-                   c, ipaddr_string(ndo, &io->id), EXTRACT_BE_U_4(io->off));
+                   c, ipaddr_string(ndo, io->id), GET_BE_U_4(io->off));
                c = ',';
        }
        if (i >= nid) {
@@ -231,11 +230,11 @@ wb_rreq(netdissect_options *ndo,
                return (-1);
 
        ND_PRINT(" please repair %s %s:%u<%u:%u>",
-              ipaddr_string(ndo, &rreq->pr_id),
-              ipaddr_string(ndo, &rreq->pr_page.p_sid),
-              EXTRACT_BE_U_4(rreq->pr_page.p_uid),
-              EXTRACT_BE_U_4(rreq->pr_sseq),
-              EXTRACT_BE_U_4(rreq->pr_eseq));
+              ipaddr_string(ndo, rreq->pr_id),
+              ipaddr_string(ndo, rreq->pr_page.p_sid),
+              GET_BE_U_4(rreq->pr_page.p_uid),
+              GET_BE_U_4(rreq->pr_sseq),
+              GET_BE_U_4(rreq->pr_eseq));
        return (0);
 }
 
@@ -248,9 +247,9 @@ wb_preq(netdissect_options *ndo,
                return (-1);
 
        ND_PRINT(" need %u/%s:%u",
-              EXTRACT_BE_U_4(preq->pp_low),
-              ipaddr_string(ndo, &preq->pp_page.p_sid),
-              EXTRACT_BE_U_4(preq->pp_page.p_uid));
+              GET_BE_U_4(preq->pp_low),
+              ipaddr_string(ndo, preq->pp_page.p_sid),
+              GET_BE_U_4(preq->pp_page.p_uid));
        return (0);
 }
 
@@ -265,20 +264,20 @@ wb_prep(netdissect_options *ndo,
        ND_PRINT(" wb-prep:");
        if (len < sizeof(*prep) || !ND_TTEST_SIZE(prep))
                return (-1);
-       n = EXTRACT_BE_U_4(prep->pp_n);
+       n = GET_BE_U_4(prep->pp_n);
        ps = (const struct pgstate *)(prep + 1);
        while (n != 0 && ND_TTEST_SIZE(ps)) {
                const struct id_off *io, *ie;
                char c = '<';
 
                ND_PRINT(" %u/%s:%u",
-                   EXTRACT_BE_U_4(ps->slot),
-                   ipaddr_string(ndo, &ps->page.p_sid),
-                   EXTRACT_BE_U_4(ps->page.p_uid));
+                   GET_BE_U_4(ps->slot),
+                   ipaddr_string(ndo, ps->page.p_sid),
+                   GET_BE_U_4(ps->page.p_uid));
                io = (const struct id_off *)(ps + 1);
-               for (ie = io + EXTRACT_U_1(ps->nid); io < ie && ND_TTEST_SIZE(io); ++io) {
-                       ND_PRINT("%c%s:%u", c, ipaddr_string(ndo, &io->id),
-                           EXTRACT_BE_U_4(io->off));
+               for (ie = io + GET_U_1(ps->nid); io < ie && ND_TTEST_SIZE(io); ++io) {
+                       ND_PRINT("%c%s:%u", c, ipaddr_string(ndo, io->id),
+                           GET_BE_U_4(io->off));
                        c = ',';
                }
                ND_PRINT(">");
@@ -319,17 +318,17 @@ wb_dops(netdissect_options *ndo, const struct pkt_dop *dop,
                u_int t;
 
                if (!ND_TTEST_SIZE(dh)) {
-                       ND_PRINT("%s", tstr);
+                       nd_print_trunc(ndo);
                        break;
                }
-               t = EXTRACT_U_1(dh->dh_type);
+               t = GET_U_1(dh->dh_type);
 
                if (t > DT_MAXTYPE)
                        ND_PRINT(" dop-%u!", t);
                else {
                        ND_PRINT(" %s", dopstr[t]);
                        if (t == DT_SKIP || t == DT_HOLE) {
-                               uint32_t ts = EXTRACT_BE_U_4(dh->dh_ts);
+                               uint32_t ts = GET_BE_U_4(dh->dh_ts);
                                ND_PRINT("%u", ts - ss + 1);
                                if (ss > ts || ts > es) {
                                        ND_PRINT("[|]");
@@ -357,16 +356,16 @@ wb_rrep(netdissect_options *ndo,
        len -= sizeof(*rrep);
 
        ND_PRINT(" for %s %s:%u<%u:%u>",
-           ipaddr_string(ndo, &rrep->pr_id),
-           ipaddr_string(ndo, &dop->pd_page.p_sid),
-           EXTRACT_BE_U_4(dop->pd_page.p_uid),
-           EXTRACT_BE_U_4(dop->pd_sseq),
-           EXTRACT_BE_U_4(dop->pd_eseq));
+           ipaddr_string(ndo, rrep->pr_id),
+           ipaddr_string(ndo, dop->pd_page.p_sid),
+           GET_BE_U_4(dop->pd_page.p_uid),
+           GET_BE_U_4(dop->pd_sseq),
+           GET_BE_U_4(dop->pd_eseq));
 
        if (ndo->ndo_vflag)
                return (wb_dops(ndo, dop,
-                   EXTRACT_BE_U_4(dop->pd_sseq),
-                   EXTRACT_BE_U_4(dop->pd_eseq)));
+                   GET_BE_U_4(dop->pd_sseq),
+                   GET_BE_U_4(dop->pd_eseq)));
        return (0);
 }
 
@@ -380,15 +379,15 @@ wb_drawop(netdissect_options *ndo,
        len -= sizeof(*dop);
 
        ND_PRINT(" %s:%u<%u:%u>",
-           ipaddr_string(ndo, &dop->pd_page.p_sid),
-           EXTRACT_BE_U_4(dop->pd_page.p_uid),
-           EXTRACT_BE_U_4(dop->pd_sseq),
-           EXTRACT_BE_U_4(dop->pd_eseq));
+           ipaddr_string(ndo, dop->pd_page.p_sid),
+           GET_BE_U_4(dop->pd_page.p_uid),
+           GET_BE_U_4(dop->pd_sseq),
+           GET_BE_U_4(dop->pd_eseq));
 
        if (ndo->ndo_vflag)
                return (wb_dops(ndo, dop,
-                               EXTRACT_BE_U_4(dop->pd_sseq),
-                               EXTRACT_BE_U_4(dop->pd_eseq)));
+                               GET_BE_U_4(dop->pd_sseq),
+                               GET_BE_U_4(dop->pd_eseq)));
        return (0);
 }
 
@@ -402,16 +401,17 @@ wb_print(netdissect_options *ndo,
        const struct pkt_hdr *ph;
        uint8_t type;
 
+       ndo->ndo_protocol = "wb";
        ph = (const struct pkt_hdr *)hdr;
        if (len < sizeof(*ph) || !ND_TTEST_SIZE(ph)) {
-               ND_PRINT("%s", tstr);
+               nd_print_trunc(ndo);
                return;
        }
        len -= sizeof(*ph);
 
-       if (EXTRACT_U_1(ph->ph_flags))
+       if (GET_U_1(ph->ph_flags))
                ND_PRINT("*");
-       type = EXTRACT_U_1(ph->ph_type);
+       type = GET_U_1(ph->ph_type);
        switch (type) {
 
        case PT_KILL:
@@ -421,37 +421,37 @@ wb_print(netdissect_options *ndo,
        case PT_ID:
                if (wb_id(ndo, (const struct pkt_id *)(ph + 1), len) >= 0)
                        return;
-               ND_PRINT("%s", tstr);
+               nd_print_trunc(ndo);
                break;
 
        case PT_RREQ:
                if (wb_rreq(ndo, (const struct pkt_rreq *)(ph + 1), len) >= 0)
                        return;
-               ND_PRINT("%s", tstr);
+               nd_print_trunc(ndo);
                break;
 
        case PT_RREP:
                if (wb_rrep(ndo, (const struct pkt_rrep *)(ph + 1), len) >= 0)
                        return;
-               ND_PRINT("%s", tstr);
+               nd_print_trunc(ndo);
                break;
 
        case PT_DRAWOP:
                if (wb_drawop(ndo, (const struct pkt_dop *)(ph + 1), len) >= 0)
                        return;
-               ND_PRINT("%s", tstr);
+               nd_print_trunc(ndo);
                break;
 
        case PT_PREQ:
                if (wb_preq(ndo, (const struct pkt_preq *)(ph + 1), len) >= 0)
                        return;
-               ND_PRINT("%s", tstr);
+               nd_print_trunc(ndo);
                break;
 
        case PT_PREP:
                if (wb_prep(ndo, (const struct pkt_prep *)(ph + 1), len) >= 0)
                        return;
-               ND_PRINT("%s", tstr);
+               nd_print_trunc(ndo);
                break;
 
        default: