]> The Tcpdump Group git mirrors - tcpdump/commitdiff
NDOize EIGRP, ICMP, L2TP, STP and UDP decoders
authorDenis Ovsienko <[email protected]>
Sat, 15 Mar 2014 19:25:06 +0000 (23:25 +0400)
committerDenis Ovsienko <[email protected]>
Sat, 15 Mar 2014 19:25:06 +0000 (23:25 +0400)
12 files changed:
interface.h
netdissect.h
print-atalk.c
print-eigrp.c
print-icmp.c
print-ip.c
print-ip6.c
print-ipx.c
print-l2tp.c
print-llc.c
print-stp.c
print-udp.c

index 8f0bb84a8c896bcc90b6e8e8eba15fd0838fe09b..400ff3b1840c66389427dd6de80fee3b38c050e4 100644 (file)
@@ -189,7 +189,6 @@ extern u_int ieee802_11_radio_if_print(const struct pcap_pkthdr *,
        const u_char *);
 extern u_int ieee802_11_radio_avs_if_print(const struct pcap_pkthdr *,
        const u_char *);
-extern void icmp_print(const u_char *, u_int, const u_char *, int);
 extern void igmp_print(const u_char *, u_int);
 extern void isoclns_print(const u_char *, u_int, u_int);
 extern void krb_print(const u_char *);
@@ -214,7 +213,6 @@ extern void lmp_print(const u_char *, u_int);
 extern void lspping_print(const u_char *, u_int);
 extern void lwapp_control_print(const u_char *, u_int, int);
 extern void lwapp_data_print(const u_char *, u_int);
-extern void eigrp_print(const u_char *, u_int);
 extern void pim_print(const u_char *, u_int, 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 *);
@@ -244,7 +242,6 @@ extern void snmp_print(const u_char *, u_int);
 extern void tcp_print(const u_char *, u_int, const u_char *, int);
 extern void tftp_print(const u_char *, u_int);
 extern void timed_print(const u_char *);
-extern void udp_print(const u_char *, u_int, const u_char *, int);
 extern void vtp_print(const u_char *, u_int);
 extern void wb_print(const void *, u_int);
 extern void rx_print(register const u_char *, int, int, int, u_char *);
@@ -257,14 +254,12 @@ extern void smb_tcp_print(const u_char *, int);
 extern char *smb_errstr(int, int);
 extern const char *nt_errstr(u_int32_t);
 extern void print_data(const unsigned char *, int);
-extern void l2tp_print(const u_char *, u_int);
 extern void vrrp_print(const u_char *, u_int, const u_char *, int);
 extern void slow_print(const u_char *, u_int);
 extern void sflow_print(const u_char *, u_int);
 extern void cfm_print(const u_char *, u_int);
 extern void pgm_print(const u_char *, u_int, const u_char *);
 extern void cdp_print(const u_char *, u_int, u_int);
-extern void stp_print(const u_char *, u_int);
 extern void radius_print(const u_char *, u_int);
 extern void lwres_print(const u_char *, u_int);
 extern void pptp_print(const u_char *);
index 1c071fb0ac522ab9cfb6be33432f88b6a588c076..512118cdfeb3b89f74237fe677f91c6cc910bbb5 100644 (file)
@@ -422,6 +422,11 @@ extern u_int sll_if_print(netdissect_options *, const struct pcap_pkthdr *, cons
 extern void dccp_print(netdissect_options *, const u_char *, const u_char *, u_int);
 extern int llc_print(netdissect_options *, const u_char *, u_int, u_int, const u_char *, const u_char *, u_short *);
 extern int snap_print(netdissect_options *, const u_char *, u_int, u_int, u_int);
+extern void eigrp_print(netdissect_options *, const u_char *, u_int);
+extern void stp_print(netdissect_options *, const u_char *, u_int);
+extern void l2tp_print(netdissect_options *, const u_char *, u_int);
+extern void udp_print(netdissect_options *, const u_char *, u_int, const u_char *, int);
+extern void icmp_print(netdissect_options *, const u_char *, u_int, const u_char *, int);
 
 /* stuff that has not yet been rototiled */
 extern const u_char * ns_nprint (register const u_char *, register const u_char *);
@@ -447,8 +452,6 @@ extern void dvmrp_print(netdissect_options *,const u_char *, u_int);
 extern void egp_print(netdissect_options *,const u_char *, u_int,
                      const u_char *);
 
-extern void icmp_print(netdissect_options *,const u_char *, u_int,
-                      const u_char *);
 extern void hsrp_print(netdissect_options *ndo,
                       register const u_char *bp, register u_int len);
 extern void ieee802_11_if_print(u_char *,const struct pcap_pkthdr *, const u_char *);
@@ -507,8 +510,6 @@ extern void tcp_print(netdissect_options *,const u_char *, u_int,
                      const u_char *, int);
 extern void tftp_print(netdissect_options *,const u_char *, u_int);
 extern void timed_print(netdissect_options *,const u_char *, u_int);
-extern void udp_print(netdissect_options *,const u_char *, u_int,
-                     const u_char *, int);
 extern void wb_print(netdissect_options *,const void *, u_int);
 extern void esp_print_decodesecret(netdissect_options *ndo);
 extern void rx_print(netdissect_options *,register const u_char *,
@@ -524,7 +525,6 @@ extern void nbt_udp138_print(netdissect_options *,
 extern char *smb_errstr(netdissect_options *,int, int);
 extern const char *nt_errstr(netdissect_options *, u_int32_t);
 extern void print_data(netdissect_options *,const unsigned char *, int);
-extern void l2tp_print(netdissect_options *,const u_char *, u_int);
 extern void lcp_print(netdissect_options *,const u_char *, u_int);
 extern void vrrp_print(netdissect_options *,const u_char *bp,
                       u_int len, int ttl);
@@ -532,7 +532,6 @@ extern void carp_print(netdissect_options *,const u_char *bp,
                       u_int len, int ttl);
 extern void cdp_print(netdissect_options *,const u_char *,
                      u_int, u_int, const u_char *, const u_char *);
-extern void stp_print(netdissect_options *,const u_char *p, u_int length);
 extern void radius_print(netdissect_options *,const u_char *, u_int);
 extern void lwres_print(netdissect_options *,const u_char *, u_int);
 extern void pptp_print(netdissect_options *,const u_char *, u_int);
index fc234b765f3c44c8cab19eb1475261066b63c76e..0f46fa3e4999792fc1098622700f8c406015ba91 100644 (file)
@@ -235,7 +235,7 @@ ddp_print(register const u_char *bp, register u_int length, register int t,
                break;
 
        case ddpEIGRP:
-               eigrp_print(bp, length);
+               eigrp_print(gndo, bp, length);
                break;
 
        default:
index 5a8c035d003c46b61d2bc6e1ced88c683f287bde..83a9f31ac949efc55da30e0ed4b0b7f733f248ee 100644 (file)
  * FOR A PARTICULAR PURPOSE.
  */
 
+#define NETDISSECT_REWORKED
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
 #include <tcpdump-stdinc.h>
 
-#include <stdio.h>
-#include <stdlib.h>
 #include <string.h>
 
 #include "interface.h"
@@ -206,7 +205,7 @@ static const struct tok eigrp_ext_proto_id_values[] = {
 };
 
 void
-eigrp_print(register const u_char *pptr, register u_int len) {
+eigrp_print(netdissect_options *ndo, register const u_char *pptr, register u_int len) {
 
     const struct eigrp_common_header *eigrp_com_header;
     const struct eigrp_tlv_header *eigrp_tlv_header;
@@ -226,21 +225,21 @@ eigrp_print(register const u_char *pptr, register u_int len) {
 
     tptr=pptr;
     eigrp_com_header = (const struct eigrp_common_header *)pptr;
-    TCHECK(*eigrp_com_header);
+    ND_TCHECK(*eigrp_com_header);
 
     /*
      * Sanity checking of the header.
      */
     if (eigrp_com_header->version != EIGRP_VERSION) {
-       printf("EIGRP version %u packet not supported",eigrp_com_header->version);
+       ND_PRINT((ndo, "EIGRP version %u packet not supported",eigrp_com_header->version));
        return;
     }
 
     /* in non-verbose mode just lets print the basic Message Type*/
-    if (vflag < 1) {
-        printf("EIGRP %s, length: %u",
+    if (ndo->ndo_vflag < 1) {
+        ND_PRINT((ndo, "EIGRP %s, length: %u",
                tok2str(eigrp_opcode_values, "unknown (%u)",eigrp_com_header->opcode),
-               len);
+               len));
         return;
     }
 
@@ -249,7 +248,7 @@ eigrp_print(register const u_char *pptr, register u_int len) {
     tlen=len-sizeof(struct eigrp_common_header);
 
     /* FIXME print other header info */
-    printf("\n\tEIGRP v%u, opcode: %s (%u), chksum: 0x%04x, Flags: [%s]\n\tseq: 0x%08x, ack: 0x%08x, AS: %u, length: %u",
+    ND_PRINT((ndo, "\n\tEIGRP v%u, opcode: %s (%u), chksum: 0x%04x, Flags: [%s]\n\tseq: 0x%08x, ack: 0x%08x, AS: %u, length: %u",
            eigrp_com_header->version,
            tok2str(eigrp_opcode_values, "unknown, type: %u",eigrp_com_header->opcode),
            eigrp_com_header->opcode,
@@ -260,13 +259,13 @@ eigrp_print(register const u_char *pptr, register u_int len) {
            EXTRACT_32BITS(&eigrp_com_header->seq),
            EXTRACT_32BITS(&eigrp_com_header->ack),
            EXTRACT_32BITS(&eigrp_com_header->asn),
-           tlen);
+           tlen));
 
     tptr+=sizeof(const struct eigrp_common_header);
 
     while(tlen>0) {
         /* did we capture enough for fully decoding the object header ? */
-        TCHECK2(*tptr, sizeof(struct eigrp_tlv_header));
+        ND_TCHECK2(*tptr, sizeof(struct eigrp_tlv_header));
 
         eigrp_tlv_header = (const struct eigrp_tlv_header *)tptr;
         eigrp_tlv_len=EXTRACT_16BITS(&eigrp_tlv_header->length);
@@ -275,45 +274,45 @@ eigrp_print(register const u_char *pptr, register u_int len) {
 
         if (eigrp_tlv_len < sizeof(struct eigrp_tlv_header) ||
             eigrp_tlv_len > tlen) {
-            print_unknown_data(gndo,tptr+sizeof(struct eigrp_tlv_header),"\n\t    ",tlen);
+            print_unknown_data(ndo,tptr+sizeof(struct eigrp_tlv_header),"\n\t    ",tlen);
             return;
         }
 
-        printf("\n\t  %s TLV (0x%04x), length: %u",
+        ND_PRINT((ndo, "\n\t  %s TLV (0x%04x), length: %u",
                tok2str(eigrp_tlv_values,
                        "Unknown",
                        eigrp_tlv_type),
                eigrp_tlv_type,
-               eigrp_tlv_len);
+               eigrp_tlv_len));
 
         tlv_tptr=tptr+sizeof(struct eigrp_tlv_header);
         tlv_tlen=eigrp_tlv_len-sizeof(struct eigrp_tlv_header);
 
         /* did we capture enough for fully decoding the object ? */
-        TCHECK2(*tptr, eigrp_tlv_len);
+        ND_TCHECK2(*tptr, eigrp_tlv_len);
 
         switch(eigrp_tlv_type) {
 
         case EIGRP_TLV_GENERAL_PARM:
             tlv_ptr.eigrp_tlv_general_parm = (const struct eigrp_tlv_general_parm_t *)tlv_tptr;
 
-            printf("\n\t    holdtime: %us, k1 %u, k2 %u, k3 %u, k4 %u, k5 %u",
+            ND_PRINT((ndo, "\n\t    holdtime: %us, k1 %u, k2 %u, k3 %u, k4 %u, k5 %u",
                    EXTRACT_16BITS(tlv_ptr.eigrp_tlv_general_parm->holdtime),
                    tlv_ptr.eigrp_tlv_general_parm->k1,
                    tlv_ptr.eigrp_tlv_general_parm->k2,
                    tlv_ptr.eigrp_tlv_general_parm->k3,
                    tlv_ptr.eigrp_tlv_general_parm->k4,
-                   tlv_ptr.eigrp_tlv_general_parm->k5);
+                   tlv_ptr.eigrp_tlv_general_parm->k5));
             break;
 
         case EIGRP_TLV_SW_VERSION:
             tlv_ptr.eigrp_tlv_sw_version = (const struct eigrp_tlv_sw_version_t *)tlv_tptr;
 
-            printf("\n\t    IOS version: %u.%u, EIGRP version %u.%u",
+            ND_PRINT((ndo, "\n\t    IOS version: %u.%u, EIGRP version %u.%u",
                    tlv_ptr.eigrp_tlv_sw_version->ios_major,
                    tlv_ptr.eigrp_tlv_sw_version->ios_minor,
                    tlv_ptr.eigrp_tlv_sw_version->eigrp_major,
-                   tlv_ptr.eigrp_tlv_sw_version->eigrp_minor);
+                   tlv_ptr.eigrp_tlv_sw_version->eigrp_minor));
             break;
 
         case EIGRP_TLV_IP_INT:
@@ -321,28 +320,28 @@ eigrp_print(register const u_char *pptr, register u_int len) {
 
             bit_length = tlv_ptr.eigrp_tlv_ip_int->plen;
             if (bit_length > 32) {
-                printf("\n\t    illegal prefix length %u",bit_length);
+                ND_PRINT((ndo, "\n\t    illegal prefix length %u",bit_length));
                 break;
             }
             byte_length = (bit_length + 7) / 8; /* variable length encoding */
             memset(prefix, 0, 4);
             memcpy(prefix,&tlv_ptr.eigrp_tlv_ip_int->destination,byte_length);
 
-            printf("\n\t    IPv4 prefix: %15s/%u, nexthop: ",
+            ND_PRINT((ndo, "\n\t    IPv4 prefix: %15s/%u, nexthop: ",
                    ipaddr_string(prefix),
-                   bit_length);
+                   bit_length));
             if (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_ip_int->nexthop) == 0)
-                printf("self");
+                ND_PRINT((ndo, "self"));
             else
-                printf("%s",ipaddr_string(&tlv_ptr.eigrp_tlv_ip_int->nexthop));
+                ND_PRINT((ndo, "%s",ipaddr_string(&tlv_ptr.eigrp_tlv_ip_int->nexthop)));
 
-            printf("\n\t      delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
+            ND_PRINT((ndo, "\n\t      delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
                    (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_ip_int->delay)/100),
                    EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_ip_int->bandwidth),
                    EXTRACT_24BITS(&tlv_ptr.eigrp_tlv_ip_int->mtu),
                    tlv_ptr.eigrp_tlv_ip_int->hopcount,
                    tlv_ptr.eigrp_tlv_ip_int->reliability,
-                   tlv_ptr.eigrp_tlv_ip_int->load);
+                   tlv_ptr.eigrp_tlv_ip_int->load));
             break;
 
         case EIGRP_TLV_IP_EXT:
@@ -350,99 +349,99 @@ eigrp_print(register const u_char *pptr, register u_int len) {
 
             bit_length = tlv_ptr.eigrp_tlv_ip_ext->plen;
             if (bit_length > 32) {
-                printf("\n\t    illegal prefix length %u",bit_length);
+                ND_PRINT((ndo, "\n\t    illegal prefix length %u",bit_length));
                 break;
             }
             byte_length = (bit_length + 7) / 8; /* variable length encoding */
             memset(prefix, 0, 4);
             memcpy(prefix,&tlv_ptr.eigrp_tlv_ip_ext->destination,byte_length);
 
-            printf("\n\t    IPv4 prefix: %15s/%u, nexthop: ",
+            ND_PRINT((ndo, "\n\t    IPv4 prefix: %15s/%u, nexthop: ",
                    ipaddr_string(prefix),
-                   bit_length);
+                   bit_length));
             if (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_ip_ext->nexthop) == 0)
-                printf("self");
+                ND_PRINT((ndo, "self"));
             else
-                printf("%s",ipaddr_string(&tlv_ptr.eigrp_tlv_ip_ext->nexthop));
+                ND_PRINT((ndo, "%s",ipaddr_string(&tlv_ptr.eigrp_tlv_ip_ext->nexthop)));
 
-            printf("\n\t      origin-router %s, origin-as %u, origin-proto %s, flags [0x%02x], tag 0x%08x, metric %u",
+            ND_PRINT((ndo, "\n\t      origin-router %s, origin-as %u, origin-proto %s, flags [0x%02x], tag 0x%08x, metric %u",
                    ipaddr_string(tlv_ptr.eigrp_tlv_ip_ext->origin_router),
                    EXTRACT_32BITS(tlv_ptr.eigrp_tlv_ip_ext->origin_as),
                    tok2str(eigrp_ext_proto_id_values,"unknown",tlv_ptr.eigrp_tlv_ip_ext->proto_id),
                    tlv_ptr.eigrp_tlv_ip_ext->flags,
                    EXTRACT_32BITS(tlv_ptr.eigrp_tlv_ip_ext->tag),
-                   EXTRACT_32BITS(tlv_ptr.eigrp_tlv_ip_ext->metric));
+                   EXTRACT_32BITS(tlv_ptr.eigrp_tlv_ip_ext->metric)));
 
-            printf("\n\t      delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
+            ND_PRINT((ndo, "\n\t      delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
                    (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_ip_ext->delay)/100),
                    EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_ip_ext->bandwidth),
                    EXTRACT_24BITS(&tlv_ptr.eigrp_tlv_ip_ext->mtu),
                    tlv_ptr.eigrp_tlv_ip_ext->hopcount,
                    tlv_ptr.eigrp_tlv_ip_ext->reliability,
-                   tlv_ptr.eigrp_tlv_ip_ext->load);
+                   tlv_ptr.eigrp_tlv_ip_ext->load));
             break;
 
         case EIGRP_TLV_AT_CABLE_SETUP:
             tlv_ptr.eigrp_tlv_at_cable_setup = (const struct eigrp_tlv_at_cable_setup_t *)tlv_tptr;
 
-            printf("\n\t    Cable-range: %u-%u, Router-ID %u",
+            ND_PRINT((ndo, "\n\t    Cable-range: %u-%u, Router-ID %u",
                    EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_cable_setup->cable_start),
                    EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_cable_setup->cable_end),
-                   EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_at_cable_setup->router_id));
+                   EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_at_cable_setup->router_id)));
             break;
 
         case EIGRP_TLV_AT_INT:
             tlv_ptr.eigrp_tlv_at_int = (const struct eigrp_tlv_at_int_t *)tlv_tptr;
 
-            printf("\n\t     Cable-Range: %u-%u, nexthop: ",
+            ND_PRINT((ndo, "\n\t     Cable-Range: %u-%u, nexthop: ",
                    EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_int->cable_start),
-                   EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_int->cable_end));
+                   EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_int->cable_end)));
 
             if (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_at_int->nexthop) == 0)
-                printf("self");
+                ND_PRINT((ndo, "self"));
             else
-                printf("%u.%u",
+                ND_PRINT((ndo, "%u.%u",
                        EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_int->nexthop),
-                       EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_int->nexthop[2]));
+                       EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_int->nexthop[2])));
 
-            printf("\n\t      delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
+            ND_PRINT((ndo, "\n\t      delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
                    (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_at_int->delay)/100),
                    EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_at_int->bandwidth),
                    EXTRACT_24BITS(&tlv_ptr.eigrp_tlv_at_int->mtu),
                    tlv_ptr.eigrp_tlv_at_int->hopcount,
                    tlv_ptr.eigrp_tlv_at_int->reliability,
-                   tlv_ptr.eigrp_tlv_at_int->load);
+                   tlv_ptr.eigrp_tlv_at_int->load));
             break;
 
         case EIGRP_TLV_AT_EXT:
             tlv_ptr.eigrp_tlv_at_ext = (const struct eigrp_tlv_at_ext_t *)tlv_tptr;
 
-            printf("\n\t     Cable-Range: %u-%u, nexthop: ",
+            ND_PRINT((ndo, "\n\t     Cable-Range: %u-%u, nexthop: ",
                    EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_ext->cable_start),
-                   EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_ext->cable_end));
+                   EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_ext->cable_end)));
 
             if (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_at_ext->nexthop) == 0)
-                printf("self");
+                ND_PRINT((ndo, "self"));
             else
-                printf("%u.%u",
+                ND_PRINT((ndo, "%u.%u",
                        EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_ext->nexthop),
-                       EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_ext->nexthop[2]));
+                       EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_ext->nexthop[2])));
 
-            printf("\n\t      origin-router %u, origin-as %u, origin-proto %s, flags [0x%02x], tag 0x%08x, metric %u",
+            ND_PRINT((ndo, "\n\t      origin-router %u, origin-as %u, origin-proto %s, flags [0x%02x], tag 0x%08x, metric %u",
                    EXTRACT_32BITS(tlv_ptr.eigrp_tlv_at_ext->origin_router),
                    EXTRACT_32BITS(tlv_ptr.eigrp_tlv_at_ext->origin_as),
                    tok2str(eigrp_ext_proto_id_values,"unknown",tlv_ptr.eigrp_tlv_at_ext->proto_id),
                    tlv_ptr.eigrp_tlv_at_ext->flags,
                    EXTRACT_32BITS(tlv_ptr.eigrp_tlv_at_ext->tag),
-                   EXTRACT_16BITS(tlv_ptr.eigrp_tlv_at_ext->metric));
+                   EXTRACT_16BITS(tlv_ptr.eigrp_tlv_at_ext->metric)));
 
-            printf("\n\t      delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
+            ND_PRINT((ndo, "\n\t      delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
                    (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_at_ext->delay)/100),
                    EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_at_ext->bandwidth),
                    EXTRACT_24BITS(&tlv_ptr.eigrp_tlv_at_ext->mtu),
                    tlv_ptr.eigrp_tlv_at_ext->hopcount,
                    tlv_ptr.eigrp_tlv_at_ext->reliability,
-                   tlv_ptr.eigrp_tlv_at_ext->load);
+                   tlv_ptr.eigrp_tlv_at_ext->load));
             break;
 
             /*
@@ -457,13 +456,13 @@ eigrp_print(register const u_char *pptr, register u_int len) {
         case EIGRP_TLV_IPX_EXT:
 
         default:
-            if (vflag <= 1)
-                print_unknown_data(gndo,tlv_tptr,"\n\t    ",tlv_tlen);
+            if (ndo->ndo_vflag <= 1)
+                print_unknown_data(ndo,tlv_tptr,"\n\t    ",tlv_tlen);
             break;
         }
         /* do we want to see an additionally hexdump ? */
-        if (vflag > 1)
-            print_unknown_data(gndo,tptr+sizeof(struct eigrp_tlv_header),"\n\t    ",
+        if (ndo->ndo_vflag > 1)
+            print_unknown_data(ndo,tptr+sizeof(struct eigrp_tlv_header),"\n\t    ",
                                eigrp_tlv_len-sizeof(struct eigrp_tlv_header));
 
         tptr+=eigrp_tlv_len;
@@ -471,5 +470,5 @@ eigrp_print(register const u_char *pptr, register u_int len) {
     }
     return;
 trunc:
-    printf("\n\t\t packet exceeded snapshot");
+    ND_PRINT((ndo, "\n\t\t packet exceeded snapshot"));
 }
index 32357dfab607dfab7428e6a1d9e104b15520b15a..e680c01c5f5d57828b80e219e140cd5629641b2b 100644 (file)
@@ -19,6 +19,7 @@
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
+#define NETDISSECT_REWORKED
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -326,7 +327,8 @@ icmp_tstamp_print(u_int tstamp) {
 }
 
 void
-icmp_print(const u_char *bp, u_int plen, const u_char *bp2, int fragmented)
+icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char *bp2,
+           int fragmented)
 {
        char *cp;
        const struct icmp *dp;
@@ -348,12 +350,12 @@ icmp_print(const u_char *bp, u_int plen, const u_char *bp2, int fragmented)
        ip = (struct ip *)bp2;
        str = buf;
 
-       TCHECK(dp->icmp_code);
+       ND_TCHECK(dp->icmp_code);
        switch (dp->icmp_type) {
 
        case ICMP_ECHO:
        case ICMP_ECHOREPLY:
-               TCHECK(dp->icmp_seq);
+               ND_TCHECK(dp->icmp_seq);
                (void)snprintf(buf, sizeof(buf), "echo %s, id %u, seq %u",
                                dp->icmp_type == ICMP_ECHO ?
                                "request" : "reply",
@@ -362,11 +364,11 @@ icmp_print(const u_char *bp, u_int plen, const u_char *bp2, int fragmented)
                break;
 
        case ICMP_UNREACH:
-               TCHECK(dp->icmp_ip.ip_dst);
+               ND_TCHECK(dp->icmp_ip.ip_dst);
                switch (dp->icmp_code) {
 
                case ICMP_UNREACH_PROTOCOL:
-                       TCHECK(dp->icmp_ip.ip_p);
+                       ND_TCHECK(dp->icmp_ip.ip_p);
                        (void)snprintf(buf, sizeof(buf),
                            "%s protocol %d unreachable",
                            ipaddr_string(&dp->icmp_ip.ip_dst),
@@ -374,11 +376,11 @@ icmp_print(const u_char *bp, u_int plen, const u_char *bp2, int fragmented)
                        break;
 
                case ICMP_UNREACH_PORT:
-                       TCHECK(dp->icmp_ip.ip_p);
+                       ND_TCHECK(dp->icmp_ip.ip_p);
                        oip = &dp->icmp_ip;
                        hlen = IP_HL(oip) * 4;
                        ouh = (struct udphdr *)(((u_char *)oip) + hlen);
-                       TCHECK(ouh->uh_dport);
+                       ND_TCHECK(ouh->uh_dport);
                        dport = EXTRACT_16BITS(&ouh->uh_dport);
                        switch (oip->ip_p) {
 
@@ -432,7 +434,7 @@ icmp_print(const u_char *bp, u_int plen, const u_char *bp2, int fragmented)
                break;
 
        case ICMP_REDIRECT:
-               TCHECK(dp->icmp_ip.ip_dst);
+               ND_TCHECK(dp->icmp_ip.ip_dst);
                fmt = tok2str(type2str, "redirect-#%d %%s to net %%s",
                    dp->icmp_code);
                (void)snprintf(buf, sizeof(buf), fmt,
@@ -450,7 +452,7 @@ icmp_print(const u_char *bp, u_int plen, const u_char *bp2, int fragmented)
                cp = buf + strlen(buf);
 
                ihp = (struct ih_rdiscovery *)&dp->icmp_void;
-               TCHECK(*ihp);
+               ND_TCHECK(*ihp);
                (void)strncpy(cp, " lifetime ", sizeof(buf) - (cp - buf));
                cp = buf + strlen(buf);
                lifetime = EXTRACT_16BITS(&ihp->ird_lifetime);
@@ -481,7 +483,7 @@ icmp_print(const u_char *bp, u_int plen, const u_char *bp2, int fragmented)
                }
                idp = (struct id_rdiscovery *)&dp->icmp_data;
                while (num-- > 0) {
-                       TCHECK(*idp);
+                       ND_TCHECK(*idp);
                        (void)snprintf(cp, sizeof(buf) - (cp - buf), " {%s %u}",
                            ipaddr_string(&idp->ird_addr),
                            EXTRACT_32BITS(&idp->ird_pref));
@@ -492,7 +494,7 @@ icmp_print(const u_char *bp, u_int plen, const u_char *bp2, int fragmented)
                break;
 
        case ICMP_TIMXCEED:
-               TCHECK(dp->icmp_ip.ip_dst);
+               ND_TCHECK(dp->icmp_ip.ip_dst);
                switch (dp->icmp_code) {
 
                case ICMP_TIMXCEED_INTRANS:
@@ -515,20 +517,20 @@ icmp_print(const u_char *bp, u_int plen, const u_char *bp2, int fragmented)
                        (void)snprintf(buf, sizeof(buf),
                            "parameter problem - code %d", dp->icmp_code);
                else {
-                       TCHECK(dp->icmp_pptr);
+                       ND_TCHECK(dp->icmp_pptr);
                        (void)snprintf(buf, sizeof(buf),
                            "parameter problem - octet %d", dp->icmp_pptr);
                }
                break;
 
        case ICMP_MASKREPLY:
-               TCHECK(dp->icmp_mask);
+               ND_TCHECK(dp->icmp_mask);
                (void)snprintf(buf, sizeof(buf), "address mask is 0x%08x",
                    EXTRACT_32BITS(&dp->icmp_mask));
                break;
 
        case ICMP_TSTAMP:
-               TCHECK(dp->icmp_seq);
+               ND_TCHECK(dp->icmp_seq);
                (void)snprintf(buf, sizeof(buf),
                    "time stamp query id %u seq %u",
                    EXTRACT_16BITS(&dp->icmp_id),
@@ -536,7 +538,7 @@ icmp_print(const u_char *bp, u_int plen, const u_char *bp2, int fragmented)
                break;
 
        case ICMP_TSTAMPREPLY:
-               TCHECK(dp->icmp_ttime);
+               ND_TCHECK(dp->icmp_ttime);
                (void)snprintf(buf, sizeof(buf),
                    "time stamp reply id %u seq %u: org %s",
                                EXTRACT_16BITS(&dp->icmp_id),
@@ -553,19 +555,19 @@ icmp_print(const u_char *bp, u_int plen, const u_char *bp2, int fragmented)
                str = tok2str(icmp2str, "type-#%d", dp->icmp_type);
                break;
        }
-       (void)printf("ICMP %s, length %u", str, plen);
-       if (vflag && !fragmented) { /* don't attempt checksumming if this is a frag */
+       ND_PRINT((ndo, "ICMP %s, length %u", str, plen));
+       if (ndo->ndo_vflag && !fragmented) { /* don't attempt checksumming if this is a frag */
                u_int16_t sum, icmp_sum;
                struct cksum_vec vec[1];
-               if (TTEST2(*bp, plen)) {
+               if (ND_TTEST2(*bp, plen)) {
                        vec[0].ptr = (const u_int8_t *)(void *)dp;
                        vec[0].len = plen;
                        sum = in_cksum(vec, 1);
                        if (sum != 0) {
                                icmp_sum = EXTRACT_16BITS(&dp->icmp_cksum);
-                               (void)printf(" (wrong icmp cksum %x (->%x)!)",
+                               ND_PRINT((ndo, " (wrong icmp cksum %x (->%x)!)",
                                             icmp_sum,
-                                            in_cksum_shouldbe(icmp_sum, sum));
+                                            in_cksum_shouldbe(icmp_sum, sum)));
                        }
                }
        }
@@ -574,22 +576,22 @@ icmp_print(const u_char *bp, u_int plen, const u_char *bp2, int fragmented)
          * print the remnants of the IP packet.
          * save the snaplength as this may get overidden in the IP printer.
          */
-       if (vflag >= 1 && !ICMP_INFOTYPE(dp->icmp_type)) {
+       if (ndo->ndo_vflag >= 1 && !ICMP_INFOTYPE(dp->icmp_type)) {
                bp += 8;
-               (void)printf("\n\t");
+               ND_PRINT((ndo, "\n\t"));
                ip = (struct ip *)bp;
-               snaplen = snapend - bp;
-                snapend_save = snapend;
-               ip_print(gndo, bp, EXTRACT_16BITS(&ip->ip_len));
-                snapend = snapend_save;
+               ndo->ndo_snaplen = ndo->ndo_snapend - bp;
+                snapend_save = ndo->ndo_snapend;
+               ip_print(ndo, bp, EXTRACT_16BITS(&ip->ip_len));
+                ndo->ndo_snapend = snapend_save;
        }
 
         /*
          * Attempt to decode the MPLS extensions only for some ICMP types.
          */
-        if (vflag >= 1 && plen > ICMP_EXTD_MINLEN && ICMP_MPLS_EXT_TYPE(dp->icmp_type)) {
+        if (ndo->ndo_vflag >= 1 && plen > ICMP_EXTD_MINLEN && ICMP_MPLS_EXT_TYPE(dp->icmp_type)) {
 
-            TCHECK(*ext_dp);
+            ND_TCHECK(*ext_dp);
 
             /*
              * Check first if the mpls extension header shows a non-zero length.
@@ -605,25 +607,25 @@ icmp_print(const u_char *bp, u_int plen, const u_char *bp2, int fragmented)
                 }
             }
 
-            printf("\n\tMPLS extension v%u",
-                   ICMP_MPLS_EXT_EXTRACT_VERSION(*(ext_dp->icmp_ext_version_res)));
+            ND_PRINT((ndo, "\n\tMPLS extension v%u",
+                   ICMP_MPLS_EXT_EXTRACT_VERSION(*(ext_dp->icmp_ext_version_res))));
 
             /*
              * Sanity checking of the header.
              */
             if (ICMP_MPLS_EXT_EXTRACT_VERSION(*(ext_dp->icmp_ext_version_res)) !=
                 ICMP_MPLS_EXT_VERSION) {
-                printf(" packet not supported");
+                ND_PRINT((ndo, " packet not supported"));
                 return;
             }
 
             hlen = plen - ICMP_EXTD_MINLEN;
             vec[0].ptr = (const u_int8_t *)(void *)&ext_dp->icmp_ext_version_res;
             vec[0].len = hlen;
-            printf(", checksum 0x%04x (%scorrect), length %u",
+            ND_PRINT((ndo, ", checksum 0x%04x (%scorrect), length %u",
                    EXTRACT_16BITS(ext_dp->icmp_ext_checksum),
                    in_cksum(vec, 1) ? "in" : "",
-                   hlen);
+                   hlen));
 
             hlen -= 4; /* subtract common header size */
             obj_tptr = (u_int8_t *)ext_dp->icmp_ext_data;
@@ -631,17 +633,17 @@ icmp_print(const u_char *bp, u_int plen, const u_char *bp2, int fragmented)
             while (hlen > sizeof(struct icmp_mpls_ext_object_header_t)) {
 
                 icmp_mpls_ext_object_header = (struct icmp_mpls_ext_object_header_t *)obj_tptr;
-                TCHECK(*icmp_mpls_ext_object_header);
+                ND_TCHECK(*icmp_mpls_ext_object_header);
                 obj_tlen = EXTRACT_16BITS(icmp_mpls_ext_object_header->length);
                 obj_class_num = icmp_mpls_ext_object_header->class_num;
                 obj_ctype = icmp_mpls_ext_object_header->ctype;
                 obj_tptr += sizeof(struct icmp_mpls_ext_object_header_t);
 
-                printf("\n\t  %s Object (%u), Class-Type: %u, length %u",
+                ND_PRINT((ndo, "\n\t  %s Object (%u), Class-Type: %u, length %u",
                        tok2str(icmp_mpls_ext_obj_values,"unknown",obj_class_num),
                        obj_class_num,
                        obj_ctype,
-                       obj_tlen);
+                       obj_tlen));
 
                 hlen-=sizeof(struct icmp_mpls_ext_object_header_t); /* length field includes tlv header */
 
@@ -656,15 +658,15 @@ icmp_print(const u_char *bp, u_int plen, const u_char *bp2, int fragmented)
                 case 1:
                     switch(obj_ctype) {
                     case 1:
-                        TCHECK2(*obj_tptr, 4);
+                        ND_TCHECK2(*obj_tptr, 4);
                         raw_label = EXTRACT_32BITS(obj_tptr);
-                        printf("\n\t    label %u, exp %u", MPLS_LABEL(raw_label), MPLS_EXP(raw_label));
+                        ND_PRINT((ndo, "\n\t    label %u, exp %u", MPLS_LABEL(raw_label), MPLS_EXP(raw_label)));
                         if (MPLS_STACK(raw_label))
-                            printf(", [S]");
-                        printf(", ttl %u", MPLS_TTL(raw_label));
+                            ND_PRINT((ndo, ", [S]"));
+                        ND_PRINT((ndo, ", ttl %u", MPLS_TTL(raw_label)));
                         break;
                     default:
-                        print_unknown_data(gndo,obj_tptr, "\n\t    ", obj_tlen);
+                        print_unknown_data(ndo, obj_tptr, "\n\t    ", obj_tlen);
                     }
                     break;
 
@@ -674,7 +676,7 @@ icmp_print(const u_char *bp, u_int plen, const u_char *bp2, int fragmented)
                 */
                 case 2:
                 default:
-                    print_unknown_data(gndo,obj_tptr, "\n\t    ", obj_tlen);
+                    print_unknown_data(ndo, obj_tptr, "\n\t    ", obj_tlen);
                     break;
                 }
                 if (hlen < obj_tlen)
index 2970c1266f3945bcff244155e37acda7708dba7a..540e0b7c1ef1c51a454314a0e3d01b3aea127770 100644 (file)
@@ -376,13 +376,13 @@ again:
 
        case IPPROTO_UDP:
                /* pass on the MF bit plus the offset to detect fragments */
-               udp_print(ipds->cp, ipds->len, (const u_char *)ipds->ip,
+               udp_print(ndo, ipds->cp, ipds->len, (const u_char *)ipds->ip,
                          ipds->off & (IP_MF|IP_OFFMASK));
                break;
 
        case IPPROTO_ICMP:
                /* pass on the MF bit plus the offset to detect fragments */
-               icmp_print(ipds->cp, ipds->len, (const u_char *)ipds->ip,
+               icmp_print(ndo, ipds->cp, ipds->len, (const u_char *)ipds->ip,
                           ipds->off & (IP_MF|IP_OFFMASK));
                break;
 
@@ -404,7 +404,7 @@ again:
                break;
 
        case IPPROTO_EIGRP:
-               eigrp_print(ipds->cp, ipds->len);
+               eigrp_print(ndo, ipds->cp, ipds->len);
                break;
 
        case IPPROTO_ND:
index 1d37e0d1b3f9930b5c01c7290db33e3287f71496..8c3a7238018ea784c910d0b9008e3fc4fc5163f7 100644 (file)
@@ -197,7 +197,7 @@ ip6_print(netdissect_options *ndo, const u_char *bp, u_int length)
                        tcp_print(cp, len, (const u_char *)ip6, fragmented);
                        return;
                case IPPROTO_UDP:
-                       udp_print(cp, len, (const u_char *)ip6, fragmented);
+                       udp_print(ndo, cp, len, (const u_char *)ip6, fragmented);
                        return;
                case IPPROTO_ICMPV6:
                        icmp6_print(ndo, cp, len, (const u_char *)ip6, fragmented);
index 7404dd79c86f6bad5f370b32afac226e86d231c9..da3fb51de510147a09276938561fbb442f115e31 100644 (file)
@@ -138,7 +138,7 @@ ipx_decode(netdissect_options *ndo, const struct ipxHdr *ipx, const u_char *data
 #endif
        break;
       case IPX_SKT_EIGRP:
-       eigrp_print(datap, length);
+       eigrp_print(ndo, datap, length);
        break;
       default:
        ND_PRINT((ndo, "ipx-#%x %d", dstSkt, length));
index ca98e9a9b8016893da21dbe764ff62663640198b..8dde75d1e7e7f5338fac0ff4cfde5ffc06354f20 100644 (file)
  * L2TP support contributed by Motonori Shindo ([email protected])
  */
 
+#define NETDISSECT_REWORKED
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
 #include <tcpdump-stdinc.h>
 
-#include <stdio.h>
-
 #include "interface.h"
 #include "extract.h"
 
@@ -264,157 +263,157 @@ static char *l2tp_error_code_general[] = {
 /* generic print out routines */
 /******************************/
 static void
-print_string(const u_char *dat, u_int length)
+print_string(netdissect_options *ndo, const u_char *dat, u_int length)
 {
        u_int i;
        for (i=0; i<length; i++) {
-               printf("%c", *dat++);
+               ND_PRINT((ndo, "%c", *dat++));
        }
 }
 
 static void
-print_octets(const u_char *dat, u_int length)
+print_octets(netdissect_options *ndo, const u_char *dat, u_int length)
 {
        u_int i;
        for (i=0; i<length; i++) {
-               printf("%02x", *dat++);
+               ND_PRINT((ndo, "%02x", *dat++));
        }
 }
 
 static void
-print_16bits_val(const u_int16_t *dat)
+print_16bits_val(netdissect_options *ndo, const u_int16_t *dat)
 {
-       printf("%u", EXTRACT_16BITS(dat));
+       ND_PRINT((ndo, "%u", EXTRACT_16BITS(dat)));
 }
 
 static void
-print_32bits_val(const u_int32_t *dat)
+print_32bits_val(netdissect_options *ndo, const u_int32_t *dat)
 {
-       printf("%lu", (u_long)EXTRACT_32BITS(dat));
+       ND_PRINT((ndo, "%lu", (u_long)EXTRACT_32BITS(dat)));
 }
 
 /***********************************/
 /* AVP-specific print out routines */
 /***********************************/
 static void
-l2tp_msgtype_print(const u_char *dat)
+l2tp_msgtype_print(netdissect_options *ndo, const u_char *dat)
 {
        u_int16_t *ptr = (u_int16_t*)dat;
 
-       printf("%s", tok2str(l2tp_msgtype2str, "MSGTYPE-#%u",
-           EXTRACT_16BITS(ptr)));
+       ND_PRINT((ndo, "%s", tok2str(l2tp_msgtype2str, "MSGTYPE-#%u",
+           EXTRACT_16BITS(ptr))));
 }
 
 static void
-l2tp_result_code_print(const u_char *dat, u_int length)
+l2tp_result_code_print(netdissect_options *ndo, const u_char *dat, u_int length)
 {
        u_int16_t *ptr = (u_int16_t *)dat;
 
-       printf("%u", EXTRACT_16BITS(ptr)); ptr++;       /* Result Code */
+       ND_PRINT((ndo, "%u", EXTRACT_16BITS(ptr))); ptr++;      /* Result Code */
        if (length > 2) {                               /* Error Code (opt) */
-               printf("/%u", EXTRACT_16BITS(ptr)); ptr++;
+               ND_PRINT((ndo, "/%u", EXTRACT_16BITS(ptr))); ptr++;
        }
        if (length > 4) {                               /* Error Message (opt) */
-               printf(" ");
-               print_string((u_char *)ptr, length - 4);
+               ND_PRINT((ndo, " "));
+               print_string(ndo, (u_char *)ptr, length - 4);
        }
 }
 
 static void
-l2tp_proto_ver_print(const u_int16_t *dat)
+l2tp_proto_ver_print(netdissect_options *ndo, const u_int16_t *dat)
 {
-       printf("%u.%u", (EXTRACT_16BITS(dat) >> 8),
-           (EXTRACT_16BITS(dat) & 0xff));
+       ND_PRINT((ndo, "%u.%u", (EXTRACT_16BITS(dat) >> 8),
+           (EXTRACT_16BITS(dat) & 0xff)));
 }
 
 static void
-l2tp_framing_cap_print(const u_char *dat)
+l2tp_framing_cap_print(netdissect_options *ndo, const u_char *dat)
 {
        u_int32_t *ptr = (u_int32_t *)dat;
 
        if (EXTRACT_32BITS(ptr) &  L2TP_FRAMING_CAP_ASYNC_MASK) {
-               printf("A");
+               ND_PRINT((ndo, "A"));
        }
        if (EXTRACT_32BITS(ptr) &  L2TP_FRAMING_CAP_SYNC_MASK) {
-               printf("S");
+               ND_PRINT((ndo, "S"));
        }
 }
 
 static void
-l2tp_bearer_cap_print(const u_char *dat)
+l2tp_bearer_cap_print(netdissect_options *ndo, const u_char *dat)
 {
        u_int32_t *ptr = (u_int32_t *)dat;
 
        if (EXTRACT_32BITS(ptr) &  L2TP_BEARER_CAP_ANALOG_MASK) {
-               printf("A");
+               ND_PRINT((ndo, "A"));
        }
        if (EXTRACT_32BITS(ptr) &  L2TP_BEARER_CAP_DIGITAL_MASK) {
-               printf("D");
+               ND_PRINT((ndo, "D"));
        }
 }
 
 static void
-l2tp_q931_cc_print(const u_char *dat, u_int length)
+l2tp_q931_cc_print(netdissect_options *ndo, const u_char *dat, u_int length)
 {
-       print_16bits_val((u_int16_t *)dat);
-       printf(", %02x", dat[2]);
+       print_16bits_val(ndo, (u_int16_t *)dat);
+       ND_PRINT((ndo, ", %02x", dat[2]));
        if (length > 3) {
-               printf(" ");
-               print_string(dat+3, length-3);
+               ND_PRINT((ndo, " "));
+               print_string(ndo, dat+3, length-3);
        }
 }
 
 static void
-l2tp_bearer_type_print(const u_char *dat)
+l2tp_bearer_type_print(netdissect_options *ndo, const u_char *dat)
 {
        u_int32_t *ptr = (u_int32_t *)dat;
 
        if (EXTRACT_32BITS(ptr) &  L2TP_BEARER_TYPE_ANALOG_MASK) {
-               printf("A");
+               ND_PRINT((ndo, "A"));
        }
        if (EXTRACT_32BITS(ptr) &  L2TP_BEARER_TYPE_DIGITAL_MASK) {
-               printf("D");
+               ND_PRINT((ndo, "D"));
        }
 }
 
 static void
-l2tp_framing_type_print(const u_char *dat)
+l2tp_framing_type_print(netdissect_options *ndo, const u_char *dat)
 {
        u_int32_t *ptr = (u_int32_t *)dat;
 
        if (EXTRACT_32BITS(ptr) &  L2TP_FRAMING_TYPE_ASYNC_MASK) {
-               printf("A");
+               ND_PRINT((ndo, "A"));
        }
        if (EXTRACT_32BITS(ptr) &  L2TP_FRAMING_TYPE_SYNC_MASK) {
-               printf("S");
+               ND_PRINT((ndo, "S"));
        }
 }
 
 static void
-l2tp_packet_proc_delay_print(void)
+l2tp_packet_proc_delay_print(netdissect_options *ndo)
 {
-       printf("obsolete");
+       ND_PRINT((ndo, "obsolete"));
 }
 
 static void
-l2tp_proxy_auth_type_print(const u_char *dat)
+l2tp_proxy_auth_type_print(netdissect_options *ndo, const u_char *dat)
 {
        u_int16_t *ptr = (u_int16_t *)dat;
 
-       printf("%s", tok2str(l2tp_authentype2str,
-                            "AuthType-#%u", EXTRACT_16BITS(ptr)));
+       ND_PRINT((ndo, "%s", tok2str(l2tp_authentype2str,
+                            "AuthType-#%u", EXTRACT_16BITS(ptr))));
 }
 
 static void
-l2tp_proxy_auth_id_print(const u_char *dat)
+l2tp_proxy_auth_id_print(netdissect_options *ndo, const u_char *dat)
 {
        u_int16_t *ptr = (u_int16_t *)dat;
 
-       printf("%u", EXTRACT_16BITS(ptr) & L2TP_PROXY_AUTH_ID_MASK);
+       ND_PRINT((ndo, "%u", EXTRACT_16BITS(ptr) & L2TP_PROXY_AUTH_ID_MASK));
 }
 
 static void
-l2tp_call_errors_print(const u_char *dat)
+l2tp_call_errors_print(netdissect_options *ndo, const u_char *dat)
 {
        u_int16_t *ptr = (u_int16_t *)dat;
        u_int16_t val_h, val_l;
@@ -423,31 +422,31 @@ l2tp_call_errors_print(const u_char *dat)
 
        val_h = EXTRACT_16BITS(ptr); ptr++;
        val_l = EXTRACT_16BITS(ptr); ptr++;
-       printf("CRCErr=%u ", (val_h<<16) + val_l);
+       ND_PRINT((ndo, "CRCErr=%u ", (val_h<<16) + val_l));
 
        val_h = EXTRACT_16BITS(ptr); ptr++;
        val_l = EXTRACT_16BITS(ptr); ptr++;
-       printf("FrameErr=%u ", (val_h<<16) + val_l);
+       ND_PRINT((ndo, "FrameErr=%u ", (val_h<<16) + val_l));
 
        val_h = EXTRACT_16BITS(ptr); ptr++;
        val_l = EXTRACT_16BITS(ptr); ptr++;
-       printf("HardOver=%u ", (val_h<<16) + val_l);
+       ND_PRINT((ndo, "HardOver=%u ", (val_h<<16) + val_l));
 
        val_h = EXTRACT_16BITS(ptr); ptr++;
        val_l = EXTRACT_16BITS(ptr); ptr++;
-       printf("BufOver=%u ", (val_h<<16) + val_l);
+       ND_PRINT((ndo, "BufOver=%u ", (val_h<<16) + val_l));
 
        val_h = EXTRACT_16BITS(ptr); ptr++;
        val_l = EXTRACT_16BITS(ptr); ptr++;
-       printf("Timeout=%u ", (val_h<<16) + val_l);
+       ND_PRINT((ndo, "Timeout=%u ", (val_h<<16) + val_l));
 
        val_h = EXTRACT_16BITS(ptr); ptr++;
        val_l = EXTRACT_16BITS(ptr); ptr++;
-       printf("AlignErr=%u ", (val_h<<16) + val_l);
+       ND_PRINT((ndo, "AlignErr=%u ", (val_h<<16) + val_l));
 }
 
 static void
-l2tp_accm_print(const u_char *dat)
+l2tp_accm_print(netdissect_options *ndo, const u_char *dat)
 {
        u_int16_t *ptr = (u_int16_t *)dat;
        u_int16_t val_h, val_l;
@@ -456,31 +455,31 @@ l2tp_accm_print(const u_char *dat)
 
        val_h = EXTRACT_16BITS(ptr); ptr++;
        val_l = EXTRACT_16BITS(ptr); ptr++;
-       printf("send=%08x ", (val_h<<16) + val_l);
+       ND_PRINT((ndo, "send=%08x ", (val_h<<16) + val_l));
 
        val_h = EXTRACT_16BITS(ptr); ptr++;
        val_l = EXTRACT_16BITS(ptr); ptr++;
-       printf("recv=%08x ", (val_h<<16) + val_l);
+       ND_PRINT((ndo, "recv=%08x ", (val_h<<16) + val_l));
 }
 
 static void
-l2tp_ppp_discon_cc_print(const u_char *dat, u_int length)
+l2tp_ppp_discon_cc_print(netdissect_options *ndo, const u_char *dat, u_int length)
 {
        u_int16_t *ptr = (u_int16_t *)dat;
 
-       printf("%04x, ", EXTRACT_16BITS(ptr)); ptr++;   /* Disconnect Code */
-       printf("%04x ",  EXTRACT_16BITS(ptr)); ptr++;   /* Control Protocol Number */
-       printf("%s", tok2str(l2tp_cc_direction2str,
-                            "Direction-#%u", *((u_char *)ptr++)));
+       ND_PRINT((ndo, "%04x, ", EXTRACT_16BITS(ptr))); ptr++;  /* Disconnect Code */
+       ND_PRINT((ndo, "%04x ",  EXTRACT_16BITS(ptr))); ptr++;  /* Control Protocol Number */
+       ND_PRINT((ndo, "%s", tok2str(l2tp_cc_direction2str,
+                            "Direction-#%u", *((u_char *)ptr++))));
 
        if (length > 5) {
-               printf(" ");
-               print_string((const u_char *)ptr, length-5);
+               ND_PRINT((ndo, " "));
+               print_string(ndo, (const u_char *)ptr, length-5);
        }
 }
 
 static void
-l2tp_avp_print(const u_char *dat, int length)
+l2tp_avp_print(netdissect_options *ndo, const u_char *dat, int length)
 {
        u_int len;
        const u_int16_t *ptr = (u_int16_t *)dat;
@@ -491,9 +490,9 @@ l2tp_avp_print(const u_char *dat, int length)
                return;
        }
 
-       printf(" ");
+       ND_PRINT((ndo, " "));
 
-       TCHECK(*ptr);   /* Flags & Length */
+       ND_TCHECK(*ptr);        /* Flags & Length */
        len = EXTRACT_16BITS(ptr) & L2TP_AVP_HDR_LEN_MASK;
 
        /* If it is not long enough to contain the header, we'll give up. */
@@ -507,58 +506,58 @@ l2tp_avp_print(const u_char *dat, int length)
 
        /* If it goes past the end of the remaining length of the captured
           data, we'll give up. */
-       TCHECK2(*ptr, len);
+       ND_TCHECK2(*ptr, len);
        /* After this point, no need to worry about truncation */
 
        if (EXTRACT_16BITS(ptr) & L2TP_AVP_HDR_FLAG_MANDATORY) {
-               printf("*");
+               ND_PRINT((ndo, "*"));
        }
        if (EXTRACT_16BITS(ptr) & L2TP_AVP_HDR_FLAG_HIDDEN) {
                hidden = TRUE;
-               printf("?");
+               ND_PRINT((ndo, "?"));
        }
        ptr++;
 
        if (EXTRACT_16BITS(ptr)) {
                /* Vendor Specific Attribute */
-               printf("VENDOR%04x:", EXTRACT_16BITS(ptr)); ptr++;
-               printf("ATTR%04x", EXTRACT_16BITS(ptr)); ptr++;
-               printf("(");
-               print_octets((u_char *)ptr, len-6);
-               printf(")");
+               ND_PRINT((ndo, "VENDOR%04x:", EXTRACT_16BITS(ptr))); ptr++;
+               ND_PRINT((ndo, "ATTR%04x", EXTRACT_16BITS(ptr))); ptr++;
+               ND_PRINT((ndo, "("));
+               print_octets(ndo, (u_char *)ptr, len-6);
+               ND_PRINT((ndo, ")"));
        } else {
                /* IETF-defined Attributes */
                ptr++;
                attr_type = EXTRACT_16BITS(ptr); ptr++;
-               printf("%s", tok2str(l2tp_avp2str, "AVP-#%u", attr_type));
-               printf("(");
+               ND_PRINT((ndo, "%s", tok2str(l2tp_avp2str, "AVP-#%u", attr_type)));
+               ND_PRINT((ndo, "("));
                if (hidden) {
-                       printf("???");
+                       ND_PRINT((ndo, "???"));
                } else {
                        switch (attr_type) {
                        case L2TP_AVP_MSGTYPE:
-                               l2tp_msgtype_print((u_char *)ptr);
+                               l2tp_msgtype_print(ndo, (u_char *)ptr);
                                break;
                        case L2TP_AVP_RESULT_CODE:
-                               l2tp_result_code_print((u_char *)ptr, len-6);
+                               l2tp_result_code_print(ndo, (u_char *)ptr, len-6);
                                break;
                        case L2TP_AVP_PROTO_VER:
-                               l2tp_proto_ver_print(ptr);
+                               l2tp_proto_ver_print(ndo, ptr);
                                break;
                        case L2TP_AVP_FRAMING_CAP:
-                               l2tp_framing_cap_print((u_char *)ptr);
+                               l2tp_framing_cap_print(ndo, (u_char *)ptr);
                                break;
                        case L2TP_AVP_BEARER_CAP:
-                               l2tp_bearer_cap_print((u_char *)ptr);
+                               l2tp_bearer_cap_print(ndo, (u_char *)ptr);
                                break;
                        case L2TP_AVP_TIE_BREAKER:
-                               print_octets((u_char *)ptr, 8);
+                               print_octets(ndo, (u_char *)ptr, 8);
                                break;
                        case L2TP_AVP_FIRM_VER:
                        case L2TP_AVP_ASSND_TUN_ID:
                        case L2TP_AVP_RECV_WIN_SIZE:
                        case L2TP_AVP_ASSND_SESS_ID:
-                               print_16bits_val(ptr);
+                               print_16bits_val(ndo, ptr);
                                break;
                        case L2TP_AVP_HOST_NAME:
                        case L2TP_AVP_VENDOR_NAME:
@@ -567,7 +566,7 @@ l2tp_avp_print(const u_char *dat, int length)
                        case L2TP_AVP_SUB_ADDRESS:
                        case L2TP_AVP_PROXY_AUTH_NAME:
                        case L2TP_AVP_PRIVATE_GRP_ID:
-                               print_string((u_char *)ptr, len-6);
+                               print_string(ndo, (u_char *)ptr, len-6);
                                break;
                        case L2TP_AVP_CHALLENGE:
                        case L2TP_AVP_INI_RECV_LCP:
@@ -576,13 +575,13 @@ l2tp_avp_print(const u_char *dat, int length)
                        case L2TP_AVP_PROXY_AUTH_CHAL:
                        case L2TP_AVP_PROXY_AUTH_RESP:
                        case L2TP_AVP_RANDOM_VECTOR:
-                               print_octets((u_char *)ptr, len-6);
+                               print_octets(ndo, (u_char *)ptr, len-6);
                                break;
                        case L2TP_AVP_Q931_CC:
-                               l2tp_q931_cc_print((u_char *)ptr, len-6);
+                               l2tp_q931_cc_print(ndo, (u_char *)ptr, len-6);
                                break;
                        case L2TP_AVP_CHALLENGE_RESP:
-                               print_octets((u_char *)ptr, 16);
+                               print_octets(ndo, (u_char *)ptr, 16);
                                break;
                        case L2TP_AVP_CALL_SER_NUM:
                        case L2TP_AVP_MINIMUM_BPS:
@@ -590,51 +589,51 @@ l2tp_avp_print(const u_char *dat, int length)
                        case L2TP_AVP_TX_CONN_SPEED:
                        case L2TP_AVP_PHY_CHANNEL_ID:
                        case L2TP_AVP_RX_CONN_SPEED:
-                               print_32bits_val((u_int32_t *)ptr);
+                               print_32bits_val(ndo, (u_int32_t *)ptr);
                                break;
                        case L2TP_AVP_BEARER_TYPE:
-                               l2tp_bearer_type_print((u_char *)ptr);
+                               l2tp_bearer_type_print(ndo, (u_char *)ptr);
                                break;
                        case L2TP_AVP_FRAMING_TYPE:
-                               l2tp_framing_type_print((u_char *)ptr);
+                               l2tp_framing_type_print(ndo, (u_char *)ptr);
                                break;
                        case L2TP_AVP_PACKET_PROC_DELAY:
-                               l2tp_packet_proc_delay_print();
+                               l2tp_packet_proc_delay_print(ndo);
                                break;
                        case L2TP_AVP_PROXY_AUTH_TYPE:
-                               l2tp_proxy_auth_type_print((u_char *)ptr);
+                               l2tp_proxy_auth_type_print(ndo, (u_char *)ptr);
                                break;
                        case L2TP_AVP_PROXY_AUTH_ID:
-                               l2tp_proxy_auth_id_print((u_char *)ptr);
+                               l2tp_proxy_auth_id_print(ndo, (u_char *)ptr);
                                break;
                        case L2TP_AVP_CALL_ERRORS:
-                               l2tp_call_errors_print((u_char *)ptr);
+                               l2tp_call_errors_print(ndo, (u_char *)ptr);
                                break;
                        case L2TP_AVP_ACCM:
-                               l2tp_accm_print((u_char *)ptr);
+                               l2tp_accm_print(ndo, (u_char *)ptr);
                                break;
                        case L2TP_AVP_SEQ_REQUIRED:
                                break;  /* No Attribute Value */
                        case L2TP_AVP_PPP_DISCON_CC:
-                               l2tp_ppp_discon_cc_print((u_char *)ptr, len-6);
+                               l2tp_ppp_discon_cc_print(ndo, (u_char *)ptr, len-6);
                                break;
                        default:
                                break;
                        }
                }
-               printf(")");
+               ND_PRINT((ndo, ")"));
        }
 
-       l2tp_avp_print(dat+len, length-len);
+       l2tp_avp_print(ndo, dat+len, length-len);
        return;
 
  trunc:
-       printf("|...");
+       ND_PRINT((ndo, "|..."));
 }
 
 
 void
-l2tp_print(const u_char *dat, u_int length)
+l2tp_print(netdissect_options *ndo, const u_char *dat, u_int length)
 {
        const u_char *ptr = dat;
        u_int cnt = 0;                  /* total octets consumed */
@@ -644,43 +643,43 @@ l2tp_print(const u_char *dat, u_int length)
 
        flag_t = flag_l = flag_s = flag_o = FALSE;
 
-       TCHECK2(*ptr, 2);       /* Flags & Version */
+       ND_TCHECK2(*ptr, 2);    /* Flags & Version */
        if ((EXTRACT_16BITS(ptr) & L2TP_VERSION_MASK) == L2TP_VERSION_L2TP) {
-               printf(" l2tp:");
+               ND_PRINT((ndo, " l2tp:"));
        } else if ((EXTRACT_16BITS(ptr) & L2TP_VERSION_MASK) == L2TP_VERSION_L2F) {
-               printf(" l2f:");
+               ND_PRINT((ndo, " l2f:"));
                return;         /* nothing to do */
        } else {
-               printf(" Unknown Version, neither L2F(1) nor L2TP(2)");
+               ND_PRINT((ndo, " Unknown Version, neither L2F(1) nor L2TP(2)"));
                return;         /* nothing we can do */
        }
 
-       printf("[");
+       ND_PRINT((ndo, "["));
        if (EXTRACT_16BITS(ptr) & L2TP_FLAG_TYPE) {
                flag_t = TRUE;
-               printf("T");
+               ND_PRINT((ndo, "T"));
        }
        if (EXTRACT_16BITS(ptr) & L2TP_FLAG_LENGTH) {
                flag_l = TRUE;
-               printf("L");
+               ND_PRINT((ndo, "L"));
        }
        if (EXTRACT_16BITS(ptr) & L2TP_FLAG_SEQUENCE) {
                flag_s = TRUE;
-               printf("S");
+               ND_PRINT((ndo, "S"));
        }
        if (EXTRACT_16BITS(ptr) & L2TP_FLAG_OFFSET) {
                flag_o = TRUE;
-               printf("O");
+               ND_PRINT((ndo, "O"));
        }
        if (EXTRACT_16BITS(ptr) & L2TP_FLAG_PRIORITY)
-               printf("P");
-       printf("]");
+               ND_PRINT((ndo, "P"));
+       ND_PRINT((ndo, "]"));
 
        ptr += 2;
        cnt += 2;
 
        if (flag_l) {
-               TCHECK2(*ptr, 2);       /* Length */
+               ND_TCHECK2(*ptr, 2);    /* Length */
                l2tp_len = EXTRACT_16BITS(ptr);
                ptr += 2;
                cnt += 2;
@@ -688,28 +687,28 @@ l2tp_print(const u_char *dat, u_int length)
                l2tp_len = 0;
        }
 
-       TCHECK2(*ptr, 2);               /* Tunnel ID */
-       printf("(%u/", EXTRACT_16BITS(ptr));
+       ND_TCHECK2(*ptr, 2);            /* Tunnel ID */
+       ND_PRINT((ndo, "(%u/", EXTRACT_16BITS(ptr)));
        ptr += 2;
        cnt += 2;
-       TCHECK2(*ptr, 2);               /* Session ID */
-       printf("%u)",  EXTRACT_16BITS(ptr));
+       ND_TCHECK2(*ptr, 2);            /* Session ID */
+       ND_PRINT((ndo, "%u)",  EXTRACT_16BITS(ptr)));
        ptr += 2;
        cnt += 2;
 
        if (flag_s) {
-               TCHECK2(*ptr, 2);       /* Ns */
-               printf("Ns=%u,", EXTRACT_16BITS(ptr));
+               ND_TCHECK2(*ptr, 2);    /* Ns */
+               ND_PRINT((ndo, "Ns=%u,", EXTRACT_16BITS(ptr)));
                ptr += 2;
                cnt += 2;
-               TCHECK2(*ptr, 2);       /* Nr */
-               printf("Nr=%u",  EXTRACT_16BITS(ptr));
+               ND_TCHECK2(*ptr, 2);    /* Nr */
+               ND_PRINT((ndo, "Nr=%u",  EXTRACT_16BITS(ptr)));
                ptr += 2;
                cnt += 2;
        }
 
        if (flag_o) {
-               TCHECK2(*ptr, 2);       /* Offset Size */
+               ND_TCHECK2(*ptr, 2);    /* Offset Size */
                pad =  EXTRACT_16BITS(ptr);
                ptr += (2 + pad);
                cnt += (2 + pad);
@@ -717,33 +716,33 @@ l2tp_print(const u_char *dat, u_int length)
 
        if (flag_l) {
                if (length < l2tp_len) {
-                       printf(" Length %u larger than packet", l2tp_len);
+                       ND_PRINT((ndo, " Length %u larger than packet", l2tp_len));
                        return;
                }
                length = l2tp_len;
        }
        if (length < cnt) {
-               printf(" Length %u smaller than header length", length);
+               ND_PRINT((ndo, " Length %u smaller than header length", length));
                return;
        }
        if (flag_t) {
                if (!flag_l) {
-                       printf(" No length");
+                       ND_PRINT((ndo, " No length"));
                        return;
                }
                if (length - cnt == 0) {
-                       printf(" ZLB");
+                       ND_PRINT((ndo, " ZLB"));
                } else {
-                       l2tp_avp_print(ptr, length - cnt);
+                       l2tp_avp_print(ndo, ptr, length - cnt);
                }
        } else {
-               printf(" {");
+               ND_PRINT((ndo, " {"));
                ppp_print(ptr, length - cnt);
-               printf("}");
+               ND_PRINT((ndo, "}"));
        }
 
        return;
 
  trunc:
-       printf("%s", tstr);
+       ND_PRINT((ndo, "%s", tstr));
 }
index 590496a36262f847dcdef811c552884dd8a0a999..59e48df98910ae55800cd582b346f4b4e83dd4e0 100644 (file)
@@ -234,7 +234,7 @@ llc_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen,
 
        if (ssap == LLCSAP_8021D && dsap == LLCSAP_8021D &&
            control == LLC_UI) {
-               stp_print(p+3, length-3);
+               stp_print(ndo, p+3, length-3);
                return (1);
        }
 
@@ -438,7 +438,7 @@ snap_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen,
                         return (1);
                 case PID_CISCO_PVST:
                 case PID_CISCO_VLANBRIDGE:
-                        stp_print(p, length);
+                        stp_print(ndo, p, length);
                         return (1);
                 default:
                         break;
@@ -510,7 +510,7 @@ snap_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen,
                        return (1);
 
                case PID_RFC2684_BPDU:
-                       stp_print(p, length);
+                       stp_print(ndo, p, length);
                        return (1);
                }
        }
index 7c4bede6e509ea64c803ba88f713a3814f0708da..5cbf5d752e8385794a52484874ff421eb5428441 100644 (file)
@@ -9,15 +9,14 @@
  * Contributed by Lennert Buytenhek <[email protected]>
  */
 
+#define NETDISSECT_REWORKED
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
 #include <tcpdump-stdinc.h>
 
-#include <stdlib.h>
 #include <stdio.h>
-#include <string.h>
 
 #include "interface.h"
 #include "extract.h"
@@ -98,36 +97,37 @@ stp_print_bridge_id(const u_char *p)
 }
 
 static void
-stp_print_config_bpdu(const struct stp_bpdu_ *stp_bpdu, u_int length)
+stp_print_config_bpdu(netdissect_options *ndo, const struct stp_bpdu_ *stp_bpdu,
+                      u_int length)
 {
-    printf(", Flags [%s]",
-           bittok2str(stp_bpdu_flag_values, "none", stp_bpdu->flags));
+    ND_PRINT((ndo, ", Flags [%s]",
+           bittok2str(stp_bpdu_flag_values, "none", stp_bpdu->flags)));
 
-    printf(", bridge-id %s.%04x, length %u",
+    ND_PRINT((ndo, ", bridge-id %s.%04x, length %u",
            stp_print_bridge_id((const u_char *)&stp_bpdu->bridge_id),
-           EXTRACT_16BITS(&stp_bpdu->port_id), length);
+           EXTRACT_16BITS(&stp_bpdu->port_id), length));
 
     /* in non-verbose mode just print the bridge-id */
-    if (!vflag) {
+    if (!ndo->ndo_vflag) {
         return;
     }
 
-    printf("\n\tmessage-age %.2fs, max-age %.2fs"
+    ND_PRINT((ndo, "\n\tmessage-age %.2fs, max-age %.2fs"
            ", hello-time %.2fs, forwarding-delay %.2fs",
            (float)EXTRACT_16BITS(&stp_bpdu->message_age) / STP_TIME_BASE,
            (float)EXTRACT_16BITS(&stp_bpdu->max_age) / STP_TIME_BASE,
            (float)EXTRACT_16BITS(&stp_bpdu->hello_time) / STP_TIME_BASE,
-           (float)EXTRACT_16BITS(&stp_bpdu->forward_delay) / STP_TIME_BASE);
+           (float)EXTRACT_16BITS(&stp_bpdu->forward_delay) / STP_TIME_BASE));
 
-    printf("\n\troot-id %s, root-pathcost %u",
+    ND_PRINT((ndo, "\n\troot-id %s, root-pathcost %u",
            stp_print_bridge_id((const u_char *)&stp_bpdu->root_id),
-           EXTRACT_32BITS(&stp_bpdu->root_path_cost));
+           EXTRACT_32BITS(&stp_bpdu->root_path_cost)));
 
     /* Port role is only valid for 802.1w */
     if (stp_bpdu->protocol_version == STP_PROTO_RAPID) {
-        printf(", port-role %s",
+        ND_PRINT((ndo, ", port-role %s",
                tok2str(rstp_obj_port_role_values, "Unknown",
-                       RSTP_EXTRACT_PORT_ROLE(stp_bpdu->flags)));
+                       RSTP_EXTRACT_PORT_ROLE(stp_bpdu->flags))));
     }
 }
 
@@ -228,7 +228,8 @@ stp_print_config_bpdu(const struct stp_bpdu_ *stp_bpdu, u_int length)
 
 
 static void
-stp_print_mstp_bpdu(const struct stp_bpdu_ *stp_bpdu, u_int length)
+stp_print_mstp_bpdu(netdissect_options *ndo, const struct stp_bpdu_ *stp_bpdu,
+                    u_int length)
 {
     const u_char *ptr;
     u_int16_t      v3len;
@@ -237,53 +238,53 @@ stp_print_mstp_bpdu(const struct stp_bpdu_ *stp_bpdu, u_int length)
     u_int          offset;
 
     ptr = (const u_char *)stp_bpdu;
-    printf(", CIST Flags [%s], length %u",
-           bittok2str(stp_bpdu_flag_values, "none", stp_bpdu->flags), length);
+    ND_PRINT((ndo, ", CIST Flags [%s], length %u",
+           bittok2str(stp_bpdu_flag_values, "none", stp_bpdu->flags), length));
 
     /*
      * in non-verbose mode just print the flags.
      */
-    if (!vflag) {
+    if (!ndo->ndo_vflag) {
         return;
     }
 
-    printf("\n\tport-role %s, ",
+    ND_PRINT((ndo, "\n\tport-role %s, ",
            tok2str(rstp_obj_port_role_values, "Unknown",
-                   RSTP_EXTRACT_PORT_ROLE(stp_bpdu->flags)));
+                   RSTP_EXTRACT_PORT_ROLE(stp_bpdu->flags))));
 
-    printf("CIST root-id %s, CIST ext-pathcost %u ",
+    ND_PRINT((ndo, "CIST root-id %s, CIST ext-pathcost %u ",
            stp_print_bridge_id((const u_char *)&stp_bpdu->root_id),
-           EXTRACT_32BITS(&stp_bpdu->root_path_cost));
+           EXTRACT_32BITS(&stp_bpdu->root_path_cost)));
 
-    printf("\n\tCIST regional-root-id %s, ",
-           stp_print_bridge_id((const u_char *)&stp_bpdu->bridge_id));
+    ND_PRINT((ndo, "\n\tCIST regional-root-id %s, ",
+           stp_print_bridge_id((const u_char *)&stp_bpdu->bridge_id)));
 
-    printf("CIST port-id %04x, ", EXTRACT_16BITS(&stp_bpdu->port_id));
+    ND_PRINT((ndo, "CIST port-id %04x, ", EXTRACT_16BITS(&stp_bpdu->port_id)));
 
-    printf("\n\tmessage-age %.2fs, max-age %.2fs"
+    ND_PRINT((ndo, "\n\tmessage-age %.2fs, max-age %.2fs"
            ", hello-time %.2fs, forwarding-delay %.2fs",
            (float)EXTRACT_16BITS(&stp_bpdu->message_age) / STP_TIME_BASE,
            (float)EXTRACT_16BITS(&stp_bpdu->max_age) / STP_TIME_BASE,
            (float)EXTRACT_16BITS(&stp_bpdu->hello_time) / STP_TIME_BASE,
-           (float)EXTRACT_16BITS(&stp_bpdu->forward_delay) / STP_TIME_BASE);
+           (float)EXTRACT_16BITS(&stp_bpdu->forward_delay) / STP_TIME_BASE));
 
-    printf ("\n\tv3len %d, ", EXTRACT_16BITS(ptr + MST_BPDU_VER3_LEN_OFFSET));
-    printf("MCID Name %s, rev %u, "
+    ND_PRINT((ndo, "\n\tv3len %d, ", EXTRACT_16BITS(ptr + MST_BPDU_VER3_LEN_OFFSET)));
+    ND_PRINT((ndo, "MCID Name %s, rev %u, "
             "\n\t\tdigest %08x%08x%08x%08x, ",
             ptr + MST_BPDU_CONFIG_NAME_OFFSET,
                  EXTRACT_16BITS(ptr + MST_BPDU_CONFIG_NAME_OFFSET + 32),
            EXTRACT_32BITS(ptr + MST_BPDU_CONFIG_DIGEST_OFFSET),
                  EXTRACT_32BITS(ptr + MST_BPDU_CONFIG_DIGEST_OFFSET + 4),
                  EXTRACT_32BITS(ptr + MST_BPDU_CONFIG_DIGEST_OFFSET + 8),
-                 EXTRACT_32BITS(ptr + MST_BPDU_CONFIG_DIGEST_OFFSET + 12));
+                 EXTRACT_32BITS(ptr + MST_BPDU_CONFIG_DIGEST_OFFSET + 12)));
 
-    printf ("CIST int-root-pathcost %u, ",
-            EXTRACT_32BITS(ptr + MST_BPDU_CIST_INT_PATH_COST_OFFSET));
+    ND_PRINT((ndo, "CIST int-root-pathcost %u, ",
+            EXTRACT_32BITS(ptr + MST_BPDU_CIST_INT_PATH_COST_OFFSET)));
 
-    printf("\n\tCIST bridge-id %s, ",
-           stp_print_bridge_id(ptr + MST_BPDU_CIST_BRIDGE_ID_OFFSET));
+    ND_PRINT((ndo, "\n\tCIST bridge-id %s, ",
+           stp_print_bridge_id(ptr + MST_BPDU_CIST_BRIDGE_ID_OFFSET)));
 
-    printf("CIST remaining-hops %d", ptr[MST_BPDU_CIST_REMAIN_HOPS_OFFSET]);
+    ND_PRINT((ndo, "CIST remaining-hops %d", ptr[MST_BPDU_CIST_REMAIN_HOPS_OFFSET]));
 
     /* Dump all MSTI's */
     v3len = EXTRACT_16BITS(ptr + MST_BPDU_VER3_LEN_OFFSET);
@@ -295,19 +296,19 @@ stp_print_mstp_bpdu(const struct stp_bpdu_ *stp_bpdu, u_int length)
                                   MST_BPDU_MSTI_ROOT_PRIO_OFFSET);
             msti = msti & 0x0FFF;
 
-            printf("\n\tMSTI %d, Flags [%s], port-role %s",
+            ND_PRINT((ndo, "\n\tMSTI %d, Flags [%s], port-role %s",
                    msti, bittok2str(stp_bpdu_flag_values, "none", ptr[offset]),
                    tok2str(rstp_obj_port_role_values, "Unknown",
-                           RSTP_EXTRACT_PORT_ROLE(ptr[offset])));
-            printf("\n\t\tMSTI regional-root-id %s, pathcost %u",
+                           RSTP_EXTRACT_PORT_ROLE(ptr[offset]))));
+            ND_PRINT((ndo, "\n\t\tMSTI regional-root-id %s, pathcost %u",
                    stp_print_bridge_id(ptr + offset +
                                        MST_BPDU_MSTI_ROOT_PRIO_OFFSET),
                    EXTRACT_32BITS(ptr + offset +
-                                  MST_BPDU_MSTI_ROOT_PATH_COST_OFFSET));
-            printf("\n\t\tMSTI bridge-prio %d, port-prio %d, hops %d",
+                                  MST_BPDU_MSTI_ROOT_PATH_COST_OFFSET)));
+            ND_PRINT((ndo, "\n\t\tMSTI bridge-prio %d, port-prio %d, hops %d",
                    ptr[offset + MST_BPDU_MSTI_BRIDGE_PRIO_OFFSET] >> 4,
                    ptr[offset + MST_BPDU_MSTI_PORT_PRIO_OFFSET] >> 4,
-                   ptr[offset + MST_BPDU_MSTI_REMAIN_HOPS_OFFSET]);
+                   ptr[offset + MST_BPDU_MSTI_REMAIN_HOPS_OFFSET]));
 
             len -= MST_BPDU_MSTI_LENGTH;
             offset += MST_BPDU_MSTI_LENGTH;
@@ -316,28 +317,29 @@ stp_print_mstp_bpdu(const struct stp_bpdu_ *stp_bpdu, u_int length)
 }
 
 static void
-stp_print_spb_bpdu(const struct stp_bpdu_ *stp_bpdu, u_int offset)
+stp_print_spb_bpdu(netdissect_options *ndo, const struct stp_bpdu_ *stp_bpdu,
+                   u_int offset)
 {
     const u_char *ptr;
 
     /*
      * in non-verbose mode don't print anything.
      */
-    if (!vflag) {
+    if (!ndo->ndo_vflag) {
         return;
     }
 
     ptr = (const u_char *)stp_bpdu;
-    printf("\n\tv4len %d AUXMCID Name %s, Rev %u, \n\t\tdigest %08x%08x%08x%08x",
+    ND_PRINT((ndo, "\n\tv4len %d AUXMCID Name %s, Rev %u, \n\t\tdigest %08x%08x%08x%08x",
             EXTRACT_16BITS (ptr + offset),
             ptr + offset + SPB_BPDU_CONFIG_NAME_OFFSET,
             EXTRACT_16BITS(ptr + offset + SPB_BPDU_CONFIG_REV_OFFSET),
             EXTRACT_32BITS(ptr + offset + SPB_BPDU_CONFIG_DIGEST_OFFSET),
             EXTRACT_32BITS(ptr + offset + SPB_BPDU_CONFIG_DIGEST_OFFSET + 4),
             EXTRACT_32BITS(ptr + offset + SPB_BPDU_CONFIG_DIGEST_OFFSET + 8),
-            EXTRACT_32BITS(ptr + offset + SPB_BPDU_CONFIG_DIGEST_OFFSET + 12));
+            EXTRACT_32BITS(ptr + offset + SPB_BPDU_CONFIG_DIGEST_OFFSET + 12)));
 
-    printf("\n\tAgreement num %d, Discarded Agreement num %d, Agreement valid-"
+    ND_PRINT((ndo, "\n\tAgreement num %d, Discarded Agreement num %d, Agreement valid-"
             "flag %d, \n\tRestricted role-flag: %d, Format id %d cap %d, "
             "Convention id %d cap %d, \n\tEdge count %d, "
             "Agreement digest %08x%08x%08x%08x%08x\n",
@@ -354,14 +356,14 @@ stp_print_spb_bpdu(const struct stp_bpdu_ *stp_bpdu, u_int offset)
             EXTRACT_32BITS(ptr + offset + SPB_BPDU_AGREEMENT_DIGEST_OFFSET)+4,
             EXTRACT_32BITS(ptr + offset + SPB_BPDU_AGREEMENT_DIGEST_OFFSET)+8,
             EXTRACT_32BITS(ptr + offset + SPB_BPDU_AGREEMENT_DIGEST_OFFSET)+12,
-            EXTRACT_32BITS(ptr + offset + SPB_BPDU_AGREEMENT_DIGEST_OFFSET)+16);
+            EXTRACT_32BITS(ptr + offset + SPB_BPDU_AGREEMENT_DIGEST_OFFSET)+16));
 }
 
 /*
  * Print 802.1d / 802.1w / 802.1q (mstp) / 802.1aq (spb) packets.
  */
 void
-stp_print(const u_char *p, u_int length)
+stp_print(netdissect_options *ndo, const u_char *p, u_int length)
 {
     const struct stp_bpdu_ *stp_bpdu;
     u_int                  mstp_len;
@@ -374,12 +376,12 @@ stp_print(const u_char *p, u_int length)
         goto trunc;
 
     if (EXTRACT_16BITS(&stp_bpdu->protocol_id)) {
-        printf("unknown STP version, length %u", length);
+        ND_PRINT((ndo, "unknown STP version, length %u", length));
         return;
     }
 
-    printf("STP %s", tok2str(stp_proto_values, "Unknown STP protocol (0x%02x)",
-                         stp_bpdu->protocol_version));
+    ND_PRINT((ndo, "STP %s", tok2str(stp_proto_values, "Unknown STP protocol (0x%02x)",
+                         stp_bpdu->protocol_version)));
 
     switch (stp_bpdu->protocol_version) {
     case STP_PROTO_REGULAR:
@@ -391,15 +393,15 @@ stp_print(const u_char *p, u_int length)
         return;
     }
 
-    printf(", %s", tok2str(stp_bpdu_type_values, "Unknown BPDU Type (0x%02x)",
-                           stp_bpdu->bpdu_type));
+    ND_PRINT((ndo, ", %s", tok2str(stp_bpdu_type_values, "Unknown BPDU Type (0x%02x)",
+                           stp_bpdu->bpdu_type)));
 
     switch (stp_bpdu->bpdu_type) {
     case STP_BPDU_TYPE_CONFIG:
         if (length < sizeof(struct stp_bpdu_) - 1) {
             goto trunc;
         }
-        stp_print_config_bpdu(stp_bpdu, length);
+        stp_print_config_bpdu(ndo, stp_bpdu, length);
         break;
 
     case STP_BPDU_TYPE_RSTP:
@@ -407,7 +409,7 @@ stp_print(const u_char *p, u_int length)
             if (length < sizeof(struct stp_bpdu_)) {
                 goto trunc;
             }
-            stp_print_config_bpdu(stp_bpdu, length);
+            stp_print_config_bpdu(ndo, stp_bpdu, length);
         } else if (stp_bpdu->protocol_version == STP_PROTO_MSTP ||
                    stp_bpdu->protocol_version == STP_PROTO_SPB) {
             if (length < STP_BPDU_MSTP_MIN_LEN) {
@@ -425,7 +427,7 @@ stp_print(const u_char *p, u_int length)
             if (length < (sizeof(struct stp_bpdu_) + mstp_len)) {
                 goto trunc;
             }
-            stp_print_mstp_bpdu(stp_bpdu, length);
+            stp_print_mstp_bpdu(ndo, stp_bpdu, length);
 
             if (stp_bpdu->protocol_version == STP_PROTO_SPB)
             {
@@ -436,7 +438,7 @@ stp_print(const u_char *p, u_int length)
                   spb_len < SPB_BPDU_MIN_LEN) {
                 goto trunc;
               }
-              stp_print_spb_bpdu(stp_bpdu, (sizeof(struct stp_bpdu_) + mstp_len));
+              stp_print_spb_bpdu(ndo, stp_bpdu, (sizeof(struct stp_bpdu_) + mstp_len));
             }
         }
         break;
@@ -451,7 +453,7 @@ stp_print(const u_char *p, u_int length)
 
     return;
  trunc:
-    printf("[|stp %d]", length);
+    ND_PRINT((ndo, "[|stp %d]", length));
 }
 
 /*
index bb11e95be66a11544f7b0e1e5c5c7ca9964089ec..bae7b975dfc8c3a58096843149cb57cc9cbce002 100644 (file)
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
+#define NETDISSECT_REWORKED
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
 #include <tcpdump-stdinc.h>
 
-#include <stdio.h>
-#include <string.h>
-
 #include "interface.h"
 #include "addrtoname.h"
 #include "extract.h"
@@ -97,33 +95,34 @@ struct rtcp_rr {
 #define RTCP_PT_APP    204
 
 static void
-vat_print(const void *hdr, register const struct udphdr *up)
+vat_print(netdissect_options *ndo, const void *hdr, register const struct udphdr *up)
 {
        /* vat/vt audio */
        u_int ts = *(u_int16_t *)hdr;
        if ((ts & 0xf060) != 0) {
                /* probably vt */
-               (void)printf("udp/vt %u %d / %d",
+               ND_PRINT((ndo, "udp/vt %u %d / %d",
                             (u_int32_t)(EXTRACT_16BITS(&up->uh_ulen) - sizeof(*up)),
-                            ts & 0x3ff, ts >> 10);
+                            ts & 0x3ff, ts >> 10));
        } else {
                /* probably vat */
                u_int32_t i0 = EXTRACT_32BITS(&((u_int *)hdr)[0]);
                u_int32_t i1 = EXTRACT_32BITS(&((u_int *)hdr)[1]);
-               printf("udp/vat %u c%d %u%s",
+               ND_PRINT((ndo, "udp/vat %u c%d %u%s",
                        (u_int32_t)(EXTRACT_16BITS(&up->uh_ulen) - sizeof(*up) - 8),
                        i0 & 0xffff,
-                       i1, i0 & 0x800000? "*" : "");
+                       i1, i0 & 0x800000? "*" : ""));
                /* audio format */
                if (i0 & 0x1f0000)
-                       printf(" f%d", (i0 >> 16) & 0x1f);
+                       ND_PRINT((ndo, " f%d", (i0 >> 16) & 0x1f));
                if (i0 & 0x3f000000)
-                       printf(" s%d", (i0 >> 24) & 0x3f);
+                       ND_PRINT((ndo, " s%d", (i0 >> 24) & 0x3f));
        }
 }
 
 static void
-rtp_print(const void *hdr, u_int len, register const struct udphdr *up)
+rtp_print(netdissect_options *ndo, const void *hdr, u_int len,
+          register const struct udphdr *up)
 {
        /* rtp v1 or v2 */
        u_int *ip = (u_int *)hdr;
@@ -154,23 +153,23 @@ rtp_print(const void *hdr, u_int len, register const struct udphdr *up)
                ip += 1;
                len -= 1;
        }
-       printf("udp/%s %d c%d %s%s %d %u",
+       ND_PRINT((ndo, "udp/%s %d c%d %s%s %d %u",
                ptype,
                dlen,
                contype,
                (hasopt || hasext)? "+" : "",
                hasmarker? "*" : "",
                i0 & 0xffff,
-               i1);
-       if (vflag) {
-               printf(" %u", EXTRACT_32BITS(&((u_int *)hdr)[2]));
+               i1));
+       if (ndo->ndo_vflag) {
+               ND_PRINT((ndo, " %u", EXTRACT_32BITS(&((u_int *)hdr)[2])));
                if (hasopt) {
                        u_int i2, optlen;
                        do {
                                i2 = ip[0];
                                optlen = (i2 >> 16) & 0xff;
                                if (optlen == 0 || optlen > len) {
-                                       printf(" !opt");
+                                       ND_PRINT((ndo, " !opt"));
                                        return;
                                }
                                ip += optlen;
@@ -182,18 +181,18 @@ rtp_print(const void *hdr, u_int len, register const struct udphdr *up)
                        i2 = ip[0];
                        extlen = (i2 & 0xffff) + 1;
                        if (extlen > len) {
-                               printf(" !ext");
+                               ND_PRINT((ndo, " !ext"));
                                return;
                        }
                        ip += extlen;
                }
                if (contype == 0x1f) /*XXX H.261 */
-                       printf(" 0x%04x", ip[0] >> 16);
+                       ND_PRINT((ndo, " 0x%04x", ip[0] >> 16));
        }
 }
 
 static const u_char *
-rtcp_print(const u_char *hdr, const u_char *ep)
+rtcp_print(netdissect_options *ndo, const u_char *hdr, const u_char *ep)
 {
        /* rtp v2 control (rtcp) */
        struct rtcp_rr *rr = 0;
@@ -204,7 +203,7 @@ rtcp_print(const u_char *hdr, const u_char *ep)
        int cnt;
        double ts, dts;
        if ((u_char *)(rh + 1) > ep) {
-               printf(" [|rtcp]");
+               ND_PRINT((ndo, " [|rtcp]"));
                return (ep);
        }
        len = (EXTRACT_16BITS(&rh->rh_len) + 1) * 4;
@@ -213,62 +212,62 @@ rtcp_print(const u_char *hdr, const u_char *ep)
        switch (flags & 0xff) {
        case RTCP_PT_SR:
                sr = (struct rtcp_sr *)(rh + 1);
-               printf(" sr");
+               ND_PRINT((ndo, " sr"));
                if (len != cnt * sizeof(*rr) + sizeof(*sr) + sizeof(*rh))
-                       printf(" [%d]", len);
-               if (vflag)
-                       printf(" %u", EXTRACT_32BITS(&rh->rh_ssrc));
+                       ND_PRINT((ndo, " [%d]", len));
+               if (ndo->ndo_vflag)
+                       ND_PRINT((ndo, " %u", EXTRACT_32BITS(&rh->rh_ssrc)));
                if ((u_char *)(sr + 1) > ep) {
-                       printf(" [|rtcp]");
+                       ND_PRINT((ndo, " [|rtcp]"));
                        return (ep);
                }
                ts = (double)(EXTRACT_32BITS(&sr->sr_ntp.upper)) +
                    ((double)(EXTRACT_32BITS(&sr->sr_ntp.lower)) /
                    4294967296.0);
-               printf(" @%.2f %u %up %ub", ts, EXTRACT_32BITS(&sr->sr_ts),
-                   EXTRACT_32BITS(&sr->sr_np), EXTRACT_32BITS(&sr->sr_nb));
+               ND_PRINT((ndo, " @%.2f %u %up %ub", ts, EXTRACT_32BITS(&sr->sr_ts),
+                   EXTRACT_32BITS(&sr->sr_np), EXTRACT_32BITS(&sr->sr_nb)));
                rr = (struct rtcp_rr *)(sr + 1);
                break;
        case RTCP_PT_RR:
-               printf(" rr");
+               ND_PRINT((ndo, " rr"));
                if (len != cnt * sizeof(*rr) + sizeof(*rh))
-                       printf(" [%d]", len);
+                       ND_PRINT((ndo, " [%d]", len));
                rr = (struct rtcp_rr *)(rh + 1);
-               if (vflag)
-                       printf(" %u", EXTRACT_32BITS(&rh->rh_ssrc));
+               if (ndo->ndo_vflag)
+                       ND_PRINT((ndo, " %u", EXTRACT_32BITS(&rh->rh_ssrc)));
                break;
        case RTCP_PT_SDES:
-               printf(" sdes %d", len);
-               if (vflag)
-                       printf(" %u", EXTRACT_32BITS(&rh->rh_ssrc));
+               ND_PRINT((ndo, " sdes %d", len));
+               if (ndo->ndo_vflag)
+                       ND_PRINT((ndo, " %u", EXTRACT_32BITS(&rh->rh_ssrc)));
                cnt = 0;
                break;
        case RTCP_PT_BYE:
-               printf(" bye %d", len);
-               if (vflag)
-                       printf(" %u", EXTRACT_32BITS(&rh->rh_ssrc));
+               ND_PRINT((ndo, " bye %d", len));
+               if (ndo->ndo_vflag)
+                       ND_PRINT((ndo, " %u", EXTRACT_32BITS(&rh->rh_ssrc)));
                cnt = 0;
                break;
        default:
-               printf(" type-0x%x %d", flags & 0xff, len);
+               ND_PRINT((ndo, " type-0x%x %d", flags & 0xff, len));
                cnt = 0;
                break;
        }
        if (cnt > 1)
-               printf(" c%d", cnt);
+               ND_PRINT((ndo, " c%d", cnt));
        while (--cnt >= 0) {
                if ((u_char *)(rr + 1) > ep) {
-                       printf(" [|rtcp]");
+                       ND_PRINT((ndo, " [|rtcp]"));
                        return (ep);
                }
-               if (vflag)
-                       printf(" %u", EXTRACT_32BITS(&rr->rr_srcid));
+               if (ndo->ndo_vflag)
+                       ND_PRINT((ndo, " %u", EXTRACT_32BITS(&rr->rr_srcid)));
                ts = (double)(EXTRACT_32BITS(&rr->rr_lsr)) / 65536.;
                dts = (double)(EXTRACT_32BITS(&rr->rr_dlsr)) / 65536.;
-               printf(" %ul %us %uj @%.2f+%.2f",
+               ND_PRINT((ndo, " %ul %us %uj @%.2f+%.2f",
                    EXTRACT_32BITS(&rr->rr_nl) & 0x00ffffff,
                    EXTRACT_32BITS(&rr->rr_ls),
-                   EXTRACT_32BITS(&rr->rr_dv), ts, dts);
+                   EXTRACT_32BITS(&rr->rr_dv), ts, dts));
        }
        return (hdr + len);
 }
@@ -291,7 +290,7 @@ static int udp6_cksum(const struct ip6_hdr *ip6, const struct udphdr *up,
 #endif
 
 static void
-udpipaddr_print(const struct ip *ip, int sport, int dport)
+udpipaddr_print(netdissect_options *ndo, const struct ip *ip, int sport, int dport)
 {
 #ifdef INET6
        const struct ip6_hdr *ip6;
@@ -304,21 +303,21 @@ udpipaddr_print(const struct ip *ip, int sport, int dport)
        if (ip6) {
                if (ip6->ip6_nxt == IPPROTO_UDP) {
                        if (sport == -1) {
-                               (void)printf("%s > %s: ",
+                               ND_PRINT((ndo, "%s > %s: ",
                                        ip6addr_string(&ip6->ip6_src),
-                                       ip6addr_string(&ip6->ip6_dst));
+                                       ip6addr_string(&ip6->ip6_dst)));
                        } else {
-                               (void)printf("%s.%s > %s.%s: ",
+                               ND_PRINT((ndo, "%s.%s > %s.%s: ",
                                        ip6addr_string(&ip6->ip6_src),
                                        udpport_string(sport),
                                        ip6addr_string(&ip6->ip6_dst),
-                                       udpport_string(dport));
+                                       udpport_string(dport)));
                        }
                } else {
                        if (sport != -1) {
-                               (void)printf("%s > %s: ",
+                               ND_PRINT((ndo, "%s > %s: ",
                                        udpport_string(sport),
-                                       udpport_string(dport));
+                                       udpport_string(dport)));
                        }
                }
        } else
@@ -326,28 +325,28 @@ udpipaddr_print(const struct ip *ip, int sport, int dport)
        {
                if (ip->ip_p == IPPROTO_UDP) {
                        if (sport == -1) {
-                               (void)printf("%s > %s: ",
+                               ND_PRINT((ndo, "%s > %s: ",
                                        ipaddr_string(&ip->ip_src),
-                                       ipaddr_string(&ip->ip_dst));
+                                       ipaddr_string(&ip->ip_dst)));
                        } else {
-                               (void)printf("%s.%s > %s.%s: ",
+                               ND_PRINT((ndo, "%s.%s > %s.%s: ",
                                        ipaddr_string(&ip->ip_src),
                                        udpport_string(sport),
                                        ipaddr_string(&ip->ip_dst),
-                                       udpport_string(dport));
+                                       udpport_string(dport)));
                        }
                } else {
                        if (sport != -1) {
-                               (void)printf("%s > %s: ",
+                               ND_PRINT((ndo, "%s > %s: ",
                                        udpport_string(sport),
-                                       udpport_string(dport));
+                                       udpport_string(dport)));
                        }
                }
        }
 }
 
 void
-udp_print(register const u_char *bp, u_int length,
+udp_print(netdissect_options *ndo, register const u_char *bp, u_int length,
          register const u_char *bp2, int fragmented)
 {
        register const struct udphdr *up;
@@ -359,8 +358,8 @@ udp_print(register const u_char *bp, u_int length,
        register const struct ip6_hdr *ip6;
 #endif
 
-       if (ep > snapend)
-               ep = snapend;
+       if (ep > ndo->ndo_snapend)
+               ep = ndo->ndo_snapend;
        up = (struct udphdr *)bp;
        ip = (struct ip *)bp2;
 #ifdef INET6
@@ -370,9 +369,9 @@ udp_print(register const u_char *bp, u_int length,
                ip6 = NULL;
 #endif /*INET6*/
        cp = (u_char *)(up + 1);
-       if (!TTEST(up->uh_dport)) {
-               udpipaddr_print(ip, -1, -1);
-               (void)printf("[|udp]");
+       if (!ND_TTEST(up->uh_dport)) {
+               udpipaddr_print(ndo, ip, -1, -1);
+               ND_PRINT((ndo, "[|udp]"));
                return;
        }
 
@@ -380,37 +379,37 @@ udp_print(register const u_char *bp, u_int length,
        dport = EXTRACT_16BITS(&up->uh_dport);
 
        if (length < sizeof(struct udphdr)) {
-               udpipaddr_print(ip, sport, dport);
-               (void)printf("truncated-udp %d", length);
+               udpipaddr_print(ndo, ip, sport, dport);
+               ND_PRINT((ndo, "truncated-udp %d", length));
                return;
        }
        length -= sizeof(struct udphdr);
 
-       if (cp > snapend) {
-               udpipaddr_print(ip, sport, dport);
-               (void)printf("[|udp]");
+       if (cp > ndo->ndo_snapend) {
+               udpipaddr_print(ndo, ip, sport, dport);
+               ND_PRINT((ndo, "[|udp]"));
                return;
        }
 
        ulen = EXTRACT_16BITS(&up->uh_ulen);
        if (ulen < 8) {
-               udpipaddr_print(ip, sport, dport);
-               (void)printf("truncated-udplength %d", ulen);
+               udpipaddr_print(ndo, ip, sport, dport);
+               ND_PRINT((ndo, "truncated-udplength %d", ulen));
                return;
        }
-       if (packettype) {
+       if (ndo->ndo_packettype) {
                register struct sunrpc_msg *rp;
                enum sunrpc_msg_type direction;
 
-               switch (packettype) {
+               switch (ndo->ndo_packettype) {
 
                case PT_VAT:
-                       udpipaddr_print(ip, sport, dport);
-                       vat_print((void *)(up + 1), up);
+                       udpipaddr_print(ndo, ip, sport, dport);
+                       vat_print(ndo, (void *)(up + 1), up);
                        break;
 
                case PT_WB:
-                       udpipaddr_print(ip, sport, dport);
+                       udpipaddr_print(ndo, ip, sport, dport);
                        wb_print((void *)(up + 1), length);
                        break;
 
@@ -418,7 +417,7 @@ udp_print(register const u_char *bp, u_int length,
                        rp = (struct sunrpc_msg *)(up + 1);
                        direction = (enum sunrpc_msg_type)EXTRACT_32BITS(&rp->rm_direction);
                        if (direction == SUNRPC_CALL)
-                               sunrpcrequest_print(gndo, (u_char *)rp, length,
+                               sunrpcrequest_print(ndo, (u_char *)rp, length,
                                    (u_char *)ip);
                        else
                                nfsreply_print((u_char *)rp, length,
@@ -426,33 +425,33 @@ udp_print(register const u_char *bp, u_int length,
                        break;
 
                case PT_RTP:
-                       udpipaddr_print(ip, sport, dport);
-                       rtp_print((void *)(up + 1), length, up);
+                       udpipaddr_print(ndo, ip, sport, dport);
+                       rtp_print(ndo, (void *)(up + 1), length, up);
                        break;
 
                case PT_RTCP:
-                       udpipaddr_print(ip, sport, dport);
+                       udpipaddr_print(ndo, ip, sport, dport);
                        while (cp < ep)
-                               cp = rtcp_print(cp, ep);
+                               cp = rtcp_print(ndo, cp, ep);
                        break;
 
                case PT_SNMP:
-                       udpipaddr_print(ip, sport, dport);
+                       udpipaddr_print(ndo, ip, sport, dport);
                        snmp_print((const u_char *)(up + 1), length);
                        break;
 
                case PT_CNFP:
-                       udpipaddr_print(ip, sport, dport);
+                       udpipaddr_print(ndo, ip, sport, dport);
                        cnfp_print(cp, (const u_char *)ip);
                        break;
 
                case PT_TFTP:
-                       udpipaddr_print(ip, sport, dport);
+                       udpipaddr_print(ndo, ip, sport, dport);
                        tftp_print(cp, length);
                        break;
 
                case PT_AODV:
-                       udpipaddr_print(ip, sport, dport);
+                       udpipaddr_print(ndo, ip, sport, dport);
                        aodv_print((const u_char *)(up + 1), length,
 #ifdef INET6
                            ip6 != NULL);
@@ -462,44 +461,44 @@ udp_print(register const u_char *bp, u_int length,
                        break;
 
                case PT_RADIUS:
-                       udpipaddr_print(ip, sport, dport);
+                       udpipaddr_print(ndo, ip, sport, dport);
                        radius_print(cp, length);
                        break;
 
                case PT_VXLAN:
-                       udpipaddr_print(ip, sport, dport);
-                       vxlan_print(gndo, (const u_char *)(up + 1), length);
+                       udpipaddr_print(ndo, ip, sport, dport);
+                       vxlan_print(ndo, (const u_char *)(up + 1), length);
                        break;
 
                case PT_PGM:
                case PT_PGM_ZMTP1:
-                       udpipaddr_print(ip, sport, dport);
+                       udpipaddr_print(ndo, ip, sport, dport);
                        pgm_print(cp, length, bp2);
                        break;
                case PT_LMP:
-                       udpipaddr_print(ip, sport, dport);
+                       udpipaddr_print(ndo, ip, sport, dport);
                        lmp_print(cp, length);
                        break;
                }
                return;
        }
 
-       udpipaddr_print(ip, sport, dport);
-       if (!qflag) {
+       udpipaddr_print(ndo, ip, sport, dport);
+       if (!ndo->ndo_qflag) {
                register struct sunrpc_msg *rp;
                enum sunrpc_msg_type direction;
 
                rp = (struct sunrpc_msg *)(up + 1);
-               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));
+                               ND_PRINT((ndo, "NFS request xid %u ", EXTRACT_32BITS(&rp->rm_xid)));
                                nfsreq_print_noaddr((u_char *)rp, length,
                                    (u_char *)ip);
                                return;
                        }
                        if (sport == NFS_PORT && direction == SUNRPC_REPLY) {
-                               (void)printf("NFS reply xid %u ", EXTRACT_32BITS(&rp->rm_xid));
+                               ND_PRINT((ndo, "NFS reply xid %u ", EXTRACT_32BITS(&rp->rm_xid)));
                                nfsreply_print_noaddr((u_char *)rp, length,
                                    (u_char *)ip);
                                return;
@@ -511,17 +510,17 @@ udp_print(register const u_char *bp, u_int length,
                        }
 #endif
                }
-               if (TTEST(((struct LAP *)cp)->type) &&
+               if (ND_TTEST(((struct LAP *)cp)->type) &&
                    ((struct LAP *)cp)->type == lapDDP &&
                    (atalk_port(sport) || atalk_port(dport))) {
-                       if (vflag)
-                               fputs("kip ", stdout);
+                       if (ndo->ndo_vflag)
+                               ND_PRINT((ndo, "kip "));
                        llap_print(cp, length);
                        return;
                }
        }
 
-       if (vflag && !Kflag && !fragmented) {
+       if (ndo->ndo_vflag && !ndo->ndo_Kflag && !fragmented) {
                 /* Check the checksum, if possible. */
                 u_int16_t sum, udp_sum;
 
@@ -529,40 +528,40 @@ udp_print(register const u_char *bp, u_int length,
                 * XXX - do this even if vflag == 1?
                 * TCP does, and we do so for UDP-over-IPv6.
                 */
-               if (IP_V(ip) == 4 && (vflag > 1)) {
+               if (IP_V(ip) == 4 && (ndo->ndo_vflag > 1)) {
                        udp_sum = EXTRACT_16BITS(&up->uh_sum);
                        if (udp_sum == 0) {
-                               (void)printf("[no cksum] ");
-                       } else if (TTEST2(cp[0], length)) {
+                               ND_PRINT((ndo, "[no cksum] "));
+                       } else if (ND_TTEST2(cp[0], length)) {
                                sum = udp_cksum(ip, up, length + sizeof(struct udphdr));
 
                                if (sum != 0) {
-                                       (void)printf("[bad udp cksum 0x%04x -> 0x%04x!] ",
+                                       ND_PRINT((ndo, "[bad udp cksum 0x%04x -> 0x%04x!] ",
                                            udp_sum,
-                                           in_cksum_shouldbe(udp_sum, sum));
+                                           in_cksum_shouldbe(udp_sum, sum)));
                                } else
-                                       (void)printf("[udp sum ok] ");
+                                       ND_PRINT((ndo, "[udp sum ok] "));
                        }
                }
 #ifdef INET6
                else if (IP_V(ip) == 6 && ip6->ip6_plen) {
                        /* for IPv6, UDP checksum is mandatory */
-                       if (TTEST2(cp[0], length)) {
+                       if (ND_TTEST2(cp[0], length)) {
                                sum = udp6_cksum(ip6, up, length + sizeof(struct udphdr));
                                udp_sum = EXTRACT_16BITS(&up->uh_sum);
 
                                if (sum != 0) {
-                                       (void)printf("[bad udp cksum 0x%04x -> 0x%04x!] ",
+                                       ND_PRINT((ndo, "[bad udp cksum 0x%04x -> 0x%04x!] ",
                                            udp_sum,
-                                           in_cksum_shouldbe(udp_sum, sum));
+                                           in_cksum_shouldbe(udp_sum, sum)));
                                } else
-                                       (void)printf("[udp sum ok] ");
+                                       ND_PRINT((ndo, "[udp sum ok] "));
                        }
                }
 #endif
        }
 
-       if (!qflag) {
+       if (!ndo->ndo_qflag) {
 #define ISPORT(p) (dport == (p) || sport == (p))
                if (ISPORT(NAMESERVER_PORT))
                        ns_print((const u_char *)(up + 1), length, 0);
@@ -584,12 +583,12 @@ udp_print(register const u_char *bp, u_int length,
                            0);
 #endif
                else if (ISPORT(ISAKMP_PORT))
-                        isakmp_print(gndo, (const u_char *)(up + 1), length, bp2);
+                        isakmp_print(ndo, (const u_char *)(up + 1), length, bp2);
                else if (ISPORT(ISAKMP_PORT_NATT))
-                        isakmp_rfc3948_print(gndo, (const u_char *)(up + 1), length, bp2);
+                        isakmp_rfc3948_print(ndo, (const u_char *)(up + 1), length, bp2);
 #if 1 /*???*/
                else if (ISPORT(ISAKMP_PORT_USER1) || ISPORT(ISAKMP_PORT_USER2))
-                       isakmp_print(gndo, (const u_char *)(up + 1), length, bp2);
+                       isakmp_print(ndo, (const u_char *)(up + 1), length, bp2);
 #endif
                else if (ISPORT(SNMP_PORT) || ISPORT(SNMPTRAP_PORT))
                        snmp_print((const u_char *)(up + 1), length);
@@ -598,7 +597,7 @@ udp_print(register const u_char *bp, u_int length,
                else if (ISPORT(KERBEROS_PORT) || ISPORT(KERBEROS_SEC_PORT))
                        krb_print((const void *)(up + 1));
                else if (ISPORT(L2TP_PORT))
-                       l2tp_print((const u_char *)(up + 1), length);
+                       l2tp_print(ndo, (const u_char *)(up + 1), length);
 #ifdef TCPDUMP_DO_SMB
                else if (ISPORT(NETBIOS_NS_PORT))
                        nbt_udp137_print((const u_char *)(up + 1), length);
@@ -606,9 +605,9 @@ udp_print(register const u_char *bp, u_int length,
                        nbt_udp138_print((const u_char *)(up + 1), length);
 #endif
                else if (dport == VAT_PORT)
-                       vat_print((const void *)(up + 1), up);
+                       vat_print(ndo, (const void *)(up + 1), up);
                else if (ISPORT(ZEPHYR_SRV_PORT) || ISPORT(ZEPHYR_CLT_PORT))
-                       zephyr_print(gndo, (const void *)(up + 1), length);
+                       zephyr_print(ndo, (const void *)(up + 1), length);
                /*
                 * Since there are 10 possible ports to check, I think
                 * a <> test would be more efficient
@@ -619,11 +618,11 @@ udp_print(register const u_char *bp, u_int length,
                                 (u_char *) ip);
 #ifdef INET6
                else if (ISPORT(RIPNG_PORT))
-                       ripng_print(gndo, (const u_char *)(up + 1), length);
+                       ripng_print(ndo, (const u_char *)(up + 1), length);
                else if (ISPORT(DHCP6_SERV_PORT) || ISPORT(DHCP6_CLI_PORT))
                        dhcp6_print((const u_char *)(up + 1), length);
                else if (ISPORT(AHCP_PORT))
-                       ahcp_print(gndo, (const u_char *)(up + 1), length);
+                       ahcp_print(ndo, (const u_char *)(up + 1), length);
                else if (ISPORT(BABEL_PORT) || ISPORT(BABEL_PORT_OLD))
                        babel_print((const u_char *)(up + 1), length);
 #endif /*INET6*/
@@ -640,7 +639,7 @@ udp_print(register const u_char *bp, u_int length,
                         ISPORT(RADIUS_NEW_ACCOUNTING_PORT) )
                        radius_print((const u_char *)(up+1), length);
                else if (dport == HSRP_PORT)
-                       hsrp_print(gndo, (const u_char *)(up + 1), length);
+                       hsrp_print(ndo, (const u_char *)(up + 1), length);
                else if (ISPORT(LWRES_PORT))
                        lwres_print((const u_char *)(up + 1), length);
                else if (ISPORT(LDP_PORT))
@@ -656,11 +655,11 @@ udp_print(register const u_char *bp, u_int length,
                        lspping_print((const u_char *)(up + 1), length);
                else if (dport == BFD_CONTROL_PORT ||
                         dport == BFD_ECHO_PORT )
-                       bfd_print(gndo, (const u_char *)(up+1), length, dport);
+                       bfd_print(ndo, (const u_char *)(up+1), length, dport);
                 else if (ISPORT(LMP_PORT))
                        lmp_print((const u_char *)(up + 1), length);
                else if (ISPORT(VQP_PORT))
-                       vqp_print(gndo, (const u_char *)(up + 1), length);
+                       vqp_print(ndo, (const u_char *)(up + 1), length);
                 else if (ISPORT(SFLOW_PORT))
                         sflow_print((const u_char *)(up + 1), length);
                else if (dport == LWAPP_CONTROL_PORT)
@@ -674,15 +673,15 @@ udp_print(register const u_char *bp, u_int length,
                 else if (ISPORT(SYSLOG_PORT))
                        syslog_print((const u_char *)(up + 1), length);
                 else if (ISPORT(OTV_PORT))
-                       otv_print(gndo, (const u_char *)(up + 1), length);
+                       otv_print(ndo, (const u_char *)(up + 1), length);
                 else if (ISPORT(VXLAN_PORT))
-                       vxlan_print(gndo, (const u_char *)(up + 1), length);
+                       vxlan_print(ndo, (const u_char *)(up + 1), length);
                else
-                       (void)printf("UDP, length %u",
-                           (u_int32_t)(ulen - sizeof(*up)));
+                       ND_PRINT((ndo, "UDP, length %u",
+                           (u_int32_t)(ulen - sizeof(*up))));
 #undef ISPORT
        } else
-               (void)printf("UDP, length %u", (u_int32_t)(ulen - sizeof(*up)));
+               ND_PRINT((ndo, "UDP, length %u", (u_int32_t)(ulen - sizeof(*up))));
 }