]> The Tcpdump Group git mirrors - tcpdump/commitdiff
NDOize DECnet, OSPF and TCP decoders
authorDenis Ovsienko <[email protected]>
Wed, 2 Apr 2014 08:59:56 +0000 (12:59 +0400)
committerDenis Ovsienko <[email protected]>
Wed, 2 Apr 2014 10:24:56 +0000 (14:24 +0400)
interface.h
netdissect.h
ospf.h
print-decnet.c
print-ether.c
print-ip.c
print-ip6.c
print-ospf.c
print-ospf6.c
print-tcp.c

index b4d0c11e5347bf7eb9c7197718413352e341d27b..c4c9c9e5febd73ebbe3e492234922ca5d0468aa9 100644 (file)
@@ -160,17 +160,14 @@ extern u_int16_t create_osi_cksum(const u_int8_t *, int, int);
 #include <pcap.h>
 
 extern void ascii_print(const u_char *, u_int);
-extern void decnet_print(const u_char *, u_int, u_int);
 extern void default_print(const u_char *, u_int);
 extern char *q922_string(const u_char *);
-extern void ospf_print(const u_char *, u_int, const u_char *);
 extern void rsvp_print(const u_char *, u_int);
 extern void lldp_print(const u_char *, u_int);
 extern u_int ppp_print(register const u_char *, u_int);
 extern u_int ppp_if_print(const struct pcap_pkthdr *, const u_char *);
 extern u_int ppp_hdlc_if_print(const struct pcap_pkthdr *, const u_char *);
 extern u_int ppp_bsdos_if_print(const struct pcap_pkthdr *, const u_char *);
-extern void tcp_print(const u_char *, u_int, const u_char *, int);
 extern void timed_print(const u_char *);
 extern char *smb_errstr(int, int);
 extern const char *nt_errstr(u_int32_t);
index ad374a89ddbca326bf6ef41bbdf49f6137c51b74..115d1c4ad408c8188c4745a0447ca05eeea602d6 100644 (file)
@@ -513,13 +513,16 @@ extern void smb_tcp_print(netdissect_options *, const u_char *, int);
 extern void netbeui_print(netdissect_options *, u_short, const u_char *, int);
 extern void ipx_netbios_print(netdissect_options *, const u_char *, u_int);
 extern void print_data(netdissect_options *, const unsigned char *, int);
+extern void decnet_print(netdissect_options *, const u_char *, u_int, u_int);
+extern void tcp_print(netdissect_options *, const u_char *, u_int, const u_char *, int);
+extern void ospf_print(netdissect_options *, const u_char *, u_int, const u_char *);
+extern int ospf_print_te_lsa(netdissect_options *, const u_int8_t *, u_int);
+extern int ospf_print_grace_lsa(netdissect_options *, const u_int8_t *, u_int);
 
 /* stuff that has not yet been rototiled */
 
 #if 0
 extern void ascii_print(netdissect_options *,u_int);
-extern void decnet_print(netdissect_options *,const u_char *,
-                        u_int, u_int);
 extern void default_print(netdissect_options *,const u_char *, u_int);
 
 extern const char *linkaddr_string(netdissect_options *ndo,
@@ -528,8 +531,6 @@ extern void nfsreply_print(netdissect_options *,const u_char *,
                           u_int, const u_char *);
 extern void nfsreq_print(netdissect_options *,const u_char *,
                         u_int, const u_char *);
-extern void ospf_print(netdissect_options *,const u_char *,
-                      u_int, const u_char *);
 extern void ppp_print(netdissect_options *,
                      register const u_char *, u_int);
 
@@ -539,8 +540,6 @@ extern void ppp_hdlc_if_print(u_char *,
 extern void ppp_bsdos_if_print(u_char *,
                               const struct pcap_pkthdr *, const u_char *);
 
-extern void tcp_print(netdissect_options *,const u_char *, u_int,
-                     const u_char *, int);
 extern void timed_print(netdissect_options *,const u_char *, u_int);
 extern char *smb_errstr(netdissect_options *,int, int);
 extern const char *nt_errstr(netdissect_options *, u_int32_t);
diff --git a/ospf.h b/ospf.h
index 65398028b07a01ee340ae3e435a6aa774547d6af..afcd50c5a11ba5e9c1136c6032e9231bd9eece56 100644 (file)
--- a/ospf.h
+++ b/ospf.h
@@ -323,7 +323,3 @@ struct ospfhdr {
 #define        ospf_lsr        ospf_un.un_lsr
 #define        ospf_lsu        ospf_un.un_lsu
 #define        ospf_lsa        ospf_un.un_lsa
-
-/* Functions shared by ospf and ospf6 */
-extern int ospf_print_te_lsa(const u_int8_t *, u_int);
-extern int ospf_print_grace_lsa(const u_int8_t *, u_int);
index 9746d962c6f56912e0f59d77b44ea855bf965768..a555571c502cfcd91c164d650e6becfc26d33d25 100644 (file)
@@ -19,6 +19,7 @@
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
+#define NETDISSECT_REWORKED
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -482,16 +483,16 @@ struct dcmsg                              /* disconnect confirm message */
   };
 
 /* Forwards */
-static int print_decnet_ctlmsg(const union routehdr *, u_int, u_int);
-static void print_t_info(int);
-static int print_l1_routes(const char *, u_int);
-static int print_l2_routes(const char *, u_int);
-static void print_i_info(int);
+static int print_decnet_ctlmsg(netdissect_options *, const union routehdr *, u_int, u_int);
+static void print_t_info(netdissect_options *, int);
+static int print_l1_routes(netdissect_options *, const char *, u_int);
+static int print_l2_routes(netdissect_options *, const char *, u_int);
+static void print_i_info(netdissect_options *, int);
 static int print_elist(const char *, u_int);
-static int print_nsp(const u_char *, u_int);
-static void print_reason(int);
+static int print_nsp(netdissect_options *, const u_char *, u_int);
+static void print_reason(netdissect_options *, int);
 #ifdef PRINT_NSPDATA
-static void pdata(u_char *, int);
+static void pdata(netdissect_options *, u_char *, u_int);
 #endif
 
 #ifndef HAVE_NETDNET_DNETDB_H_DNET_HTOA
@@ -499,8 +500,9 @@ extern char *dnet_htoa(struct dn_naddr *);
 #endif
 
 void
-decnet_print(register const u_char *ap, register u_int length,
-            register u_int caplen)
+decnet_print(netdissect_options *ndo,
+             register const u_char *ap, register u_int length,
+             register u_int caplen)
 {
        register const union routehdr *rhp;
        register int mflags;
@@ -509,36 +511,36 @@ decnet_print(register const u_char *ap, register u_int length,
        const u_char *nspp;
 
        if (length < sizeof(struct shorthdr)) {
-               (void)printf("%s", tstr);
+               ND_PRINT((ndo, "%s", tstr));
                return;
        }
 
-       TCHECK2(*ap, sizeof(short));
+       ND_TCHECK2(*ap, sizeof(short));
        pktlen = EXTRACT_LE_16BITS(ap);
        if (pktlen < sizeof(struct shorthdr)) {
-               (void)printf("%s", tstr);
+               ND_PRINT((ndo, "%s", tstr));
                return;
        }
        if (pktlen > length) {
-               (void)printf("%s", tstr);
+               ND_PRINT((ndo, "%s", tstr));
                return;
        }
        length = pktlen;
 
        rhp = (const union routehdr *)&(ap[sizeof(short)]);
-       TCHECK(rhp->rh_short.sh_flags);
+       ND_TCHECK(rhp->rh_short.sh_flags);
        mflags = EXTRACT_LE_8BITS(rhp->rh_short.sh_flags);
 
        if (mflags & RMF_PAD) {
            /* pad bytes of some sort in front of message */
            u_int padlen = mflags & RMF_PADMASK;
-           if (vflag)
-               (void) printf("[pad:%d] ", padlen);
+           if (ndo->ndo_vflag)
+               ND_PRINT((ndo, "[pad:%d] ", padlen));
            if (length < padlen + 2) {
-               (void)printf("%s", tstr);
+               ND_PRINT((ndo, "%s", tstr));
                return;
            }
-           TCHECK2(ap[sizeof(short)], padlen);
+           ND_TCHECK2(ap[sizeof(short)], padlen);
            ap += padlen;
            length -= padlen;
            caplen -= padlen;
@@ -547,14 +549,14 @@ decnet_print(register const u_char *ap, register u_int length,
        }
 
        if (mflags & RMF_FVER) {
-               (void) printf("future-version-decnet");
+               ND_PRINT((ndo, "future-version-decnet"));
                default_print(ap, min(length, caplen));
                return;
        }
 
        /* is it a control message? */
        if (mflags & RMF_CTLMSG) {
-               if (!print_decnet_ctlmsg(rhp, length, caplen))
+               if (!print_decnet_ctlmsg(ndo, rhp, length, caplen))
                        goto trunc;
                return;
        }
@@ -562,10 +564,10 @@ decnet_print(register const u_char *ap, register u_int length,
        switch (mflags & RMF_MASK) {
        case RMF_LONG:
            if (length < sizeof(struct longhdr)) {
-               (void)printf("%s", tstr);
+               ND_PRINT((ndo, "%s", tstr));
                return;
            }
-           TCHECK(rhp->rh_long);
+           ND_TCHECK(rhp->rh_long);
            dst =
                EXTRACT_LE_16BITS(rhp->rh_long.lg_dst.dne_remote.dne_nodeaddr);
            src =
@@ -575,7 +577,7 @@ decnet_print(register const u_char *ap, register u_int length,
            nsplen = length - sizeof(struct longhdr);
            break;
        case RMF_SHORT:
-           TCHECK(rhp->rh_short);
+           ND_TCHECK(rhp->rh_short);
            dst = EXTRACT_LE_16BITS(rhp->rh_short.sh_dst);
            src = EXTRACT_LE_16BITS(rhp->rh_short.sh_src);
            hops = (EXTRACT_LE_8BITS(rhp->rh_short.sh_visits) & VIS_MASK)+1;
@@ -583,35 +585,36 @@ decnet_print(register const u_char *ap, register u_int length,
            nsplen = length - sizeof(struct shorthdr);
            break;
        default:
-           (void) printf("unknown message flags under mask");
+           ND_PRINT((ndo, "unknown message flags under mask"));
            default_print((u_char *)ap, min(length, caplen));
            return;
        }
 
-       (void)printf("%s > %s %d ",
-                       dnaddr_string(src), dnaddr_string(dst), pktlen);
-       if (vflag) {
+       ND_PRINT((ndo, "%s > %s %d ",
+                       dnaddr_string(src), dnaddr_string(dst), pktlen));
+       if (ndo->ndo_vflag) {
            if (mflags & RMF_RQR)
-               (void)printf("RQR ");
+               ND_PRINT((ndo, "RQR "));
            if (mflags & RMF_RTS)
-               (void)printf("RTS ");
+               ND_PRINT((ndo, "RTS "));
            if (mflags & RMF_IE)
-               (void)printf("IE ");
-           (void)printf("%d hops ", hops);
+               ND_PRINT((ndo, "IE "));
+           ND_PRINT((ndo, "%d hops ", hops));
        }
 
-       if (!print_nsp(nspp, nsplen))
+       if (!print_nsp(ndo, nspp, nsplen))
                goto trunc;
        return;
 
 trunc:
-       (void)printf("%s", tstr);
+       ND_PRINT((ndo, "%s", tstr));
        return;
 }
 
 static int
-print_decnet_ctlmsg(register const union routehdr *rhp, u_int length,
-    u_int caplen)
+print_decnet_ctlmsg(netdissect_options *ndo,
+                    register const union routehdr *rhp, u_int length,
+                    u_int caplen)
 {
        int mflags = EXTRACT_LE_8BITS(rhp->rh_short.sh_flags);
        register union controlmsg *cmp = (union controlmsg *)rhp;
@@ -623,10 +626,10 @@ print_decnet_ctlmsg(register const union routehdr *rhp, u_int length,
 
        switch (mflags & RMF_CTLMASK) {
        case RMF_INIT:
-           (void)printf("init ");
+           ND_PRINT((ndo, "init "));
            if (length < sizeof(struct initmsg))
                goto trunc;
-           TCHECK(cmp->cm_init);
+           ND_TCHECK(cmp->cm_init);
            src = EXTRACT_LE_16BITS(cmp->cm_init.in_src);
            info = EXTRACT_LE_8BITS(cmp->cm_init.in_info);
            blksize = EXTRACT_LE_16BITS(cmp->cm_init.in_blksize);
@@ -634,58 +637,58 @@ print_decnet_ctlmsg(register const union routehdr *rhp, u_int length,
            eco = EXTRACT_LE_8BITS(cmp->cm_init.in_eco);
            ueco = EXTRACT_LE_8BITS(cmp->cm_init.in_ueco);
            hello = EXTRACT_LE_16BITS(cmp->cm_init.in_hello);
-           print_t_info(info);
-           (void)printf(
+           print_t_info(ndo, info);
+           ND_PRINT((ndo,
                "src %sblksize %d vers %d eco %d ueco %d hello %d",
                        dnaddr_string(src), blksize, vers, eco, ueco,
-                       hello);
+                       hello));
            ret = 1;
            break;
        case RMF_VER:
-           (void)printf("verification ");
+           ND_PRINT((ndo, "verification "));
            if (length < sizeof(struct verifmsg))
                goto trunc;
-           TCHECK(cmp->cm_ver);
+           ND_TCHECK(cmp->cm_ver);
            src = EXTRACT_LE_16BITS(cmp->cm_ver.ve_src);
            other = EXTRACT_LE_8BITS(cmp->cm_ver.ve_fcnval);
-           (void)printf("src %s fcnval %o", dnaddr_string(src), other);
+           ND_PRINT((ndo, "src %s fcnval %o", dnaddr_string(src), other));
            ret = 1;
            break;
        case RMF_TEST:
-           (void)printf("test ");
+           ND_PRINT((ndo, "test "));
            if (length < sizeof(struct testmsg))
                goto trunc;
-           TCHECK(cmp->cm_test);
+           ND_TCHECK(cmp->cm_test);
            src = EXTRACT_LE_16BITS(cmp->cm_test.te_src);
            other = EXTRACT_LE_8BITS(cmp->cm_test.te_data);
-           (void)printf("src %s data %o", dnaddr_string(src), other);
+           ND_PRINT((ndo, "src %s data %o", dnaddr_string(src), other));
            ret = 1;
            break;
        case RMF_L1ROUT:
-           (void)printf("lev-1-routing ");
+           ND_PRINT((ndo, "lev-1-routing "));
            if (length < sizeof(struct l1rout))
                goto trunc;
-           TCHECK(cmp->cm_l1rou);
+           ND_TCHECK(cmp->cm_l1rou);
            src = EXTRACT_LE_16BITS(cmp->cm_l1rou.r1_src);
-           (void)printf("src %s ", dnaddr_string(src));
-           ret = print_l1_routes(&(rhpx[sizeof(struct l1rout)]),
+           ND_PRINT((ndo, "src %s ", dnaddr_string(src)));
+           ret = print_l1_routes(ndo, &(rhpx[sizeof(struct l1rout)]),
                                length - sizeof(struct l1rout));
            break;
        case RMF_L2ROUT:
-           (void)printf("lev-2-routing ");
+           ND_PRINT((ndo, "lev-2-routing "));
            if (length < sizeof(struct l2rout))
                goto trunc;
-           TCHECK(cmp->cm_l2rout);
+           ND_TCHECK(cmp->cm_l2rout);
            src = EXTRACT_LE_16BITS(cmp->cm_l2rout.r2_src);
-           (void)printf("src %s ", dnaddr_string(src));
-           ret = print_l2_routes(&(rhpx[sizeof(struct l2rout)]),
+           ND_PRINT((ndo, "src %s ", dnaddr_string(src)));
+           ret = print_l2_routes(ndo, &(rhpx[sizeof(struct l2rout)]),
                                length - sizeof(struct l2rout));
            break;
        case RMF_RHELLO:
-           (void)printf("router-hello ");
+           ND_PRINT((ndo, "router-hello "));
            if (length < sizeof(struct rhellomsg))
                goto trunc;
-           TCHECK(cmp->cm_rhello);
+           ND_TCHECK(cmp->cm_rhello);
            vers = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_vers);
            eco = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_eco);
            ueco = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_ueco);
@@ -696,19 +699,19 @@ print_decnet_ctlmsg(register const union routehdr *rhp, u_int length,
            blksize = EXTRACT_LE_16BITS(cmp->cm_rhello.rh_blksize);
            priority = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_priority);
            hello = EXTRACT_LE_16BITS(cmp->cm_rhello.rh_hello);
-           print_i_info(info);
-           (void)printf(
+           print_i_info(ndo, info);
+           ND_PRINT((ndo,
            "vers %d eco %d ueco %d src %s blksize %d pri %d hello %d",
                        vers, eco, ueco, dnaddr_string(src),
-                       blksize, priority, hello);
+                       blksize, priority, hello));
            ret = print_elist(&(rhpx[sizeof(struct rhellomsg)]),
                                length - sizeof(struct rhellomsg));
            break;
        case RMF_EHELLO:
-           (void)printf("endnode-hello ");
+           ND_PRINT((ndo, "endnode-hello "));
            if (length < sizeof(struct ehellomsg))
                goto trunc;
-           TCHECK(cmp->cm_ehello);
+           ND_TCHECK(cmp->cm_ehello);
            vers = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_vers);
            eco = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_eco);
            ueco = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_ueco);
@@ -723,16 +726,16 @@ print_decnet_ctlmsg(register const union routehdr *rhp, u_int length,
            dst = EXTRACT_LE_16BITS(rtea.dne_remote.dne_nodeaddr);
            hello = EXTRACT_LE_16BITS(cmp->cm_ehello.eh_hello);
            other = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_data);
-           print_i_info(info);
-           (void)printf(
+           print_i_info(ndo, info);
+           ND_PRINT((ndo,
        "vers %d eco %d ueco %d src %s blksize %d rtr %s hello %d data %o",
                        vers, eco, ueco, dnaddr_string(src),
-                       blksize, dnaddr_string(dst), hello, other);
+                       blksize, dnaddr_string(dst), hello, other));
            ret = 1;
            break;
 
        default:
-           (void)printf("unknown control message");
+           ND_PRINT((ndo, "unknown control message"));
            default_print((u_char *)rhp, min(length, caplen));
            ret = 1;
            break;
@@ -744,23 +747,25 @@ trunc:
 }
 
 static void
-print_t_info(int info)
+print_t_info(netdissect_options *ndo,
+             int info)
 {
        int ntype = info & 3;
        switch (ntype) {
-       case 0: (void)printf("reserved-ntype? "); break;
-       case TI_L2ROUT: (void)printf("l2rout "); break;
-       case TI_L1ROUT: (void)printf("l1rout "); break;
-       case TI_ENDNODE: (void)printf("endnode "); break;
+       case 0: ND_PRINT((ndo, "reserved-ntype? ")); break;
+       case TI_L2ROUT: ND_PRINT((ndo, "l2rout ")); break;
+       case TI_L1ROUT: ND_PRINT((ndo, "l1rout ")); break;
+       case TI_ENDNODE: ND_PRINT((ndo, "endnode ")); break;
        }
        if (info & TI_VERIF)
-           (void)printf("verif ");
+           ND_PRINT((ndo, "verif "));
        if (info & TI_BLOCK)
-           (void)printf("blo ");
+           ND_PRINT((ndo, "blo "));
 }
 
 static int
-print_l1_routes(const char *rp, u_int len)
+print_l1_routes(netdissect_options *ndo,
+                const char *rp, u_int len)
 {
        int count;
        int id;
@@ -768,7 +773,7 @@ print_l1_routes(const char *rp, u_int len)
 
        /* The last short is a checksum */
        while (len > (3 * sizeof(short))) {
-           TCHECK2(*rp, 3 * sizeof(short));
+           ND_TCHECK2(*rp, 3 * sizeof(short));
            count = EXTRACT_LE_16BITS(rp);
            if (count > 1024)
                return (1);     /* seems to be bogus from here on */
@@ -780,8 +785,8 @@ print_l1_routes(const char *rp, u_int len)
            info = EXTRACT_LE_16BITS(rp);
            rp += sizeof(short);
            len -= sizeof(short);
-           (void)printf("{ids %d-%d cost %d hops %d} ", id, id + count,
-                           RI_COST(info), RI_HOPS(info));
+           ND_PRINT((ndo, "{ids %d-%d cost %d hops %d} ", id, id + count,
+                           RI_COST(info), RI_HOPS(info)));
        }
        return (1);
 
@@ -790,7 +795,8 @@ trunc:
 }
 
 static int
-print_l2_routes(const char *rp, u_int len)
+print_l2_routes(netdissect_options *ndo,
+                const char *rp, u_int len)
 {
        int count;
        int area;
@@ -798,7 +804,7 @@ print_l2_routes(const char *rp, u_int len)
 
        /* The last short is a checksum */
        while (len > (3 * sizeof(short))) {
-           TCHECK2(*rp, 3 * sizeof(short));
+           ND_TCHECK2(*rp, 3 * sizeof(short));
            count = EXTRACT_LE_16BITS(rp);
            if (count > 1024)
                return (1);     /* seems to be bogus from here on */
@@ -810,8 +816,8 @@ print_l2_routes(const char *rp, u_int len)
            info = EXTRACT_LE_16BITS(rp);
            rp += sizeof(short);
            len -= sizeof(short);
-           (void)printf("{areas %d-%d cost %d hops %d} ", area, area + count,
-                           RI_COST(info), RI_HOPS(info));
+           ND_PRINT((ndo, "{areas %d-%d cost %d hops %d} ", area, area + count,
+                           RI_COST(info), RI_HOPS(info)));
        }
        return (1);
 
@@ -820,21 +826,22 @@ trunc:
 }
 
 static void
-print_i_info(int info)
+print_i_info(netdissect_options *ndo,
+             int info)
 {
        int ntype = info & II_TYPEMASK;
        switch (ntype) {
-       case 0: (void)printf("reserved-ntype? "); break;
-       case II_L2ROUT: (void)printf("l2rout "); break;
-       case II_L1ROUT: (void)printf("l1rout "); break;
-       case II_ENDNODE: (void)printf("endnode "); break;
+       case 0: ND_PRINT((ndo, "reserved-ntype? ")); break;
+       case II_L2ROUT: ND_PRINT((ndo, "l2rout ")); break;
+       case II_L1ROUT: ND_PRINT((ndo, "l1rout ")); break;
+       case II_ENDNODE: ND_PRINT((ndo, "endnode ")); break;
        }
        if (info & II_VERIF)
-           (void)printf("verif ");
+           ND_PRINT((ndo, "verif "));
        if (info & II_NOMCAST)
-           (void)printf("nomcast ");
+           ND_PRINT((ndo, "nomcast "));
        if (info & II_BLOCK)
-           (void)printf("blo ");
+           ND_PRINT((ndo, "blo "));
 }
 
 static int
@@ -845,14 +852,15 @@ print_elist(const char *elp _U_, u_int len _U_)
 }
 
 static int
-print_nsp(const u_char *nspp, u_int nsplen)
+print_nsp(netdissect_options *ndo,
+          const u_char *nspp, u_int nsplen)
 {
        const struct nsphdr *nsphp = (struct nsphdr *)nspp;
        int dst, src, flags;
 
        if (nsplen < sizeof(struct nsphdr))
                goto trunc;
-       TCHECK(*nsphp);
+       ND_TCHECK(*nsphp);
        flags = EXTRACT_LE_8BITS(nsphp->nh_flags);
        dst = EXTRACT_LE_16BITS(nsphp->nh_dst);
        src = EXTRACT_LE_16BITS(nsphp->nh_src);
@@ -864,7 +872,7 @@ print_nsp(const u_char *nspp, u_int nsplen)
            case MFS_MOM:
            case MFS_EOM:
            case MFS_BOM+MFS_EOM:
-               printf("data %d>%d ", src, dst);
+               ND_PRINT((ndo, "data %d>%d ", src, dst));
                {
                    struct seghdr *shp = (struct seghdr *)nspp;
                    int ack;
@@ -875,42 +883,42 @@ print_nsp(const u_char *nspp, u_int nsplen)
 
                    if (nsplen < data_off)
                        goto trunc;
-                   TCHECK(shp->sh_seq[0]);
+                   ND_TCHECK(shp->sh_seq[0]);
                    ack = EXTRACT_LE_16BITS(shp->sh_seq[0]);
                    if (ack & SGQ_ACK) {        /* acknum field */
                        if ((ack & SGQ_NAK) == SGQ_NAK)
-                           (void)printf("nak %d ", ack & SGQ_MASK);
+                           ND_PRINT((ndo, "nak %d ", ack & SGQ_MASK));
                        else
-                           (void)printf("ack %d ", ack & SGQ_MASK);
+                           ND_PRINT((ndo, "ack %d ", ack & SGQ_MASK));
                        data_off += sizeof(short);
                        if (nsplen < data_off)
                            goto trunc;
-                       TCHECK(shp->sh_seq[1]);
+                       ND_TCHECK(shp->sh_seq[1]);
                        ack = EXTRACT_LE_16BITS(shp->sh_seq[1]);
                        if (ack & SGQ_OACK) {   /* ackoth field */
                            if ((ack & SGQ_ONAK) == SGQ_ONAK)
-                               (void)printf("onak %d ", ack & SGQ_MASK);
+                               ND_PRINT((ndo, "onak %d ", ack & SGQ_MASK));
                            else
-                               (void)printf("oack %d ", ack & SGQ_MASK);
+                               ND_PRINT((ndo, "oack %d ", ack & SGQ_MASK));
                            data_off += sizeof(short);
                            if (nsplen < data_off)
                                goto trunc;
-                           TCHECK(shp->sh_seq[2]);
+                           ND_TCHECK(shp->sh_seq[2]);
                            ack = EXTRACT_LE_16BITS(shp->sh_seq[2]);
                        }
                    }
-                   (void)printf("seg %d ", ack & SGQ_MASK);
+                   ND_PRINT((ndo, "seg %d ", ack & SGQ_MASK));
 #ifdef PRINT_NSPDATA
                    if (nsplen > data_off) {
                        dp = &(nspp[data_off]);
-                       TCHECK2(*dp, nsplen - data_off);
-                       pdata(dp, nsplen - data_off);
+                       ND_TCHECK2(*dp, nsplen - data_off);
+                       pdata(ndo, dp, nsplen - data_off);
                    }
 #endif
                }
                break;
            case MFS_ILS+MFS_INT:
-               printf("intr ");
+               ND_PRINT((ndo, "intr "));
                {
                    struct seghdr *shp = (struct seghdr *)nspp;
                    int ack;
@@ -921,42 +929,42 @@ print_nsp(const u_char *nspp, u_int nsplen)
 
                    if (nsplen < data_off)
                        goto trunc;
-                   TCHECK(shp->sh_seq[0]);
+                   ND_TCHECK(shp->sh_seq[0]);
                    ack = EXTRACT_LE_16BITS(shp->sh_seq[0]);
                    if (ack & SGQ_ACK) {        /* acknum field */
                        if ((ack & SGQ_NAK) == SGQ_NAK)
-                           (void)printf("nak %d ", ack & SGQ_MASK);
+                           ND_PRINT((ndo, "nak %d ", ack & SGQ_MASK));
                        else
-                           (void)printf("ack %d ", ack & SGQ_MASK);
+                           ND_PRINT((ndo, "ack %d ", ack & SGQ_MASK));
                        data_off += sizeof(short);
                        if (nsplen < data_off)
                            goto trunc;
-                       TCHECK(shp->sh_seq[1]);
+                       ND_TCHECK(shp->sh_seq[1]);
                        ack = EXTRACT_LE_16BITS(shp->sh_seq[1]);
                        if (ack & SGQ_OACK) {   /* ackdat field */
                            if ((ack & SGQ_ONAK) == SGQ_ONAK)
-                               (void)printf("nakdat %d ", ack & SGQ_MASK);
+                               ND_PRINT((ndo, "nakdat %d ", ack & SGQ_MASK));
                            else
-                               (void)printf("ackdat %d ", ack & SGQ_MASK);
+                               ND_PRINT((ndo, "ackdat %d ", ack & SGQ_MASK));
                            data_off += sizeof(short);
                            if (nsplen < data_off)
                                goto trunc;
-                           TCHECK(shp->sh_seq[2]);
+                           ND_TCHECK(shp->sh_seq[2]);
                            ack = EXTRACT_LE_16BITS(shp->sh_seq[2]);
                        }
                    }
-                   (void)printf("seg %d ", ack & SGQ_MASK);
+                   ND_PRINT((ndo, "seg %d ", ack & SGQ_MASK));
 #ifdef PRINT_NSPDATA
                    if (nsplen > data_off) {
                        dp = &(nspp[data_off]);
-                       TCHECK2(*dp, nsplen - data_off);
-                       pdata(dp, nsplen - data_off);
+                       ND_TCHECK2(*dp, nsplen - data_off);
+                       pdata(ndo, dp, nsplen - data_off);
                    }
 #endif
                }
                break;
            case MFS_ILS:
-               (void)printf("link-service %d>%d ", src, dst);
+               ND_PRINT((ndo, "link-service %d>%d ", src, dst));
                {
                    struct seghdr *shp = (struct seghdr *)nspp;
                    struct lsmsg *lsmp =
@@ -966,117 +974,117 @@ print_nsp(const u_char *nspp, u_int nsplen)
 
                    if (nsplen < sizeof(struct seghdr) + sizeof(struct lsmsg))
                        goto trunc;
-                   TCHECK(shp->sh_seq[0]);
+                   ND_TCHECK(shp->sh_seq[0]);
                    ack = EXTRACT_LE_16BITS(shp->sh_seq[0]);
                    if (ack & SGQ_ACK) {        /* acknum field */
                        if ((ack & SGQ_NAK) == SGQ_NAK)
-                           (void)printf("nak %d ", ack & SGQ_MASK);
+                           ND_PRINT((ndo, "nak %d ", ack & SGQ_MASK));
                        else
-                           (void)printf("ack %d ", ack & SGQ_MASK);
-                       TCHECK(shp->sh_seq[1]);
+                           ND_PRINT((ndo, "ack %d ", ack & SGQ_MASK));
+                       ND_TCHECK(shp->sh_seq[1]);
                        ack = EXTRACT_LE_16BITS(shp->sh_seq[1]);
                        if (ack & SGQ_OACK) {   /* ackdat field */
                            if ((ack & SGQ_ONAK) == SGQ_ONAK)
-                               (void)printf("nakdat %d ", ack & SGQ_MASK);
+                               ND_PRINT((ndo, "nakdat %d ", ack & SGQ_MASK));
                            else
-                               (void)printf("ackdat %d ", ack & SGQ_MASK);
-                           TCHECK(shp->sh_seq[2]);
+                               ND_PRINT((ndo, "ackdat %d ", ack & SGQ_MASK));
+                           ND_TCHECK(shp->sh_seq[2]);
                            ack = EXTRACT_LE_16BITS(shp->sh_seq[2]);
                        }
                    }
-                   (void)printf("seg %d ", ack & SGQ_MASK);
-                   TCHECK(*lsmp);
+                   ND_PRINT((ndo, "seg %d ", ack & SGQ_MASK));
+                   ND_TCHECK(*lsmp);
                    lsflags = EXTRACT_LE_8BITS(lsmp->ls_lsflags);
                    fcval = EXTRACT_LE_8BITS(lsmp->ls_fcval);
                    switch (lsflags & LSI_MASK) {
                    case LSI_DATA:
-                       (void)printf("dat seg count %d ", fcval);
+                       ND_PRINT((ndo, "dat seg count %d ", fcval));
                        switch (lsflags & LSM_MASK) {
                        case LSM_NOCHANGE:
                            break;
                        case LSM_DONOTSEND:
-                           (void)printf("donotsend-data ");
+                           ND_PRINT((ndo, "donotsend-data "));
                            break;
                        case LSM_SEND:
-                           (void)printf("send-data ");
+                           ND_PRINT((ndo, "send-data "));
                            break;
                        default:
-                           (void)printf("reserved-fcmod? %x", lsflags);
+                           ND_PRINT((ndo, "reserved-fcmod? %x", lsflags));
                            break;
                        }
                        break;
                    case LSI_INTR:
-                       (void)printf("intr req count %d ", fcval);
+                       ND_PRINT((ndo, "intr req count %d ", fcval));
                        break;
                    default:
-                       (void)printf("reserved-fcval-int? %x", lsflags);
+                       ND_PRINT((ndo, "reserved-fcval-int? %x", lsflags));
                        break;
                    }
                }
                break;
            default:
-               (void)printf("reserved-subtype? %x %d > %d", flags, src, dst);
+               ND_PRINT((ndo, "reserved-subtype? %x %d > %d", flags, src, dst));
                break;
            }
            break;
        case MFT_ACK:
            switch (flags & NSP_SUBMASK) {
            case MFS_DACK:
-               (void)printf("data-ack %d>%d ", src, dst);
+               ND_PRINT((ndo, "data-ack %d>%d ", src, dst));
                {
                    struct ackmsg *amp = (struct ackmsg *)nspp;
                    int ack;
 
                    if (nsplen < sizeof(struct ackmsg))
                        goto trunc;
-                   TCHECK(*amp);
+                   ND_TCHECK(*amp);
                    ack = EXTRACT_LE_16BITS(amp->ak_acknum[0]);
                    if (ack & SGQ_ACK) {        /* acknum field */
                        if ((ack & SGQ_NAK) == SGQ_NAK)
-                           (void)printf("nak %d ", ack & SGQ_MASK);
+                           ND_PRINT((ndo, "nak %d ", ack & SGQ_MASK));
                        else
-                           (void)printf("ack %d ", ack & SGQ_MASK);
+                           ND_PRINT((ndo, "ack %d ", ack & SGQ_MASK));
                        ack = EXTRACT_LE_16BITS(amp->ak_acknum[1]);
                        if (ack & SGQ_OACK) {   /* ackoth field */
                            if ((ack & SGQ_ONAK) == SGQ_ONAK)
-                               (void)printf("onak %d ", ack & SGQ_MASK);
+                               ND_PRINT((ndo, "onak %d ", ack & SGQ_MASK));
                            else
-                               (void)printf("oack %d ", ack & SGQ_MASK);
+                               ND_PRINT((ndo, "oack %d ", ack & SGQ_MASK));
                        }
                    }
                }
                break;
            case MFS_IACK:
-               (void)printf("ils-ack %d>%d ", src, dst);
+               ND_PRINT((ndo, "ils-ack %d>%d ", src, dst));
                {
                    struct ackmsg *amp = (struct ackmsg *)nspp;
                    int ack;
 
                    if (nsplen < sizeof(struct ackmsg))
                        goto trunc;
-                   TCHECK(*amp);
+                   ND_TCHECK(*amp);
                    ack = EXTRACT_LE_16BITS(amp->ak_acknum[0]);
                    if (ack & SGQ_ACK) {        /* acknum field */
                        if ((ack & SGQ_NAK) == SGQ_NAK)
-                           (void)printf("nak %d ", ack & SGQ_MASK);
+                           ND_PRINT((ndo, "nak %d ", ack & SGQ_MASK));
                        else
-                           (void)printf("ack %d ", ack & SGQ_MASK);
-                       TCHECK(amp->ak_acknum[1]);
+                           ND_PRINT((ndo, "ack %d ", ack & SGQ_MASK));
+                       ND_TCHECK(amp->ak_acknum[1]);
                        ack = EXTRACT_LE_16BITS(amp->ak_acknum[1]);
                        if (ack & SGQ_OACK) {   /* ackdat field */
                            if ((ack & SGQ_ONAK) == SGQ_ONAK)
-                               (void)printf("nakdat %d ", ack & SGQ_MASK);
+                               ND_PRINT((ndo, "nakdat %d ", ack & SGQ_MASK));
                            else
-                               (void)printf("ackdat %d ", ack & SGQ_MASK);
+                               ND_PRINT((ndo, "ackdat %d ", ack & SGQ_MASK));
                        }
                    }
                }
                break;
            case MFS_CACK:
-               (void)printf("conn-ack %d", dst);
+               ND_PRINT((ndo, "conn-ack %d", dst));
                break;
            default:
-               (void)printf("reserved-acktype? %x %d > %d", flags, src, dst);
+               ND_PRINT((ndo, "reserved-acktype? %x %d > %d", flags, src, dst));
                break;
            }
            break;
@@ -1085,10 +1093,10 @@ print_nsp(const u_char *nspp, u_int nsplen)
            case MFS_CI:
            case MFS_RCI:
                if ((flags & NSP_SUBMASK) == MFS_CI)
-                   (void)printf("conn-initiate ");
+                   ND_PRINT((ndo, "conn-initiate "));
                else
-                   (void)printf("retrans-conn-initiate ");
-               (void)printf("%d>%d ", src, dst);
+                   ND_PRINT((ndo, "retrans-conn-initiate "));
+               ND_PRINT((ndo, "%d>%d ", src, dst));
                {
                    struct cimsg *cimp = (struct cimsg *)nspp;
                    int services, info, segsize;
@@ -1098,7 +1106,7 @@ print_nsp(const u_char *nspp, u_int nsplen)
 
                    if (nsplen < sizeof(struct cimsg))
                        goto trunc;
-                   TCHECK(*cimp);
+                   ND_TCHECK(*cimp);
                    services = EXTRACT_LE_8BITS(cimp->ci_services);
                    info = EXTRACT_LE_8BITS(cimp->ci_info);
                    segsize = EXTRACT_LE_16BITS(cimp->ci_segsize);
@@ -1107,41 +1115,41 @@ print_nsp(const u_char *nspp, u_int nsplen)
                    case COS_NONE:
                        break;
                    case COS_SEGMENT:
-                       (void)printf("seg ");
+                       ND_PRINT((ndo, "seg "));
                        break;
                    case COS_MESSAGE:
-                       (void)printf("msg ");
+                       ND_PRINT((ndo, "msg "));
                        break;
                    case COS_CRYPTSER:
-                       (void)printf("crypt ");
+                       ND_PRINT((ndo, "crypt "));
                        break;
                    }
                    switch (info & COI_MASK) {
                    case COI_32:
-                       (void)printf("ver 3.2 ");
+                       ND_PRINT((ndo, "ver 3.2 "));
                        break;
                    case COI_31:
-                       (void)printf("ver 3.1 ");
+                       ND_PRINT((ndo, "ver 3.1 "));
                        break;
                    case COI_40:
-                       (void)printf("ver 4.0 ");
+                       ND_PRINT((ndo, "ver 4.0 "));
                        break;
                    case COI_41:
-                       (void)printf("ver 4.1 ");
+                       ND_PRINT((ndo, "ver 4.1 "));
                        break;
                    }
-                   (void)printf("segsize %d ", segsize);
+                   ND_PRINT((ndo, "segsize %d ", segsize));
 #ifdef PRINT_NSPDATA
                    if (nsplen > sizeof(struct cimsg)) {
                        dp = &(nspp[sizeof(struct cimsg)]);
-                       TCHECK2(*dp, nsplen - sizeof(struct cimsg));
-                       pdata(dp, nsplen - sizeof(struct cimsg));
+                       ND_TCHECK2(*dp, nsplen - sizeof(struct cimsg));
+                       pdata(ndo, dp, nsplen - sizeof(struct cimsg));
                    }
 #endif
                }
                break;
            case MFS_CC:
-               (void)printf("conn-confirm %d>%d ", src, dst);
+               ND_PRINT((ndo, "conn-confirm %d>%d ", src, dst));
                {
                    struct ccmsg *ccmp = (struct ccmsg *)nspp;
                    int services, info;
@@ -1152,7 +1160,7 @@ print_nsp(const u_char *nspp, u_int nsplen)
 
                    if (nsplen < sizeof(struct ccmsg))
                        goto trunc;
-                   TCHECK(*ccmp);
+                   ND_TCHECK(*ccmp);
                    services = EXTRACT_LE_8BITS(ccmp->cc_services);
                    info = EXTRACT_LE_8BITS(ccmp->cc_info);
                    segsize = EXTRACT_LE_16BITS(ccmp->cc_segsize);
@@ -1162,44 +1170,44 @@ print_nsp(const u_char *nspp, u_int nsplen)
                    case COS_NONE:
                        break;
                    case COS_SEGMENT:
-                       (void)printf("seg ");
+                       ND_PRINT((ndo, "seg "));
                        break;
                    case COS_MESSAGE:
-                       (void)printf("msg ");
+                       ND_PRINT((ndo, "msg "));
                        break;
                    case COS_CRYPTSER:
-                       (void)printf("crypt ");
+                       ND_PRINT((ndo, "crypt "));
                        break;
                    }
                    switch (info & COI_MASK) {
                    case COI_32:
-                       (void)printf("ver 3.2 ");
+                       ND_PRINT((ndo, "ver 3.2 "));
                        break;
                    case COI_31:
-                       (void)printf("ver 3.1 ");
+                       ND_PRINT((ndo, "ver 3.1 "));
                        break;
                    case COI_40:
-                       (void)printf("ver 4.0 ");
+                       ND_PRINT((ndo, "ver 4.0 "));
                        break;
                    case COI_41:
-                       (void)printf("ver 4.1 ");
+                       ND_PRINT((ndo, "ver 4.1 "));
                        break;
                    }
-                   (void)printf("segsize %d ", segsize);
+                   ND_PRINT((ndo, "segsize %d ", segsize));
                    if (optlen) {
-                       (void)printf("optlen %d ", optlen);
+                       ND_PRINT((ndo, "optlen %d ", optlen));
 #ifdef PRINT_NSPDATA
                        if (optlen > nsplen - sizeof(struct ccmsg))
                            goto trunc;
                        dp = &(nspp[sizeof(struct ccmsg)]);
-                       TCHECK2(*dp, optlen);
-                       pdata(dp, optlen);
+                       ND_TCHECK2(*dp, optlen);
+                       pdata(ndo, dp, optlen);
 #endif
                    }
                }
                break;
            case MFS_DI:
-               (void)printf("disconn-initiate %d>%d ", src, dst);
+               ND_PRINT((ndo, "disconn-initiate %d>%d ", src, dst));
                {
                    struct dimsg *dimp = (struct dimsg *)nspp;
                    int reason;
@@ -1210,42 +1218,42 @@ print_nsp(const u_char *nspp, u_int nsplen)
 
                    if (nsplen < sizeof(struct dimsg))
                        goto trunc;
-                   TCHECK(*dimp);
+                   ND_TCHECK(*dimp);
                    reason = EXTRACT_LE_16BITS(dimp->di_reason);
                    optlen = EXTRACT_LE_8BITS(dimp->di_optlen);
 
-                   print_reason(reason);
+                   print_reason(ndo, reason);
                    if (optlen) {
-                       (void)printf("optlen %d ", optlen);
+                       ND_PRINT((ndo, "optlen %d ", optlen));
 #ifdef PRINT_NSPDATA
                        if (optlen > nsplen - sizeof(struct dimsg))
                            goto trunc;
                        dp = &(nspp[sizeof(struct dimsg)]);
-                       TCHECK2(*dp, optlen);
-                       pdata(dp, optlen);
+                       ND_TCHECK2(*dp, optlen);
+                       pdata(ndo, dp, optlen);
 #endif
                    }
                }
                break;
            case MFS_DC:
-               (void)printf("disconn-confirm %d>%d ", src, dst);
+               ND_PRINT((ndo, "disconn-confirm %d>%d ", src, dst));
                {
                    struct dcmsg *dcmp = (struct dcmsg *)nspp;
                    int reason;
 
-                   TCHECK(*dcmp);
+                   ND_TCHECK(*dcmp);
                    reason = EXTRACT_LE_16BITS(dcmp->dc_reason);
 
-                   print_reason(reason);
+                   print_reason(ndo, reason);
                }
                break;
            default:
-               (void)printf("reserved-ctltype? %x %d > %d", flags, src, dst);
+               ND_PRINT((ndo, "reserved-ctltype? %x %d > %d", flags, src, dst));
                break;
            }
            break;
        default:
-           (void)printf("reserved-type? %x %d > %d", flags, src, dst);
+           ND_PRINT((ndo, "reserved-type? %x %d > %d", flags, src, dst));
            break;
        }
        return (1);
@@ -1281,9 +1289,10 @@ static const struct tok reason2str[] = {
 };
 
 static void
-print_reason(register int reason)
+print_reason(netdissect_options *ndo,
+             register int reason)
 {
-       printf("%s ", tok2str(reason2str, "reason-%d", reason));
+       ND_PRINT((ndo, "%s ", tok2str(reason2str, "reason-%d", reason)));
 }
 
 const char *
@@ -1317,14 +1326,15 @@ dnname_string(u_short dnaddr)
 
 #ifdef PRINT_NSPDATA
 static void
-pdata(u_char *dp, u_int maxlen)
+pdata(netdissect_options *ndo,
+      u_char *dp, u_int maxlen)
 {
        char c;
        u_int x = maxlen;
 
        while (x-- > 0) {
            c = *dp++;
-           safeputchar(gndo, c);
+           safeputchar(ndo, c);
        }
 }
 #endif
index 2bae5742f7e36d8fc74d46b3046c056a14b06a5f..057825dc7e5f6c3d6eb6e8bd2ef7a8f0be4de2da 100644 (file)
@@ -336,7 +336,7 @@ ethertype_print(netdissect_options *ndo,
                return (1);
 
        case ETHERTYPE_DN:
-               decnet_print(/*ndo,*/p, length, caplen);
+               decnet_print(ndo, p, length, caplen);
                return (1);
 
        case ETHERTYPE_ATALK:
index 252584da4123c9e1aac26679b9cd3236d1ecf78a..597f08b8ca26c4ff7b22e6b9b0811608d1b47a1b 100644 (file)
@@ -374,7 +374,7 @@ again:
 
        case IPPROTO_TCP:
                /* pass on the MF bit plus the offset to detect fragments */
-               tcp_print(ipds->cp, ipds->len, (const u_char *)ipds->ip,
+               tcp_print(ndo, ipds->cp, ipds->len, (const u_char *)ipds->ip,
                          ipds->off & (IP_MF|IP_OFFMASK));
                break;
 
@@ -420,7 +420,7 @@ again:
                break;
 
        case IPPROTO_OSPF:
-               ospf_print(ipds->cp, ipds->len, (const u_char *)ipds->ip);
+               ospf_print(ndo, ipds->cp, ipds->len, (const u_char *)ipds->ip);
                break;
 
        case IPPROTO_IGMP:
index 3a7b869582303d3b9b0d525cba2ecc1cf4928917..5ca63c008b5e1d48d5126ad7d89b94bef598d516 100644 (file)
@@ -194,7 +194,7 @@ ip6_print(netdissect_options *ndo, const u_char *bp, u_int length)
                        dccp_print(ndo, cp, (const u_char *)ip6, len);
                        return;
                case IPPROTO_TCP:
-                       tcp_print(cp, len, (const u_char *)ip6, fragmented);
+                       tcp_print(ndo, cp, len, (const u_char *)ip6, fragmented);
                        return;
                case IPPROTO_UDP:
                        udp_print(ndo, cp, len, (const u_char *)ip6, fragmented);
index b36a61b5f71931d79959b3a58646de5e0ac3b710..a6bd6c311ed2b96662a6820475dd2b7f13d7a052 100644 (file)
  * OSPF support contributed by Jeffrey Honig ([email protected])
  */
 
+#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"
@@ -36,8 +35,6 @@
 
 #include "ospf.h"
 
-#include "ip.h"
-
 static const char tstr[] = " [|ospf2]";
 
 static const struct tok ospf_option_values[] = {
@@ -182,21 +179,17 @@ static const struct tok ospf_lls_eo_options[] = {
        { 0,    NULL }
 };
 
-static int ospf_print_lshdr(const struct lsa_hdr *);
-static const u_char *ospf_print_lsa(const struct lsa *);
-static int ospf_decode_v2(const struct ospfhdr *, const u_char *);
-static int ospf_decode_lls(const struct ospfhdr *, register u_int);
-
 int
-ospf_print_grace_lsa (const u_int8_t *tptr, u_int ls_length) {
+ospf_print_grace_lsa(netdissect_options *ndo,
+                     const u_int8_t *tptr, u_int ls_length) {
 
     u_int tlv_type, tlv_length;
 
 
     while (ls_length > 0) {
-        TCHECK2(*tptr, 4);
+        ND_TCHECK2(*tptr, 4);
         if (ls_length < 4) {
-            printf("\n\t    Remaining LS length %u < 4", ls_length);
+            ND_PRINT((ndo, "\n\t    Remaining LS length %u < 4", ls_length));
             return -1;
         }
         tlv_type = EXTRACT_16BITS(tptr);
@@ -204,14 +197,14 @@ ospf_print_grace_lsa (const u_int8_t *tptr, u_int ls_length) {
         tptr+=4;
         ls_length-=4;
 
-        printf("\n\t    %s TLV (%u), length %u, value: ",
+        ND_PRINT((ndo, "\n\t    %s TLV (%u), length %u, value: ",
                tok2str(lsa_opaque_grace_tlv_values,"unknown",tlv_type),
                tlv_type,
-               tlv_length);
+               tlv_length));
 
         if (tlv_length > ls_length) {
-            printf("\n\t    Bogus length %u > %u", tlv_length,
-                   ls_length);
+            ND_PRINT((ndo, "\n\t    Bogus length %u > %u", tlv_length,
+                   ls_length));
             return -1;
         }
 
@@ -220,38 +213,38 @@ ospf_print_grace_lsa (const u_int8_t *tptr, u_int ls_length) {
             return -1;
         }
 
-        TCHECK2(*tptr, tlv_length);
+        ND_TCHECK2(*tptr, tlv_length);
         switch(tlv_type) {
 
         case LS_OPAQUE_GRACE_TLV_PERIOD:
             if (tlv_length != 4) {
-                printf("\n\t    Bogus length %u != 4", tlv_length);
+                ND_PRINT((ndo, "\n\t    Bogus length %u != 4", tlv_length));
                 return -1;
             }
-            printf("%us",EXTRACT_32BITS(tptr));
+            ND_PRINT((ndo, "%us", EXTRACT_32BITS(tptr)));
             break;
 
         case LS_OPAQUE_GRACE_TLV_REASON:
             if (tlv_length != 1) {
-                printf("\n\t    Bogus length %u != 1", tlv_length);
+                ND_PRINT((ndo, "\n\t    Bogus length %u != 1", tlv_length));
                 return -1;
             }
-            printf("%s (%u)",
+            ND_PRINT((ndo, "%s (%u)",
                    tok2str(lsa_opaque_grace_tlv_reason_values, "Unknown", *tptr),
-                   *tptr);
+                   *tptr));
             break;
 
         case LS_OPAQUE_GRACE_TLV_INT_ADDRESS:
             if (tlv_length != 4) {
-                printf("\n\t    Bogus length %u != 4", tlv_length);
+                ND_PRINT((ndo, "\n\t    Bogus length %u != 4", tlv_length));
                 return -1;
             }
-            printf("%s", ipaddr_string(tptr));
+            ND_PRINT((ndo, "%s", ipaddr_string(tptr)));
             break;
 
         default:
-            if (vflag <= 1) {
-                if(!print_unknown_data(gndo,tptr,"\n\t      ",tlv_length))
+            if (ndo->ndo_vflag <= 1) {
+                if (!print_unknown_data(ndo, tptr, "\n\t      ", tlv_length))
                     return -1;
             }
             break;
@@ -270,7 +263,8 @@ trunc:
 }
 
 int
-ospf_print_te_lsa (const u_int8_t *tptr, u_int ls_length) {
+ospf_print_te_lsa(netdissect_options *ndo,
+                  const u_int8_t *tptr, u_int ls_length) {
 
     u_int tlv_type, tlv_length, subtlv_type, subtlv_length;
     u_int priority_level, te_class, count_srlg;
@@ -280,9 +274,9 @@ ospf_print_te_lsa (const u_int8_t *tptr, u_int ls_length) {
     } bw;
 
     while (ls_length != 0) {
-        TCHECK2(*tptr, 4);
+        ND_TCHECK2(*tptr, 4);
         if (ls_length < 4) {
-            printf("\n\t    Remaining LS length %u < 4", ls_length);
+            ND_PRINT((ndo, "\n\t    Remaining LS length %u < 4", ls_length));
             return -1;
         }
         tlv_type = EXTRACT_16BITS(tptr);
@@ -290,14 +284,14 @@ ospf_print_te_lsa (const u_int8_t *tptr, u_int ls_length) {
         tptr+=4;
         ls_length-=4;
 
-        printf("\n\t    %s TLV (%u), length: %u",
+        ND_PRINT((ndo, "\n\t    %s TLV (%u), length: %u",
                tok2str(lsa_opaque_te_tlv_values,"unknown",tlv_type),
                tlv_type,
-               tlv_length);
+               tlv_length));
 
         if (tlv_length > ls_length) {
-            printf("\n\t    Bogus length %u > %u", tlv_length,
-                   ls_length);
+            ND_PRINT((ndo, "\n\t    Bogus length %u > %u", tlv_length,
+                   ls_length));
             return -1;
         }
 
@@ -310,108 +304,108 @@ ospf_print_te_lsa (const u_int8_t *tptr, u_int ls_length) {
         case LS_OPAQUE_TE_TLV_LINK:
             while (tlv_length >= sizeof(subtlv_type) + sizeof(subtlv_length)) {
                 if (tlv_length < 4) {
-                    printf("\n\t    Remaining TLV length %u < 4",
-                           tlv_length);
+                    ND_PRINT((ndo, "\n\t    Remaining TLV length %u < 4",
+                           tlv_length));
                     return -1;
                 }
-                TCHECK2(*tptr, 4);
+                ND_TCHECK2(*tptr, 4);
                 subtlv_type = EXTRACT_16BITS(tptr);
                 subtlv_length = EXTRACT_16BITS(tptr+2);
                 tptr+=4;
                 tlv_length-=4;
 
-                printf("\n\t      %s subTLV (%u), length: %u",
+                ND_PRINT((ndo, "\n\t      %s subTLV (%u), length: %u",
                        tok2str(lsa_opaque_te_link_tlv_subtlv_values,"unknown",subtlv_type),
                        subtlv_type,
-                       subtlv_length);
+                       subtlv_length));
 
-                TCHECK2(*tptr, subtlv_length);
+                ND_TCHECK2(*tptr, subtlv_length);
                 switch(subtlv_type) {
                 case LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP:
-                    printf(", 0x%08x", EXTRACT_32BITS(tptr));
+                    ND_PRINT((ndo, ", 0x%08x", EXTRACT_32BITS(tptr)));
                     break;
                 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID:
                 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID:
-                    printf(", %s (0x%08x)",
+                    ND_PRINT((ndo, ", %s (0x%08x)",
                            ipaddr_string(tptr),
-                           EXTRACT_32BITS(tptr));
+                           EXTRACT_32BITS(tptr)));
                     if (subtlv_length == 8) /* rfc4203 */
-                        printf(", %s (0x%08x)",
+                        ND_PRINT((ndo, ", %s (0x%08x)",
                                ipaddr_string(tptr+4),
-                               EXTRACT_32BITS(tptr+4));
+                               EXTRACT_32BITS(tptr + 4)));
                     break;
                 case LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP:
                 case LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP:
-                    printf(", %s", ipaddr_string(tptr));
+                    ND_PRINT((ndo, ", %s", ipaddr_string(tptr)));
                     break;
                 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW:
                 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW:
                     bw.i = EXTRACT_32BITS(tptr);
-                    printf(", %.3f Mbps", bw.f*8/1000000 );
+                    ND_PRINT((ndo, ", %.3f Mbps", bw.f * 8 / 1000000));
                     break;
                 case LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW:
                     for (te_class = 0; te_class < 8; te_class++) {
                         bw.i = EXTRACT_32BITS(tptr+te_class*4);
-                        printf("\n\t\tTE-Class %u: %.3f Mbps",
+                        ND_PRINT((ndo, "\n\t\tTE-Class %u: %.3f Mbps",
                                te_class,
-                               bw.f*8/1000000 );
+                               bw.f * 8 / 1000000));
                     }
                     break;
                 case LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS:
-                    printf("\n\t\tBandwidth Constraints Model ID: %s (%u)",
+                    ND_PRINT((ndo, "\n\t\tBandwidth Constraints Model ID: %s (%u)",
                            tok2str(diffserv_te_bc_values, "unknown", *tptr),
-                           *tptr);
+                           *tptr));
                     /* decode BCs until the subTLV ends */
                     for (te_class = 0; te_class < (subtlv_length-4)/4; te_class++) {
                         bw.i = EXTRACT_32BITS(tptr+4+te_class*4);
-                        printf("\n\t\t  Bandwidth constraint CT%u: %.3f Mbps",
+                        ND_PRINT((ndo, "\n\t\t  Bandwidth constraint CT%u: %.3f Mbps",
                                te_class,
-                               bw.f*8/1000000 );
+                               bw.f * 8 / 1000000));
                     }
                     break;
                 case LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC:
-                    printf(", Metric %u", EXTRACT_32BITS(tptr));
+                    ND_PRINT((ndo, ", Metric %u", EXTRACT_32BITS(tptr)));
                     break;
                 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE:
-                    printf(", %s, Priority %u",
+                    ND_PRINT((ndo, ", %s, Priority %u",
                            bittok2str(gmpls_link_prot_values, "none", *tptr),
-                           *(tptr+1));
+                           *(tptr + 1)));
                     break;
                 case LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR:
-                    printf("\n\t\tInterface Switching Capability: %s",
-                           tok2str(gmpls_switch_cap_values, "Unknown", *(tptr)));
-                    printf("\n\t\tLSP Encoding: %s\n\t\tMax LSP Bandwidth:",
-                           tok2str(gmpls_encoding_values, "Unknown", *(tptr+1)));
+                    ND_PRINT((ndo, "\n\t\tInterface Switching Capability: %s",
+                           tok2str(gmpls_switch_cap_values, "Unknown", *(tptr))));
+                    ND_PRINT((ndo, "\n\t\tLSP Encoding: %s\n\t\tMax LSP Bandwidth:",
+                           tok2str(gmpls_encoding_values, "Unknown", *(tptr + 1))));
                     for (priority_level = 0; priority_level < 8; priority_level++) {
                         bw.i = EXTRACT_32BITS(tptr+4+(priority_level*4));
-                        printf("\n\t\t  priority level %d: %.3f Mbps",
+                        ND_PRINT((ndo, "\n\t\t  priority level %d: %.3f Mbps",
                                priority_level,
-                               bw.f*8/1000000 );
+                               bw.f * 8 / 1000000));
                     }
                     break;
                 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE:
-                    printf(", %s (%u)",
+                    ND_PRINT((ndo, ", %s (%u)",
                            tok2str(lsa_opaque_te_tlv_link_type_sub_tlv_values,"unknown",*tptr),
-                           *tptr);
+                           *tptr));
                     break;
 
                 case LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP:
                     count_srlg = subtlv_length / 4;
                     if (count_srlg != 0)
-                        printf("\n\t\t  Shared risk group: ");
+                        ND_PRINT((ndo, "\n\t\t  Shared risk group: "));
                     while (count_srlg > 0) {
                         bw.i = EXTRACT_32BITS(tptr);
-                        printf("%d",bw.i);
+                        ND_PRINT((ndo, "%d", bw.i));
                         tptr+=4;
                         count_srlg--;
                         if (count_srlg > 0)
-                            printf(", ");
+                            ND_PRINT((ndo, ", "));
                     }
                     break;
 
                 default:
-                    if (vflag <= 1) {
-                        if(!print_unknown_data(gndo,tptr,"\n\t\t",subtlv_length))
+                    if (ndo->ndo_vflag <= 1) {
+                        if (!print_unknown_data(ndo, tptr, "\n\t\t", subtlv_length))
                             return -1;
                     }
                     break;
@@ -428,16 +422,16 @@ ospf_print_te_lsa (const u_int8_t *tptr, u_int ls_length) {
 
         case LS_OPAQUE_TE_TLV_ROUTER:
             if (tlv_length < 4) {
-                printf("\n\t    TLV length %u < 4", tlv_length);
+                ND_PRINT((ndo, "\n\t    TLV length %u < 4", tlv_length));
                 return -1;
             }
-            TCHECK2(*tptr, 4);
-            printf(", %s", ipaddr_string(tptr));
+            ND_TCHECK2(*tptr, 4);
+            ND_PRINT((ndo, ", %s", ipaddr_string(tptr)));
             break;
 
         default:
-            if (vflag <= 1) {
-                if(!print_unknown_data(gndo,tptr,"\n\t      ",tlv_length))
+            if (ndo->ndo_vflag <= 1) {
+                if (!print_unknown_data(ndo, tptr, "\n\t      ", tlv_length))
                     return -1;
             }
             break;
@@ -453,34 +447,34 @@ trunc:
     return -1;
 }
 
-
 static int
-ospf_print_lshdr(register const struct lsa_hdr *lshp)
+ospf_print_lshdr(netdissect_options *ndo,
+                 register const struct lsa_hdr *lshp)
 {
         u_int ls_length;
 
-        TCHECK(lshp->ls_length);
+        ND_TCHECK(lshp->ls_length);
         ls_length = EXTRACT_16BITS(&lshp->ls_length);
         if (ls_length < sizeof(struct lsa_hdr)) {
-                printf("\n\t    Bogus length %u < header (%lu)", ls_length,
-                    (unsigned long)sizeof(struct lsa_hdr));
+                ND_PRINT((ndo, "\n\t    Bogus length %u < header (%lu)", ls_length,
+                    (unsigned long)sizeof(struct lsa_hdr)));
                 return(-1);
         }
 
-        TCHECK(lshp->ls_seq);  /* XXX - ls_length check checked this */
-       printf("\n\t  Advertising Router %s, seq 0x%08x, age %us, length %u",
-              ipaddr_string(&lshp->ls_router),
-              EXTRACT_32BITS(&lshp->ls_seq),
-              EXTRACT_16BITS(&lshp->ls_age),
-               ls_length-(u_int)sizeof(struct lsa_hdr));
+        ND_TCHECK(lshp->ls_seq); /* XXX - ls_length check checked this */
+        ND_PRINT((ndo, "\n\t  Advertising Router %s, seq 0x%08x, age %us, length %u",
+                  ipaddr_string(&lshp->ls_router),
+                  EXTRACT_32BITS(&lshp->ls_seq),
+                  EXTRACT_16BITS(&lshp->ls_age),
+                  ls_length - (u_int)sizeof(struct lsa_hdr)));
 
-       TCHECK(lshp->ls_type);  /* XXX - ls_length check checked this */
+        ND_TCHECK(lshp->ls_type); /* XXX - ls_length check checked this */
         switch (lshp->ls_type) {
-       /* the LSA header for opaque LSAs was slightly changed */
+        /* the LSA header for opaque LSAs was slightly changed */
         case LS_TYPE_OPAQUE_LL:
         case LS_TYPE_OPAQUE_AL:
         case LS_TYPE_OPAQUE_DW:
-            printf("\n\t    %s LSA (%d), Opaque-Type %s LSA (%u), Opaque-ID %u",
+            ND_PRINT((ndo, "\n\t    %s LSA (%d), Opaque-Type %s LSA (%u), Opaque-ID %u",
                    tok2str(lsa_values,"unknown",lshp->ls_type),
                    lshp->ls_type,
 
@@ -490,20 +484,20 @@ ospf_print_lshdr(register const struct lsa_hdr *lshp)
                   *(&lshp->un_lsa_id.opaque_field.opaque_type),
                   EXTRACT_24BITS(&lshp->un_lsa_id.opaque_field.opaque_id)
 
-                   );
+                   ));
             break;
 
-       /* all other LSA types use regular style LSA headers */
-       default:
-            printf("\n\t    %s LSA (%d), LSA-ID: %s",
+        /* all other LSA types use regular style LSA headers */
+        default:
+            ND_PRINT((ndo, "\n\t    %s LSA (%d), LSA-ID: %s",
                    tok2str(lsa_values,"unknown",lshp->ls_type),
                    lshp->ls_type,
-                   ipaddr_string(&lshp->un_lsa_id.lsa_id));
+                   ipaddr_string(&lshp->un_lsa_id.lsa_id)));
             break;
         }
 
-       TCHECK(lshp->ls_options);       /* XXX - ls_length check checked this */
-        printf("\n\t    Options: [%s]", bittok2str(ospf_option_values,"none",lshp->ls_options));
+        ND_TCHECK(lshp->ls_options); /* XXX - ls_length check checked this */
+        ND_PRINT((ndo, "\n\t    Options: [%s]", bittok2str(ospf_option_values, "none", lshp->ls_options)));
 
         return (ls_length);
 trunc:
@@ -522,7 +516,8 @@ static const struct tok ospf_topology_values[] = {
  * Print all the per-topology metrics.
  */
 static void
-ospf_print_tos_metrics(const union un_tos *tos)
+ospf_print_tos_metrics(netdissect_options *ndo,
+                       const union un_tos *tos)
 {
     int metric_count;
     int toscount;
@@ -534,11 +529,11 @@ ospf_print_tos_metrics(const union un_tos *tos)
      * All but the first metric contain a valid topology id.
      */
     while (toscount) {
-        printf("\n\t\ttopology %s(%u), metric %u",
+        ND_PRINT((ndo, "\n\t\ttopology %s(%u), metric %u",
                tok2str(ospf_topology_values, "",
                        metric_count ? tos->metrics.tos_type : 0),
                metric_count ? tos->metrics.tos_type : 0,
-               EXTRACT_16BITS(&tos->metrics.tos_metric));
+               EXTRACT_16BITS(&tos->metrics.tos_metric)));
         metric_count++;
         tos++;
         toscount--;
@@ -551,7 +546,8 @@ ospf_print_tos_metrics(const union un_tos *tos)
  * return pointer to data past end of LSA.
  */
 static const u_int8_t *
-ospf_print_lsa(register const struct lsa *lsap)
+ospf_print_lsa(netdissect_options *ndo,
+               register const struct lsa *lsap)
 {
        register const u_int8_t *ls_end;
        register const struct rlalink *rlp;
@@ -564,7 +560,7 @@ ospf_print_lsa(register const struct lsa *lsap)
        const u_int8_t *tptr;
 
        tptr = (u_int8_t *)lsap->lsa_un.un_unknown; /* squelch compiler warnings */
-        ls_length = ospf_print_lshdr(&lsap->ls_hdr);
+        ls_length = ospf_print_lshdr(ndo, &lsap->ls_hdr);
         if (ls_length == -1)
                 return(NULL);
        ls_end = (u_int8_t *)lsap + ls_length;
@@ -573,48 +569,49 @@ ospf_print_lsa(register const struct lsa *lsap)
        switch (lsap->ls_hdr.ls_type) {
 
        case LS_TYPE_ROUTER:
-               TCHECK(lsap->lsa_un.un_rla.rla_flags);
-                printf("\n\t    Router LSA Options: [%s]", bittok2str(ospf_rla_flag_values,"none",lsap->lsa_un.un_rla.rla_flags));
+               ND_TCHECK(lsap->lsa_un.un_rla.rla_flags);
+               ND_PRINT((ndo, "\n\t    Router LSA Options: [%s]",
+                         bittok2str(ospf_rla_flag_values, "none", lsap->lsa_un.un_rla.rla_flags)));
 
-               TCHECK(lsap->lsa_un.un_rla.rla_count);
+               ND_TCHECK(lsap->lsa_un.un_rla.rla_count);
                j = EXTRACT_16BITS(&lsap->lsa_un.un_rla.rla_count);
-               TCHECK(lsap->lsa_un.un_rla.rla_link);
+               ND_TCHECK(lsap->lsa_un.un_rla.rla_link);
                rlp = lsap->lsa_un.un_rla.rla_link;
                while (j--) {
-                       TCHECK(*rlp);
+                       ND_TCHECK(*rlp);
                        switch (rlp->un_tos.link.link_type) {
 
                        case RLA_TYPE_VIRTUAL:
-                               printf("\n\t      Virtual Link: Neighbor Router-ID: %s, Interface Address: %s",
+                               ND_PRINT((ndo, "\n\t      Virtual Link: Neighbor Router-ID: %s, Interface Address: %s",
                                    ipaddr_string(&rlp->link_id),
-                                   ipaddr_string(&rlp->link_data));
-                                break;
+                                   ipaddr_string(&rlp->link_data)));
+                               break;
 
                        case RLA_TYPE_ROUTER:
-                               printf("\n\t      Neighbor Router-ID: %s, Interface Address: %s",
+                               ND_PRINT((ndo, "\n\t      Neighbor Router-ID: %s, Interface Address: %s",
                                    ipaddr_string(&rlp->link_id),
-                                   ipaddr_string(&rlp->link_data));
+                                   ipaddr_string(&rlp->link_data)));
                                break;
 
                        case RLA_TYPE_TRANSIT:
-                               printf("\n\t      Neighbor Network-ID: %s, Interface Address: %s",
+                               ND_PRINT((ndo, "\n\t      Neighbor Network-ID: %s, Interface Address: %s",
                                    ipaddr_string(&rlp->link_id),
-                                   ipaddr_string(&rlp->link_data));
+                                   ipaddr_string(&rlp->link_data)));
                                break;
 
                        case RLA_TYPE_STUB:
-                               printf("\n\t      Stub Network: %s, Mask: %s",
+                               ND_PRINT((ndo, "\n\t      Stub Network: %s, Mask: %s",
                                    ipaddr_string(&rlp->link_id),
-                                   ipaddr_string(&rlp->link_data));
+                                   ipaddr_string(&rlp->link_data)));
                                break;
 
                        default:
-                               printf("\n\t      Unknown Router Link Type (%u)",
-                                   rlp->un_tos.link.link_type);
+                               ND_PRINT((ndo, "\n\t      Unknown Router Link Type (%u)",
+                                   rlp->un_tos.link.link_type));
                                return (ls_end);
                        }
 
-                        ospf_print_tos_metrics(&rlp->un_tos);
+                       ospf_print_tos_metrics(ndo, &rlp->un_tos);
 
                        rlp = (struct rlalink *)((u_char *)(rlp + 1) +
                            ((rlp->un_tos.link.link_tos_count) * sizeof(union un_tos)));
@@ -622,86 +619,84 @@ ospf_print_lsa(register const struct lsa *lsap)
                break;
 
        case LS_TYPE_NETWORK:
-               TCHECK(lsap->lsa_un.un_nla.nla_mask);
-               printf("\n\t    Mask %s\n\t    Connected Routers:",
-                   ipaddr_string(&lsap->lsa_un.un_nla.nla_mask));
+               ND_TCHECK(lsap->lsa_un.un_nla.nla_mask);
+               ND_PRINT((ndo, "\n\t    Mask %s\n\t    Connected Routers:",
+                   ipaddr_string(&lsap->lsa_un.un_nla.nla_mask)));
                ap = lsap->lsa_un.un_nla.nla_router;
                while ((u_char *)ap < ls_end) {
-                       TCHECK(*ap);
-                       printf("\n\t      %s", ipaddr_string(ap));
+                       ND_TCHECK(*ap);
+                       ND_PRINT((ndo, "\n\t      %s", ipaddr_string(ap)));
                        ++ap;
                }
                break;
 
        case LS_TYPE_SUM_IP:
-               TCHECK(lsap->lsa_un.un_nla.nla_mask);
-               printf("\n\t    Mask %s",
-                   ipaddr_string(&lsap->lsa_un.un_sla.sla_mask));
-               TCHECK(lsap->lsa_un.un_sla.sla_tosmetric);
+               ND_TCHECK(lsap->lsa_un.un_nla.nla_mask);
+               ND_PRINT((ndo, "\n\t    Mask %s",
+                   ipaddr_string(&lsap->lsa_un.un_sla.sla_mask)));
+               ND_TCHECK(lsap->lsa_un.un_sla.sla_tosmetric);
                lp = lsap->lsa_un.un_sla.sla_tosmetric;
                while ((u_char *)lp < ls_end) {
                        register u_int32_t ul;
 
-                       TCHECK(*lp);
+                       ND_TCHECK(*lp);
                        ul = EXTRACT_32BITS(lp);
                         topology = (ul & SLA_MASK_TOS) >> SLA_SHIFT_TOS;
-                       printf("\n\t\ttopology %s(%u) metric %d",
+                       ND_PRINT((ndo, "\n\t\ttopology %s(%u) metric %d",
                                tok2str(ospf_topology_values, "", topology),
                                topology,
-                               ul & SLA_MASK_METRIC);
+                               ul & SLA_MASK_METRIC));
                        ++lp;
                }
                break;
 
        case LS_TYPE_SUM_ABR:
-               TCHECK(lsap->lsa_un.un_sla.sla_tosmetric);
+               ND_TCHECK(lsap->lsa_un.un_sla.sla_tosmetric);
                lp = lsap->lsa_un.un_sla.sla_tosmetric;
                while ((u_char *)lp < ls_end) {
                        register u_int32_t ul;
 
-                       TCHECK(*lp);
+                       ND_TCHECK(*lp);
                        ul = EXTRACT_32BITS(lp);
                         topology = (ul & SLA_MASK_TOS) >> SLA_SHIFT_TOS;
-                       printf("\n\t\ttopology %s(%u) metric %d",
+                       ND_PRINT((ndo, "\n\t\ttopology %s(%u) metric %d",
                                tok2str(ospf_topology_values, "", topology),
                                topology,
-                               ul & SLA_MASK_METRIC);
+                               ul & SLA_MASK_METRIC));
                        ++lp;
                }
                break;
 
        case LS_TYPE_ASE:
         case LS_TYPE_NSSA: /* fall through - those LSAs share the same format */
-               TCHECK(lsap->lsa_un.un_nla.nla_mask);
-               printf("\n\t    Mask %s",
-                   ipaddr_string(&lsap->lsa_un.un_asla.asla_mask));
+               ND_TCHECK(lsap->lsa_un.un_nla.nla_mask);
+               ND_PRINT((ndo, "\n\t    Mask %s",
+                   ipaddr_string(&lsap->lsa_un.un_asla.asla_mask)));
 
-               TCHECK(lsap->lsa_un.un_sla.sla_tosmetric);
+               ND_TCHECK(lsap->lsa_un.un_sla.sla_tosmetric);
                almp = lsap->lsa_un.un_asla.asla_metric;
                while ((u_char *)almp < ls_end) {
                        register u_int32_t ul;
 
-                       TCHECK(almp->asla_tosmetric);
+                       ND_TCHECK(almp->asla_tosmetric);
                        ul = EXTRACT_32BITS(&almp->asla_tosmetric);
                         topology = ((ul & ASLA_MASK_TOS) >> ASLA_SHIFT_TOS);
-                       printf("\n\t\ttopology %s(%u), type %d, metric",
+                       ND_PRINT((ndo, "\n\t\ttopology %s(%u), type %d, metric",
                                tok2str(ospf_topology_values, "", topology),
                                topology,
-                               (ul & ASLA_FLAG_EXTERNAL) ? 2 : 1);
-                        if ((ul & ASLA_MASK_METRIC)==0xffffff)
-                            printf(" infinite");
-                        else
-                            printf(" %d", (ul & ASLA_MASK_METRIC));
+                               (ul & ASLA_FLAG_EXTERNAL) ? 2 : 1));
+                       if ((ul & ASLA_MASK_METRIC) == 0xffffff)
+                               ND_PRINT((ndo, " infinite"));
+                       else
+                               ND_PRINT((ndo, " %d", (ul & ASLA_MASK_METRIC)));
 
-                       TCHECK(almp->asla_forward);
+                       ND_TCHECK(almp->asla_forward);
                        if (almp->asla_forward.s_addr) {
-                               printf(", forward %s",
-                                   ipaddr_string(&almp->asla_forward));
+                               ND_PRINT((ndo, ", forward %s", ipaddr_string(&almp->asla_forward)));
                        }
-                       TCHECK(almp->asla_tag);
+                       ND_TCHECK(almp->asla_tag);
                        if (almp->asla_tag.s_addr) {
-                               printf(", tag %s",
-                                   ipaddr_string(&almp->asla_tag));
+                               ND_PRINT((ndo, ", tag %s", ipaddr_string(&almp->asla_tag)));
                        }
                        ++almp;
                }
@@ -711,22 +706,22 @@ ospf_print_lsa(register const struct lsa *lsap)
                /* Multicast extensions as of 23 July 1991 */
                mcp = lsap->lsa_un.un_mcla;
                while ((u_char *)mcp < ls_end) {
-                       TCHECK(mcp->mcla_vid);
+                       ND_TCHECK(mcp->mcla_vid);
                        switch (EXTRACT_32BITS(&mcp->mcla_vtype)) {
 
                        case MCLA_VERTEX_ROUTER:
-                               printf("\n\t    Router Router-ID %s",
-                                   ipaddr_string(&mcp->mcla_vid));
+                               ND_PRINT((ndo, "\n\t    Router Router-ID %s",
+                                   ipaddr_string(&mcp->mcla_vid)));
                                break;
 
                        case MCLA_VERTEX_NETWORK:
-                               printf("\n\t    Network Designated Router %s",
-                                   ipaddr_string(&mcp->mcla_vid));
+                               ND_PRINT((ndo, "\n\t    Network Designated Router %s",
+                                   ipaddr_string(&mcp->mcla_vid)));
                                break;
 
                        default:
-                               printf("\n\t    unknown VertexType (%u)",
-                                   EXTRACT_32BITS(&mcp->mcla_vtype));
+                               ND_PRINT((ndo, "\n\t    unknown VertexType (%u)",
+                                   EXTRACT_32BITS(&mcp->mcla_vtype)));
                                break;
                        }
                ++mcp;
@@ -742,9 +737,9 @@ ospf_print_lsa(register const struct lsa *lsap)
                tptr = (u_int8_t *)(&lsap->lsa_un.un_ri_tlv.type);
 
                while (ls_length != 0) {
-                    TCHECK2(*tptr, 4);
+                    ND_TCHECK2(*tptr, 4);
                    if (ls_length < 4) {
-                        printf("\n\t    Remaining LS length %u < 4", ls_length);
+                        ND_PRINT((ndo, "\n\t    Remaining LS length %u < 4", ls_length));
                         return(ls_end);
                     }
                     tlv_type = EXTRACT_16BITS(tptr);
@@ -752,30 +747,30 @@ ospf_print_lsa(register const struct lsa *lsap)
                     tptr+=4;
                     ls_length-=4;
 
-                    printf("\n\t    %s TLV (%u), length: %u, value: ",
+                    ND_PRINT((ndo, "\n\t    %s TLV (%u), length: %u, value: ",
                            tok2str(lsa_opaque_ri_tlv_values,"unknown",tlv_type),
                            tlv_type,
-                           tlv_length);
+                           tlv_length));
 
                     if (tlv_length > ls_length) {
-                        printf("\n\t    Bogus length %u > %u", tlv_length,
-                            ls_length);
+                        ND_PRINT((ndo, "\n\t    Bogus length %u > %u", tlv_length,
+                            ls_length));
                         return(ls_end);
                     }
-                    TCHECK2(*tptr, tlv_length);
+                    ND_TCHECK2(*tptr, tlv_length);
                     switch(tlv_type) {
 
                     case LS_OPAQUE_RI_TLV_CAP:
                         if (tlv_length != 4) {
-                            printf("\n\t    Bogus length %u != 4", tlv_length);
+                            ND_PRINT((ndo, "\n\t    Bogus length %u != 4", tlv_length));
                             return(ls_end);
                         }
-                        printf("Capabilities: %s",
-                               bittok2str(lsa_opaque_ri_tlv_cap_values, "Unknown", EXTRACT_32BITS(tptr)));
+                        ND_PRINT((ndo, "Capabilities: %s",
+                               bittok2str(lsa_opaque_ri_tlv_cap_values, "Unknown", EXTRACT_32BITS(tptr))));
                         break;
                     default:
-                        if (vflag <= 1) {
-                            if(!print_unknown_data(gndo,tptr,"\n\t      ",tlv_length))
+                        if (ndo->ndo_vflag <= 1) {
+                            if (!print_unknown_data(ndo, tptr, "\n\t      ", tlv_length))
                                 return(ls_end);
                         }
                         break;
@@ -787,22 +782,22 @@ ospf_print_lsa(register const struct lsa *lsap)
                 break;
 
             case LS_OPAQUE_TYPE_GRACE:
-                if (ospf_print_grace_lsa((u_int8_t *)(&lsap->lsa_un.un_grace_tlv.type),
+                if (ospf_print_grace_lsa(ndo, (u_int8_t *)(&lsap->lsa_un.un_grace_tlv.type),
                                          ls_length) == -1) {
                     return(ls_end);
                 }
                 break;
 
            case LS_OPAQUE_TYPE_TE:
-                if (ospf_print_te_lsa((u_int8_t *)(&lsap->lsa_un.un_te_lsa_tlv.type),
+                if (ospf_print_te_lsa(ndo, (u_int8_t *)(&lsap->lsa_un.un_te_lsa_tlv.type),
                                       ls_length) == -1) {
                     return(ls_end);
                 }
                 break;
 
             default:
-                if (vflag <= 1) {
-                    if(!print_unknown_data(gndo,(u_int8_t *)lsap->lsa_un.un_unknown,
+                if (ndo->ndo_vflag <= 1) {
+                    if (!print_unknown_data(ndo, (u_int8_t *)lsap->lsa_un.un_unknown,
                                            "\n\t    ", ls_length))
                         return(ls_end);
                 }
@@ -811,8 +806,8 @@ ospf_print_lsa(register const struct lsa *lsap)
         }
 
         /* do we want to see an additionally hexdump ? */
-        if (vflag> 1)
-            if(!print_unknown_data(gndo,(u_int8_t *)lsap->lsa_un.un_unknown,
+        if (ndo->ndo_vflag> 1)
+            if (!print_unknown_data(ndo, (u_int8_t *)lsap->lsa_un.un_unknown,
                                    "\n\t    ", ls_length)) {
                 return(ls_end);
             }
@@ -823,8 +818,8 @@ trunc:
 }
 
 static int
-ospf_decode_lls(register const struct ospfhdr *op,
-               register u_int length)
+ospf_decode_lls(netdissect_options *ndo,
+                register const struct ospfhdr *op, register u_int length)
 {
     register const u_char *dptr;
     register const u_char *dataend;
@@ -858,51 +853,51 @@ ospf_decode_lls(register const struct ospfhdr *op,
         length2 += op->ospf_authdata[3];
     }
     if (length2 >= length) {
-        printf("\n\t[LLS truncated]");
+        ND_PRINT((ndo, "\n\t[LLS truncated]"));
         return (1);
     }
-    TCHECK2(*dptr, 2);
-    printf("\n\t  LLS: checksum: 0x%04x", (u_int)EXTRACT_16BITS(dptr));
+    ND_TCHECK2(*dptr, 2);
+    ND_PRINT((ndo, "\n\t  LLS: checksum: 0x%04x", (u_int)EXTRACT_16BITS(dptr)));
 
     dptr += 2;
-    TCHECK2(*dptr, 2);
+    ND_TCHECK2(*dptr, 2);
     length2 = EXTRACT_16BITS(dptr);
-    printf(", length: %u", length2);
+    ND_PRINT((ndo, ", length: %u", length2));
 
     dptr += 2;
-    TCHECK(*dptr);
+    ND_TCHECK(*dptr);
     while (dptr < dataend) {
-        TCHECK2(*dptr, 2);
+        ND_TCHECK2(*dptr, 2);
         lls_type = EXTRACT_16BITS(dptr);
-        printf("\n\t    %s (%u)",
+        ND_PRINT((ndo, "\n\t    %s (%u)",
                tok2str(ospf_lls_tlv_values,"Unknown TLV",lls_type),
-               lls_type);
+               lls_type));
         dptr += 2;
-        TCHECK2(*dptr, 2);
+        ND_TCHECK2(*dptr, 2);
         lls_len = EXTRACT_16BITS(dptr);
-        printf(", length: %u", lls_len);
+        ND_PRINT((ndo, ", length: %u", lls_len));
         dptr += 2;
         switch (lls_type) {
 
         case OSPF_LLS_EO:
             if (lls_len != 4) {
-                printf(" [should be 4]");
+                ND_PRINT((ndo, " [should be 4]"));
                 lls_len = 4;
             }
-            TCHECK2(*dptr, 4);
+            ND_TCHECK2(*dptr, 4);
             lls_flags = EXTRACT_32BITS(dptr);
-            printf("\n\t      Options: 0x%08x [%s]", lls_flags,
-                   bittok2str(ospf_lls_eo_options,"?",lls_flags));
+            ND_PRINT((ndo, "\n\t      Options: 0x%08x [%s]", lls_flags,
+                   bittok2str(ospf_lls_eo_options, "?", lls_flags)));
 
             break;
 
         case OSPF_LLS_MD5:
             if (lls_len != 20) {
-                printf(" [should be 20]");
+                ND_PRINT((ndo, " [should be 20]"));
                 lls_len = 20;
             }
-                       TCHECK2(*dptr, 4);
-            printf("\n\t      Sequence number: 0x%08x", EXTRACT_32BITS(dptr));
+            ND_TCHECK2(*dptr, 4);
+            ND_PRINT((ndo, "\n\t      Sequence number: 0x%08x", EXTRACT_32BITS(dptr)));
             break;
         }
 
@@ -915,8 +910,8 @@ trunc:
 }
 
 static int
-ospf_decode_v2(register const struct ospfhdr *op,
-    register const u_char *dataend)
+ospf_decode_v2(netdissect_options *ndo,
+               register const struct ospfhdr *op, register const u_char *dataend)
 {
        register const struct in_addr *ap;
        register const struct lsr *lsrp;
@@ -934,80 +929,80 @@ ospf_decode_v2(register const struct ospfhdr *op,
                break;
 
        case OSPF_TYPE_HELLO:
-                printf("\n\tOptions [%s]",
-                       bittok2str(ospf_option_values,"none",op->ospf_hello.hello_options));
+               ND_PRINT((ndo, "\n\tOptions [%s]",
+                         bittok2str(ospf_option_values,"none",op->ospf_hello.hello_options)));
 
-                TCHECK(op->ospf_hello.hello_deadint);
-                printf("\n\t  Hello Timer %us, Dead Timer %us, Mask %s, Priority %u",
-                       EXTRACT_16BITS(&op->ospf_hello.hello_helloint),
-                       EXTRACT_32BITS(&op->ospf_hello.hello_deadint),
-                       ipaddr_string(&op->ospf_hello.hello_mask),
-                       op->ospf_hello.hello_priority);
+               ND_TCHECK(op->ospf_hello.hello_deadint);
+               ND_PRINT((ndo, "\n\t  Hello Timer %us, Dead Timer %us, Mask %s, Priority %u",
+                         EXTRACT_16BITS(&op->ospf_hello.hello_helloint),
+                         EXTRACT_32BITS(&op->ospf_hello.hello_deadint),
+                         ipaddr_string(&op->ospf_hello.hello_mask),
+                         op->ospf_hello.hello_priority));
 
-               TCHECK(op->ospf_hello.hello_dr);
+               ND_TCHECK(op->ospf_hello.hello_dr);
                if (op->ospf_hello.hello_dr.s_addr != 0)
-                       printf("\n\t  Designated Router %s",
-                           ipaddr_string(&op->ospf_hello.hello_dr));
+                       ND_PRINT((ndo, "\n\t  Designated Router %s",
+                           ipaddr_string(&op->ospf_hello.hello_dr)));
 
-               TCHECK(op->ospf_hello.hello_bdr);
+               ND_TCHECK(op->ospf_hello.hello_bdr);
                if (op->ospf_hello.hello_bdr.s_addr != 0)
-                       printf(", Backup Designated Router %s",
-                           ipaddr_string(&op->ospf_hello.hello_bdr));
-
-                ap = op->ospf_hello.hello_neighbor;
-                if ((u_char *)ap < dataend)
-                        printf("\n\t  Neighbor List:");
-                while ((u_char *)ap < dataend) {
-                        TCHECK(*ap);
-                        printf("\n\t    %s", ipaddr_string(ap));
-                        ++ap;
-                }
+                       ND_PRINT((ndo, ", Backup Designated Router %s",
+                                 ipaddr_string(&op->ospf_hello.hello_bdr)));
+
+               ap = op->ospf_hello.hello_neighbor;
+               if ((u_char *)ap < dataend)
+                       ND_PRINT((ndo, "\n\t  Neighbor List:"));
+               while ((u_char *)ap < dataend) {
+                       ND_TCHECK(*ap);
+                       ND_PRINT((ndo, "\n\t    %s", ipaddr_string(ap)));
+                       ++ap;
+               }
                break;  /* HELLO */
 
        case OSPF_TYPE_DD:
-               TCHECK(op->ospf_db.db_options);
-                printf("\n\tOptions [%s]",
-                       bittok2str(ospf_option_values,"none",op->ospf_db.db_options));
-               TCHECK(op->ospf_db.db_flags);
-                printf(", DD Flags [%s]",
-                       bittok2str(ospf_dd_flag_values,"none",op->ospf_db.db_flags));
-                TCHECK(op->ospf_db.db_ifmtu);
-                if (op->ospf_db.db_ifmtu) {
-                        printf(", MTU: %u", EXTRACT_16BITS(&op->ospf_db.db_ifmtu));
-                }
-                TCHECK(op->ospf_db.db_seq);
-                printf(", Sequence: 0x%08x", EXTRACT_32BITS(&op->ospf_db.db_seq));
+               ND_TCHECK(op->ospf_db.db_options);
+               ND_PRINT((ndo, "\n\tOptions [%s]",
+                         bittok2str(ospf_option_values, "none", op->ospf_db.db_options)));
+               ND_TCHECK(op->ospf_db.db_flags);
+               ND_PRINT((ndo, ", DD Flags [%s]",
+                         bittok2str(ospf_dd_flag_values, "none", op->ospf_db.db_flags)));
+               ND_TCHECK(op->ospf_db.db_ifmtu);
+               if (op->ospf_db.db_ifmtu) {
+                       ND_PRINT((ndo, ", MTU: %u", EXTRACT_16BITS(&op->ospf_db.db_ifmtu)));
+               }
+               ND_TCHECK(op->ospf_db.db_seq);
+               ND_PRINT((ndo, ", Sequence: 0x%08x", EXTRACT_32BITS(&op->ospf_db.db_seq)));
 
-                /* Print all the LS adv's */
-                lshp = op->ospf_db.db_lshdr;
-                while (((u_char *)lshp < dataend) && ospf_print_lshdr(lshp) != -1) {
-                    ++lshp;
-                }
+               /* Print all the LS adv's */
+               lshp = op->ospf_db.db_lshdr;
+               while (((u_char *)lshp < dataend) && ospf_print_lshdr(ndo, lshp) != -1) {
+                       ++lshp;
+               }
                break;
 
        case OSPF_TYPE_LS_REQ:
                 lsrp = op->ospf_lsr;
                 while ((u_char *)lsrp < dataend) {
-                    TCHECK(*lsrp);
+                    ND_TCHECK(*lsrp);
 
-                    printf("\n\t  Advertising Router: %s, %s LSA (%u)",
+                    ND_PRINT((ndo, "\n\t  Advertising Router: %s, %s LSA (%u)",
                            ipaddr_string(&lsrp->ls_router),
                            tok2str(lsa_values,"unknown",EXTRACT_32BITS(lsrp->ls_type)),
-                           EXTRACT_32BITS(&lsrp->ls_type));
+                           EXTRACT_32BITS(&lsrp->ls_type)));
 
                     switch (EXTRACT_32BITS(lsrp->ls_type)) {
                         /* the LSA header for opaque LSAs was slightly changed */
                     case LS_TYPE_OPAQUE_LL:
                     case LS_TYPE_OPAQUE_AL:
                     case LS_TYPE_OPAQUE_DW:
-                        printf(", Opaque-Type: %s LSA (%u), Opaque-ID: %u",
+                        ND_PRINT((ndo, ", Opaque-Type: %s LSA (%u), Opaque-ID: %u",
                                tok2str(lsa_opaque_values, "unknown",lsrp->un_ls_stateid.opaque_field.opaque_type),
                                lsrp->un_ls_stateid.opaque_field.opaque_type,
-                               EXTRACT_24BITS(&lsrp->un_ls_stateid.opaque_field.opaque_id));
+                               EXTRACT_24BITS(&lsrp->un_ls_stateid.opaque_field.opaque_id)));
                         break;
                     default:
-                        printf(", LSA-ID: %s",
-                               ipaddr_string(&lsrp->un_ls_stateid.ls_stateid));
+                        ND_PRINT((ndo, ", LSA-ID: %s",
+                               ipaddr_string(&lsrp->un_ls_stateid.ls_stateid)));
                         break;
                     }
 
@@ -1017,12 +1012,12 @@ ospf_decode_v2(register const struct ospfhdr *op,
 
        case OSPF_TYPE_LS_UPDATE:
                 lsap = op->ospf_lsu.lsu_lsa;
-                TCHECK(op->ospf_lsu.lsu_count);
+                ND_TCHECK(op->ospf_lsu.lsu_count);
                 lsa_count_max = EXTRACT_32BITS(&op->ospf_lsu.lsu_count);
-                printf(", %d LSA%s",lsa_count_max, PLURAL_SUFFIX(lsa_count_max));
+                ND_PRINT((ndo, ", %d LSA%s", lsa_count_max, PLURAL_SUFFIX(lsa_count_max)));
                 for (lsa_count=1;lsa_count <= lsa_count_max;lsa_count++) {
-                    printf("\n\t  LSA #%u",lsa_count);
-                        lsap = (const struct lsa *)ospf_print_lsa(lsap);
+                    ND_PRINT((ndo, "\n\t  LSA #%u", lsa_count));
+                        lsap = (const struct lsa *)ospf_print_lsa(ndo, lsap);
                         if (lsap == NULL)
                                 goto trunc;
                 }
@@ -1030,7 +1025,7 @@ ospf_decode_v2(register const struct ospfhdr *op,
 
        case OSPF_TYPE_LS_ACK:
                 lshp = op->ospf_lsa.lsa_lshdr;
-                while (ospf_print_lshdr(lshp) != -1) {
+                while (ospf_print_lshdr(ndo, lshp) != -1) {
                     ++lshp;
                 }
                 break;
@@ -1044,8 +1039,9 @@ trunc:
 }
 
 void
-ospf_print(register const u_char *bp, register u_int length,
-    const u_char *bp2 _U_)
+ospf_print(netdissect_options *ndo,
+           register const u_char *bp, register u_int length,
+           const u_char *bp2 _U_)
 {
        register const struct ospfhdr *op;
        register const u_char *dataend;
@@ -1053,31 +1049,28 @@ ospf_print(register const u_char *bp, register u_int length,
 
        op = (struct ospfhdr *)bp;
 
-        /* XXX Before we do anything else, strip off the MD5 trailer */
-        TCHECK(op->ospf_authtype);
-        if (EXTRACT_16BITS(&op->ospf_authtype) == OSPF_AUTH_MD5) {
-                length -= OSPF_AUTH_MD5_LEN;
-                snapend -= OSPF_AUTH_MD5_LEN;
-        }
+       /* XXX Before we do anything else, strip off the MD5 trailer */
+       ND_TCHECK(op->ospf_authtype);
+       if (EXTRACT_16BITS(&op->ospf_authtype) == OSPF_AUTH_MD5) {
+               length -= OSPF_AUTH_MD5_LEN;
+               ndo->ndo_snapend -= OSPF_AUTH_MD5_LEN;
+       }
 
        /* If the type is valid translate it, or just print the type */
        /* value.  If it's not valid, say so and return */
-       TCHECK(op->ospf_type);
+       ND_TCHECK(op->ospf_type);
        cp = tok2str(type2str, "unknown LS-type", op->ospf_type);
-       printf("OSPFv%u, %s, length %u",
-              op->ospf_version,
-              cp,
-              length);
+       ND_PRINT((ndo, "OSPFv%u, %s, length %u", op->ospf_version, cp, length));
        if (*cp == 'u')
                return;
 
-        if(!vflag) { /* non verbose - so lets bail out here */
-                return;
-        }
+       if (!ndo->ndo_vflag) { /* non verbose - so lets bail out here */
+               return;
+       }
 
-       TCHECK(op->ospf_len);
+       ND_TCHECK(op->ospf_len);
        if (length != EXTRACT_16BITS(&op->ospf_len)) {
-               printf(" [len %d]", EXTRACT_16BITS(&op->ospf_len));
+               ND_PRINT((ndo, " [len %d]", EXTRACT_16BITS(&op->ospf_len)));
        }
 
        if (length > EXTRACT_16BITS(&op->ospf_len)) {
@@ -1086,22 +1079,22 @@ ospf_print(register const u_char *bp, register u_int length,
                dataend = bp + length;
        }
 
-       TCHECK(op->ospf_routerid);
-        printf("\n\tRouter-ID %s", ipaddr_string(&op->ospf_routerid));
+       ND_TCHECK(op->ospf_routerid);
+       ND_PRINT((ndo, "\n\tRouter-ID %s", ipaddr_string(&op->ospf_routerid)));
 
-       TCHECK(op->ospf_areaid);
+       ND_TCHECK(op->ospf_areaid);
        if (op->ospf_areaid.s_addr != 0)
-               printf(", Area %s", ipaddr_string(&op->ospf_areaid));
+               ND_PRINT((ndo, ", Area %s", ipaddr_string(&op->ospf_areaid)));
        else
-               printf(", Backbone Area");
+               ND_PRINT((ndo, ", Backbone Area"));
 
-       if (vflag) {
+       if (ndo->ndo_vflag) {
                /* Print authentication data (should we really do this?) */
-               TCHECK2(op->ospf_authdata[0], sizeof(op->ospf_authdata));
+               ND_TCHECK2(op->ospf_authdata[0], sizeof(op->ospf_authdata));
 
-                printf(", Authentication Type: %s (%u)",
-                       tok2str(ospf_authtype_values,"unknown",EXTRACT_16BITS(&op->ospf_authtype)),
-                       EXTRACT_16BITS(&op->ospf_authtype));
+               ND_PRINT((ndo, ", Authentication Type: %s (%u)",
+                         tok2str(ospf_authtype_values, "unknown", EXTRACT_16BITS(&op->ospf_authtype)),
+                         EXTRACT_16BITS(&op->ospf_authtype)));
 
                switch (EXTRACT_16BITS(&op->ospf_authtype)) {
 
@@ -1109,15 +1102,15 @@ ospf_print(register const u_char *bp, register u_int length,
                        break;
 
                case OSPF_AUTH_SIMPLE:
-                        printf("\n\tSimple text password: ");
-                        safeputs(gndo, op->ospf_authdata, OSPF_AUTH_SIMPLE_LEN);
+                       ND_PRINT((ndo, "\n\tSimple text password: "));
+                       safeputs(ndo, op->ospf_authdata, OSPF_AUTH_SIMPLE_LEN);
                        break;
 
                case OSPF_AUTH_MD5:
-                        printf("\n\tKey-ID: %u, Auth-Length: %u, Crypto Sequence Number: 0x%08x",
-                               *((op->ospf_authdata)+2),
-                               *((op->ospf_authdata)+3),
-                               EXTRACT_32BITS((op->ospf_authdata)+4));
+                       ND_PRINT((ndo, "\n\tKey-ID: %u, Auth-Length: %u, Crypto Sequence Number: 0x%08x",
+                                 *((op->ospf_authdata) + 2),
+                                 *((op->ospf_authdata) + 3),
+                                 EXTRACT_32BITS((op->ospf_authdata) + 4)));
                        break;
 
                default:
@@ -1129,20 +1122,20 @@ ospf_print(register const u_char *bp, register u_int length,
 
        case 2:
                /* ospf version 2 */
-               if (ospf_decode_v2(op, dataend))
+               if (ospf_decode_v2(ndo, op, dataend))
                        goto trunc;
                if (length > EXTRACT_16BITS(&op->ospf_len)) {
-                       if (ospf_decode_lls(op, length))
+                       if (ospf_decode_lls(ndo, op, length))
                                goto trunc;
                }
                break;
 
        default:
-               printf(" ospf [version %d]", op->ospf_version);
+               ND_PRINT((ndo, " ospf [version %d]", op->ospf_version));
                break;
        }                       /* end switch on version */
 
        return;
 trunc:
-       fputs(tstr, stdout);
+       ND_PRINT((ndo, "%s", tstr));
 }
index 8fb42afb89f9e29a3e30af187e0dfb0876ee3e6d..31f104050df67151ee64467b60fb600b68a4b1c2 100644 (file)
@@ -697,13 +697,13 @@ ospf6_print_lsa(netdissect_options *ndo,
                break;
 
         case LS_TYPE_GRACE | LS_SCOPE_LINKLOCAL:
-                if (ospf_print_grace_lsa(tptr, lsa_length) == -1) {
+                if (ospf_print_grace_lsa(ndo, tptr, lsa_length) == -1) {
                     return 1;
                 }
                 break;
 
         case LS_TYPE_INTRA_ATE | LS_SCOPE_LINKLOCAL:
-                if (ospf_print_te_lsa(tptr, lsa_length) == -1) {
+                if (ospf_print_te_lsa(ndo, tptr, lsa_length) == -1) {
                     return 1;
                 }
                 break;
index b6f5cbd4302a5a0da80fb6114e4b090b2d599b71..5d726af71d6e331c95e303299b3f3d8e41289179 100644 (file)
 __RCSID("$NetBSD: print-tcp.c,v 1.8 2007/07/24 11:53:48 drochner Exp $");
 #endif
 
+#define NETDISSECT_REWORKED
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
 #include <tcpdump-stdinc.h>
 
-#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -58,11 +58,12 @@ __RCSID("$NetBSD: print-tcp.c,v 1.8 2007/07/24 11:53:48 drochner Exp $");
 #include <openssl/md5.h>
 #include <signature.h>
 
-static int tcp_verify_signature(const struct ip *ip, const struct tcphdr *tp,
+static int tcp_verify_signature(netdissect_options *ndo,
+                                const struct ip *ip, const struct tcphdr *tp,
                                 const u_char *data, int length, const u_char *rcvsig);
 #endif
 
-static void print_tcp_rst_data(register const u_char *sp, u_int length);
+static void print_tcp_rst_data(netdissect_options *, register const u_char *sp, u_int length);
 
 #define MAX_RST_DATA_LEN       30
 
@@ -138,17 +139,20 @@ static const struct tok tcp_option_values[] = {
         { 0, NULL }
 };
 
-static int tcp_cksum(register const struct ip *ip,
-                    register const struct tcphdr *tp,
-                    register u_int len)
+static int
+tcp_cksum(netdissect_options *ndo,
+          register const struct ip *ip,
+          register const struct tcphdr *tp,
+          register u_int len)
 {
-       return nextproto4_cksum(gndo, ip, (const u_int8_t *)tp, len, len,
+       return nextproto4_cksum(ndo, ip, (const u_int8_t *)tp, len, len,
                                IPPROTO_TCP);
 }
 
 void
-tcp_print(register const u_char *bp, register u_int length,
-         register const u_char *bp2, int fragmented)
+tcp_print(netdissect_options *ndo,
+          register const u_char *bp, register u_int length,
+          register const u_char *bp2, int fragmented)
 {
         register const struct tcphdr *tp;
         register const struct ip *ip;
@@ -173,10 +177,10 @@ tcp_print(register const u_char *bp, register u_int length,
                 ip6 = NULL;
 #endif /*INET6*/
         ch = '\0';
-        if (!TTEST(tp->th_dport)) {
-                (void)printf("%s > %s: [|tcp]",
+        if (!ND_TTEST(tp->th_dport)) {
+                ND_PRINT((ndo, "%s > %s: [|tcp]",
                              ipaddr_string(&ip->ip_src),
-                             ipaddr_string(&ip->ip_dst));
+                             ipaddr_string(&ip->ip_dst)));
                 return;
         }
 
@@ -188,56 +192,56 @@ tcp_print(register const u_char *bp, register u_int length,
 #ifdef INET6
         if (ip6) {
                 if (ip6->ip6_nxt == IPPROTO_TCP) {
-                        (void)printf("%s.%s > %s.%s: ",
+                        ND_PRINT((ndo, "%s.%s > %s.%s: ",
                                      ip6addr_string(&ip6->ip6_src),
                                      tcpport_string(sport),
                                      ip6addr_string(&ip6->ip6_dst),
-                                     tcpport_string(dport));
+                                     tcpport_string(dport)));
                 } else {
-                        (void)printf("%s > %s: ",
-                                     tcpport_string(sport), tcpport_string(dport));
+                        ND_PRINT((ndo, "%s > %s: ",
+                                     tcpport_string(sport), tcpport_string(dport)));
                 }
         } else
 #endif /*INET6*/
         {
                 if (ip->ip_p == IPPROTO_TCP) {
-                        (void)printf("%s.%s > %s.%s: ",
+                        ND_PRINT((ndo, "%s.%s > %s.%s: ",
                                      ipaddr_string(&ip->ip_src),
                                      tcpport_string(sport),
                                      ipaddr_string(&ip->ip_dst),
-                                     tcpport_string(dport));
+                                     tcpport_string(dport)));
                 } else {
-                        (void)printf("%s > %s: ",
-                                     tcpport_string(sport), tcpport_string(dport));
+                        ND_PRINT((ndo, "%s > %s: ",
+                                     tcpport_string(sport), tcpport_string(dport)));
                 }
         }
 
         if (hlen < sizeof(*tp)) {
-                (void)printf(" tcp %d [bad hdr length %u - too short, < %lu]",
-                             length - hlen, hlen, (unsigned long)sizeof(*tp));
+                ND_PRINT((ndo, " tcp %d [bad hdr length %u - too short, < %lu]",
+                             length - hlen, hlen, (unsigned long)sizeof(*tp)));
                 return;
         }
 
-        TCHECK(*tp);
+        ND_TCHECK(*tp);
 
         seq = EXTRACT_32BITS(&tp->th_seq);
         ack = EXTRACT_32BITS(&tp->th_ack);
         win = EXTRACT_16BITS(&tp->th_win);
         urp = EXTRACT_16BITS(&tp->th_urp);
 
-        if (qflag) {
-                (void)printf("tcp %d", length - hlen);
+        if (ndo->ndo_qflag) {
+                ND_PRINT((ndo, "tcp %d", length - hlen));
                 if (hlen > length) {
-                        (void)printf(" [bad hdr length %u - too long, > %u]",
-                                     hlen, length);
+                        ND_PRINT((ndo, " [bad hdr length %u - too long, > %u]",
+                                     hlen, length));
                 }
                 return;
         }
 
         flags = tp->th_flags;
-        printf("Flags [%s]", bittok2str_nosep(tcp_flag_values, "none", flags));
+        ND_PRINT((ndo, "Flags [%s]", bittok2str_nosep(tcp_flag_values, "none", flags)));
 
-        if (!Sflag && (flags & TH_ACK)) {
+        if (!ndo->ndo_Sflag && (flags & TH_ACK)) {
                 /*
                  * Find (or record) the initial sequence numbers for
                  * this conversation.  (we pick an arbitrary
@@ -361,41 +365,41 @@ tcp_print(register const u_char *bp, register u_int length,
                 thseq = thack = rev = 0;
         }
         if (hlen > length) {
-                (void)printf(" [bad hdr length %u - too long, > %u]",
-                             hlen, length);
+                ND_PRINT((ndo, " [bad hdr length %u - too long, > %u]",
+                             hlen, length));
                 return;
         }
 
-        if (vflag && !Kflag && !fragmented) {
+        if (ndo->ndo_vflag && !ndo->ndo_Kflag && !fragmented) {
                 /* Check the checksum, if possible. */
                 u_int16_t sum, tcp_sum;
 
                 if (IP_V(ip) == 4) {
-                        if (TTEST2(tp->th_sport, length)) {
-                                sum = tcp_cksum(ip, tp, length);
+                        if (ND_TTEST2(tp->th_sport, length)) {
+                                sum = tcp_cksum(ndo, ip, tp, length);
                                 tcp_sum = EXTRACT_16BITS(&tp->th_sum);
 
-                                (void)printf(", cksum 0x%04x", tcp_sum);
+                                ND_PRINT((ndo, ", cksum 0x%04x", tcp_sum));
                                 if (sum != 0)
-                                        (void)printf(" (incorrect -> 0x%04x)",
-                                            in_cksum_shouldbe(tcp_sum, sum));
+                                        ND_PRINT((ndo, " (incorrect -> 0x%04x)",
+                                            in_cksum_shouldbe(tcp_sum, sum)));
                                 else
-                                        (void)printf(" (correct)");
+                                        ND_PRINT((ndo, " (correct)"));
                         }
                 }
 #ifdef INET6
                 else if (IP_V(ip) == 6 && ip6->ip6_plen) {
-                        if (TTEST2(tp->th_sport, length)) {
+                        if (ND_TTEST2(tp->th_sport, length)) {
                                 sum = nextproto6_cksum(ip6, (const u_int8_t *)tp,
                                                        length, length, IPPROTO_TCP);
                                 tcp_sum = EXTRACT_16BITS(&tp->th_sum);
 
-                                (void)printf(", cksum 0x%04x", tcp_sum);
+                                ND_PRINT((ndo, ", cksum 0x%04x", tcp_sum));
                                 if (sum != 0)
-                                        (void)printf(" (incorrect -> 0x%04x)",
-                                            in_cksum_shouldbe(tcp_sum, sum));
+                                        ND_PRINT((ndo, " (incorrect -> 0x%04x)",
+                                            in_cksum_shouldbe(tcp_sum, sum)));
                                 else
-                                        (void)printf(" (correct)");
+                                        ND_PRINT((ndo, " (correct)"));
 
                         }
                 }
@@ -403,22 +407,22 @@ tcp_print(register const u_char *bp, register u_int length,
         }
 
         length -= hlen;
-        if (vflag > 1 || length > 0 || flags & (TH_SYN | TH_FIN | TH_RST)) {
-                (void)printf(", seq %u", seq);
+        if (ndo->ndo_vflag > 1 || length > 0 || flags & (TH_SYN | TH_FIN | TH_RST)) {
+                ND_PRINT((ndo, ", seq %u", seq));
 
                 if (length > 0) {
-                        (void)printf(":%u", seq + length);
+                        ND_PRINT((ndo, ":%u", seq + length));
                 }
         }
 
         if (flags & TH_ACK) {
-                (void)printf(", ack %u", ack);
+                ND_PRINT((ndo, ", ack %u", ack));
         }
 
-        (void)printf(", win %d", win);
+        ND_PRINT((ndo, ", win %d", win));
 
         if (flags & TH_URG)
-                (void)printf(", urg %d", urp);
+                ND_PRINT((ndo, ", urg %d", urp));
         /*
          * Handle any options.
          */
@@ -429,16 +433,16 @@ tcp_print(register const u_char *bp, register u_int length,
 
                 hlen -= sizeof(*tp);
                 cp = (const u_char *)tp + sizeof(*tp);
-                printf(", options [");
+                ND_PRINT((ndo, ", options ["));
                 while (hlen > 0) {
                         if (ch != '\0')
-                                putchar(ch);
-                        TCHECK(*cp);
+                                ND_PRINT((ndo, "%c", ch));
+                        ND_TCHECK(*cp);
                         opt = *cp++;
                         if (ZEROLENOPT(opt))
                                 len = 1;
                         else {
-                                TCHECK(*cp);
+                                ND_TCHECK(*cp);
                                 len = *cp++;   /* total including type, len */
                                 if (len < 2 || len > hlen)
                                         goto bad;
@@ -448,33 +452,33 @@ tcp_print(register const u_char *bp, register u_int length,
                         datalen = 0;
 
 /* Bail if "l" bytes of data are not left or were not captured  */
-#define LENCHECK(l) { if ((l) > hlen) goto bad; TCHECK2(*cp, l); }
+#define LENCHECK(l) { if ((l) > hlen) goto bad; ND_TCHECK2(*cp, l); }
 
 
-                        printf("%s", tok2str(tcp_option_values, "unknown-%u", opt));
+                        ND_PRINT((ndo, "%s", tok2str(tcp_option_values, "unknown-%u", opt)));
 
                         switch (opt) {
 
                         case TCPOPT_MAXSEG:
                                 datalen = 2;
                                 LENCHECK(datalen);
-                                (void)printf(" %u", EXTRACT_16BITS(cp));
+                                ND_PRINT((ndo, " %u", EXTRACT_16BITS(cp)));
                                 break;
 
                         case TCPOPT_WSCALE:
                                 datalen = 1;
                                 LENCHECK(datalen);
-                                (void)printf(" %u", *cp);
+                                ND_PRINT((ndo, " %u", *cp));
                                 break;
 
                         case TCPOPT_SACK:
                                 datalen = len - 2;
                                 if (datalen % 8 != 0) {
-                                        (void)printf("malformed sack");
+                                        ND_PRINT((ndo, "malformed sack"));
                                 } else {
                                         u_int32_t s, e;
 
-                                        (void)printf(" %d ", datalen / 8);
+                                        ND_PRINT((ndo, " %d ", datalen / 8));
                                         for (i = 0; i < datalen; i += 8) {
                                                 LENCHECK(i + 4);
                                                 s = EXTRACT_32BITS(cp + i);
@@ -487,7 +491,7 @@ tcp_print(register const u_char *bp, register u_int length,
                                                         s -= thack;
                                                         e -= thack;
                                                 }
-                                                (void)printf("{%u:%u}", s, e);
+                                                ND_PRINT((ndo, "{%u:%u}", s, e));
                                         }
                                 }
                                 break;
@@ -504,50 +508,50 @@ tcp_print(register const u_char *bp, register u_int length,
                                  */
                                 datalen = 4;
                                 LENCHECK(datalen);
-                                (void)printf(" %u", EXTRACT_32BITS(cp));
+                                ND_PRINT((ndo, " %u", EXTRACT_32BITS(cp)));
                                 break;
 
                         case TCPOPT_TIMESTAMP:
                                 datalen = 8;
                                 LENCHECK(datalen);
-                                (void)printf(" val %u ecr %u",
+                                ND_PRINT((ndo, " val %u ecr %u",
                                              EXTRACT_32BITS(cp),
-                                             EXTRACT_32BITS(cp + 4));
+                                             EXTRACT_32BITS(cp + 4)));
                                 break;
 
                         case TCPOPT_SIGNATURE:
                                 datalen = TCP_SIGLEN;
                                 LENCHECK(datalen);
 #ifdef HAVE_LIBCRYPTO
-                                switch (tcp_verify_signature(ip, tp,
+                                switch (tcp_verify_signature(ndo, ip, tp,
                                                              bp + TH_OFF(tp) * 4, length, cp)) {
 
                                 case SIGNATURE_VALID:
-                                        (void)printf("valid");
+                                        ND_PRINT((ndo, "valid"));
                                         break;
 
                                 case SIGNATURE_INVALID:
-                                        (void)printf("invalid");
+                                        ND_PRINT((ndo, "invalid"));
                                         break;
 
                                 case CANT_CHECK_SIGNATURE:
-                                        (void)printf("can't check - ");
+                                        ND_PRINT((ndo, "can't check - "));
                                         for (i = 0; i < TCP_SIGLEN; ++i)
-                                                (void)printf("%02x", cp[i]);
+                                                ND_PRINT((ndo, "%02x", cp[i]));
                                         break;
                                 }
 #else
                                 for (i = 0; i < TCP_SIGLEN; ++i)
-                                        (void)printf("%02x", cp[i]);
+                                        ND_PRINT((ndo, "%02x", cp[i]));
 #endif
                                 break;
 
                         case TCPOPT_AUTH:
-                                (void)printf("keyid %d", *cp++);
+                                ND_PRINT((ndo, "keyid %d", *cp++));
                                 datalen = len - 3;
                                 for (i = 0; i < datalen; ++i) {
                                         LENCHECK(i);
-                                        (void)printf("%02x", cp[i]);
+                                        ND_PRINT((ndo, "%02x", cp[i]));
                                 }
                                 break;
 
@@ -565,18 +569,18 @@ tcp_print(register const u_char *bp, register u_int length,
                                 datalen = 2;
                                 LENCHECK(datalen);
                                 utoval = EXTRACT_16BITS(cp);
-                                (void)printf("0x%x", utoval);
+                                ND_PRINT((ndo, "0x%x", utoval));
                                 if (utoval & 0x0001)
                                         utoval = (utoval >> 1) * 60;
                                 else
                                         utoval >>= 1;
-                                (void)printf(" %u", utoval);
+                                ND_PRINT((ndo, " %u", utoval));
                                 break;
 
                         case TCPOPT_MPTCP:
                                 datalen = len - 2;
                                 LENCHECK(datalen);
-                                if (!mptcp_print(gndo, cp-2, len, flags))
+                                if (!mptcp_print(ndo, cp-2, len, flags))
                                         goto bad;
                                 break;
 
@@ -587,7 +591,7 @@ tcp_print(register const u_char *bp, register u_int length,
                                         goto bad;
                                 /* RFC6994 */
                                 magic = EXTRACT_16BITS(cp);
-                                (void)printf("-");
+                                ND_PRINT((ndo, "-"));
 
                                 switch(magic) {
 
@@ -595,22 +599,22 @@ tcp_print(register const u_char *bp, register u_int length,
                                         /* TCP Fast Open: draft-ietf-tcpm-fastopen-04 */
                                         if (datalen == 2) {
                                                 /* Fast Open Cookie Request */
-                                                (void)printf("tfo cookiereq");
+                                                ND_PRINT((ndo, "tfo cookiereq"));
                                         } else {
                                                 /* Fast Open Cookie */
                                                 if (datalen % 2 != 0 || datalen < 6 || datalen > 18) {
-                                                        (void)printf("tfo malformed");
+                                                        ND_PRINT((ndo, "tfo malformed"));
                                                 } else {
-                                                        (void)printf("tfo cookie ");
+                                                        ND_PRINT((ndo, "tfo cookie "));
                                                         for (i = 2; i < datalen; ++i)
-                                                                (void)printf("%02x", cp[i]);
+                                                                ND_PRINT((ndo, "%02x", cp[i]));
                                                 }
                                         }
                                         break;
 
                                 default:
                                         /* Unknown magic number */
-                                        (void)printf("%04x", magic);
+                                        ND_PRINT((ndo, "%04x", magic));
                                         break;
                                 }
                                 break;
@@ -618,10 +622,10 @@ tcp_print(register const u_char *bp, register u_int length,
                         default:
                                 datalen = len - 2;
                                 if (datalen)
-                                        printf(" 0x");
+                                        ND_PRINT((ndo, " 0x"));
                                 for (i = 0; i < datalen; ++i) {
                                         LENCHECK(i);
-                                        (void)printf("%02x", cp[i]);
+                                        ND_PRINT((ndo, "%02x", cp[i]));
                                 }
                                 break;
                         }
@@ -635,18 +639,18 @@ tcp_print(register const u_char *bp, register u_int length,
                         if (!ZEROLENOPT(opt))
                                 ++datalen;             /* size octet */
                         if (datalen != len)
-                                (void)printf("[len %d]", len);
+                                ND_PRINT((ndo, "[len %d]", len));
                         ch = ',';
                         if (opt == TCPOPT_EOL)
                                 break;
                 }
-                putchar(']');
+                ND_PRINT((ndo, "]"));
         }
 
         /*
          * Print length field before crawling down the stack.
          */
-        printf(", length %u", length);
+        ND_PRINT((ndo, ", length %u", length));
 
         if (length <= 0)
                 return;
@@ -655,38 +659,38 @@ tcp_print(register const u_char *bp, register u_int length,
          * Decode payload if necessary.
          */
         bp += TH_OFF(tp) * 4;
-        if ((flags & TH_RST) && vflag) {
-                print_tcp_rst_data(bp, length);
+        if ((flags & TH_RST) && ndo->ndo_vflag) {
+                print_tcp_rst_data(ndo, bp, length);
                 return;
         }
 
-        if (packettype) {
-                switch (packettype) {
+        if (ndo->ndo_packettype) {
+                switch (ndo->ndo_packettype) {
                 case PT_ZMTP1:
-                        zmtp1_print(gndo, bp, length);
+                        zmtp1_print(ndo, bp, length);
                         break;
                 }
                 return;
         }
 
         if (sport == TELNET_PORT || dport == TELNET_PORT) {
-                if (!qflag && vflag)
-                        telnet_print(gndo, bp, length);
+                if (!ndo->ndo_qflag && ndo->ndo_vflag)
+                        telnet_print(ndo, bp, length);
         } else if (sport == BGP_PORT || dport == BGP_PORT)
-                bgp_print(gndo, bp, length);
+                bgp_print(ndo, bp, length);
         else if (sport == PPTP_PORT || dport == PPTP_PORT)
-                pptp_print(gndo, bp);
+                pptp_print(ndo, bp);
 #ifdef TCPDUMP_DO_SMB
         else if (sport == NETBIOS_SSN_PORT || dport == NETBIOS_SSN_PORT)
-                nbt_tcp_print(gndo, bp, length);
+                nbt_tcp_print(ndo, bp, length);
        else if (sport == SMB_PORT || dport == SMB_PORT)
-               smb_tcp_print(gndo, bp, length);
+               smb_tcp_print(ndo, bp, length);
 #endif
         else if (sport == BEEP_PORT || dport == BEEP_PORT)
-                beep_print(gndo, bp, length);
+                beep_print(ndo, bp, length);
         else if (sport == OPENFLOW_PORT_OLD || dport == OPENFLOW_PORT_OLD ||
                  sport == OPENFLOW_PORT_IANA || dport == OPENFLOW_PORT_IANA)
-                openflow_print(gndo, bp, length);
+                openflow_print(ndo, bp, length);
         else if (length > 2 &&
                  (sport == NAMESERVER_PORT || dport == NAMESERVER_PORT ||
                   sport == MULTICASTDNS_PORT || dport == MULTICASTDNS_PORT)) {
@@ -694,17 +698,17 @@ tcp_print(register const u_char *bp, register u_int length,
                  * TCP DNS query has 2byte length at the head.
                  * XXX packet could be unaligned, it can go strange
                  */
-                ns_print(gndo, bp + 2, length - 2, 0);
+                ns_print(ndo, bp + 2, length - 2, 0);
         } else if (sport == MSDP_PORT || dport == MSDP_PORT) {
-                msdp_print(gndo, bp, length);
+                msdp_print(ndo, bp, length);
         } else if (sport == RPKI_RTR_PORT || dport == RPKI_RTR_PORT) {
-                rpki_rtr_print(gndo, bp, length);
+                rpki_rtr_print(ndo, bp, length);
         }
         else if (length > 0 && (sport == LDP_PORT || dport == LDP_PORT)) {
-                ldp_print(gndo, bp, length);
+                ldp_print(ndo, bp, length);
         }
         else if ((sport == NFS_PORT || dport == NFS_PORT) &&
-                 length >= 4 && TTEST2(*bp, 4)) {
+                 length >= 4 && ND_TTEST2(*bp, 4)) {
                 /*
                  * If data present, header length valid, and NFS port used,
                  * assume NFS.
@@ -719,16 +723,16 @@ tcp_print(register const u_char *bp, register u_int length,
                 if (fraglen > (length) - 4)
                         fraglen = (length) - 4;
                 rp = (struct sunrpc_msg *)(bp + 4);
-                if (TTEST(rp->rm_direction)) {
+                if (ND_TTEST(rp->rm_direction)) {
                         direction = (enum sunrpc_msg_type)EXTRACT_32BITS(&rp->rm_direction);
                         if (dport == NFS_PORT && direction == SUNRPC_CALL) {
-                                (void)printf(": NFS request xid %u ", EXTRACT_32BITS(&rp->rm_xid));
-                                nfsreq_print_noaddr(gndo, (u_char *)rp, fraglen, (u_char *)ip);
+                                ND_PRINT((ndo, ": NFS request xid %u ", EXTRACT_32BITS(&rp->rm_xid)));
+                                nfsreq_print_noaddr(ndo, (u_char *)rp, fraglen, (u_char *)ip);
                                 return;
                         }
                         if (sport == NFS_PORT && direction == SUNRPC_REPLY) {
-                                (void)printf(": NFS reply xid %u ", EXTRACT_32BITS(&rp->rm_xid));
-                                nfsreply_print_noaddr(gndo, (u_char *)rp, fraglen, (u_char *)ip);
+                                ND_PRINT((ndo, ": NFS reply xid %u ", EXTRACT_32BITS(&rp->rm_xid)));
+                                nfsreply_print_noaddr(ndo, (u_char *)rp, fraglen, (u_char *)ip);
                                 return;
                         }
                 }
@@ -736,14 +740,14 @@ tcp_print(register const u_char *bp, register u_int length,
 
         return;
  bad:
-        fputs("[bad opt]", stdout);
+        ND_PRINT((ndo, "[bad opt]"));
         if (ch != '\0')
-                putchar('>');
+                ND_PRINT((ndo, ">"));
         return;
  trunc:
-        fputs("[|tcp]", stdout);
+        ND_PRINT((ndo, "[|tcp]"));
         if (ch != '\0')
-                putchar('>');
+                ND_PRINT((ndo, ">"));
 }
 
 /*
@@ -762,30 +766,29 @@ tcp_print(register const u_char *bp, register u_int length,
  */
 
 static void
-print_tcp_rst_data(register const u_char *sp, u_int length)
+print_tcp_rst_data(netdissect_options *ndo,
+                   register const u_char *sp, u_int length)
 {
         int c;
 
-        if (TTEST2(*sp, length))
-                printf(" [RST");
-        else
-                printf(" [!RST");
+        ND_PRINT((ndo, ND_TTEST2(*sp, length) ? " [RST" : " [!RST"));
         if (length > MAX_RST_DATA_LEN) {
                 length = MAX_RST_DATA_LEN;     /* can use -X for longer */
-                putchar('+');                  /* indicate we truncate */
+                ND_PRINT((ndo, "+"));                  /* indicate we truncate */
         }
-        putchar(' ');
-        while (length-- && sp <= snapend) {
+        ND_PRINT((ndo, " "));
+        while (length-- && sp <= ndo->ndo_snapend) {
                 c = *sp++;
-                safeputchar(gndo, c);
+                safeputchar(ndo, c);
         }
-        putchar(']');
+        ND_PRINT((ndo, "]"));
 }
 
 #ifdef HAVE_LIBCRYPTO
 USES_APPLE_DEPRECATED_API
 static int
-tcp_verify_signature(const struct ip *ip, const struct tcphdr *tp,
+tcp_verify_signature(netdissect_options *ndo,
+                     const struct ip *ip, const struct tcphdr *tp,
                      const u_char *data, int length, const u_char *rcvsig)
 {
         struct tcphdr tp1;
@@ -799,16 +802,16 @@ tcp_verify_signature(const struct ip *ip, const struct tcphdr *tp,
         u_int8_t nxt;
 #endif
 
-       if (data + length > snapend) {
-               printf("snaplen too short, ");
+       if (data + length > ndo->ndo_snapend) {
+               ND_PRINT((ndo, "snaplen too short, "));
                return (CANT_CHECK_SIGNATURE);
        }
 
         tp1 = *tp;
 
-        if (sigsecret == NULL) {
-               printf("shared secret not supplied with -M, ");
-                return (CANT_CHECK_SIGNATURE);
+        if (ndo->ndo_sigsecret == NULL) {
+               ND_PRINT((ndo, "shared secret not supplied with -M, ");
+                return (CANT_CHECK_SIGNATURE));
         }
 
         MD5_Init(&ctx);
@@ -839,9 +842,9 @@ tcp_verify_signature(const struct ip *ip, const struct tcphdr *tp,
 #endif
         } else {
 #ifdef INET6
-               printf("IP version not 4 or 6, ");
+               ND_PRINT((ndo, "IP version not 4 or 6, "));
 #else
-               printf("IP version not 4, ");
+               ND_PRINT((ndo, "IP version not 4, "));
 #endif
                 return (CANT_CHECK_SIGNATURE);
         }
@@ -862,7 +865,7 @@ tcp_verify_signature(const struct ip *ip, const struct tcphdr *tp,
         /*
          * Step 4: Update MD5 hash with shared secret.
          */
-        MD5_Update(&ctx, sigsecret, strlen(sigsecret));
+        MD5_Update(&ctx, ndo->ndo_sigsecret, strlen(ndo->ndo_sigsecret));
         MD5_Final(sig, &ctx);
 
         if (memcmp(rcvsig, sig, TCP_SIGLEN) == 0)