]> The Tcpdump Group git mirrors - tcpdump/commitdiff
reworked print-ether to use netdissect
authorMichael Richardson <[email protected]>
Thu, 7 Oct 2010 18:36:49 +0000 (14:36 -0400)
committerMichael Richardson <[email protected]>
Thu, 7 Oct 2010 18:40:50 +0000 (14:40 -0400)
13 files changed:
interface.h
netdissect.h
print-ap1394.c
print-ether.c
print-fr.c
print-gre.c
print-ip.c
print-juniper.c
print-lane.c
print-llc.c
print-sll.c
print-symantec.c
tcpdump.c

index be027ed34c99d328cf6b4b9f21689a94ab68be6f..1823b9318e3088c7116d1a0c5b8995639bbd1e5a 100644 (file)
@@ -162,7 +162,6 @@ extern void hex_and_ascii_print(const char *, const u_char *, u_int);
 extern void hex_print_with_offset(const char *, const u_char *, u_int, u_int);
 extern void hex_print(const char *, const u_char *, u_int);
 extern void telnet_print(const u_char *, u_int);
-extern int ethertype_print(u_short, const u_char *, u_int, u_int);
 extern int llc_print(const u_char *, u_int, u_int, const u_char *,
        const u_char *, u_short *);
 extern int snap_print(const u_char *, u_int, u_int, u_int);
@@ -185,9 +184,6 @@ extern u_int enc_if_print(const struct pcap_pkthdr *, const u_char *);
 extern u_int pflog_if_print(const struct pcap_pkthdr *, const u_char *);
 extern u_int arcnet_if_print(const struct pcap_pkthdr *, const u_char *);
 extern u_int arcnet_linux_if_print(const struct pcap_pkthdr *, const u_char *);
-extern void ether_print(const u_char *, u_int, u_int,
-    void (*)(const u_char *), const u_char *);
-extern u_int ether_if_print(const struct pcap_pkthdr *, const u_char *);
 extern u_int token_print(const u_char *, u_int, u_int);
 extern u_int token_if_print(const struct pcap_pkthdr *, const u_char *);
 extern void fddi_print(const u_char *, u_int, u_int);
index 52711ee4515ec8720328b60a8fded00818be0545..86ab1ad5c1efe1d74a365fa888b0eefb25a9e598 100644 (file)
@@ -283,6 +283,17 @@ extern void ip_print_inner(netdissect_options *ndo,
                           const u_char *bp2);
 extern void rrcp_print(netdissect_options *,const u_char *, u_int);
 
+extern void ether_print(netdissect_options *,
+                        const u_char *, u_int, u_int,
+                        void (*)(netdissect_options *, const u_char *),
+                        const u_char *);
+
+extern u_int ether_if_print(netdissect_options *, 
+                           const struct pcap_pkthdr *,const u_char *);
+
+extern int ethertype_print(netdissect_options *,u_short, const u_char *,
+                            u_int, u_int);
+
 /* stuff that has not yet been rototiled */
 #if 0
 extern void ascii_print(netdissect_options *,u_int);
@@ -293,8 +304,6 @@ extern void hex_print_with_offset(netdissect_options *,const char *,
                                  u_int, u_int);
 extern void hex_print(netdissect_options *,const char *, u_int);
 extern void telnet_print(netdissect_options *,const u_char *, u_int);
-extern int ethertype_print(netdissect_options *,u_short, const u_char *,
-                            u_int, u_int);
 extern int llc_print(netdissect_options *,
                     const u_char *, u_int, u_int, const u_char *,
                     const u_char *, u_short *);
@@ -321,7 +330,6 @@ extern void egp_print(netdissect_options *,const u_char *, u_int,
                      const u_char *);
 
 extern void arcnet_if_print(u_char*,const struct pcap_pkthdr *,const u_char *);
-extern void ether_if_print(u_char *,const struct pcap_pkthdr *,const u_char *);
 extern void token_if_print(u_char *,const struct pcap_pkthdr *,const u_char *);
 extern void fddi_if_print(u_char *,const struct pcap_pkthdr *, const u_char *);
 
index cb9d972f43b6f83a80db3e75f05e7b831db1b0d0..ab0713b5a7a2b5965df3f73ddbc52c4222a44a55 100644 (file)
@@ -106,7 +106,7 @@ ap1394_if_print(const struct pcap_pkthdr *h, const u_char *p)
        p += FIREWIRE_HDRLEN;
 
        ether_type = EXTRACT_16BITS(&fp->firewire_type);
-       if (ethertype_print(ether_type, p, length, caplen) == 0) {
+       if (ethertype_print(gndo, ether_type, p, length, caplen) == 0) {
                /* ether_type not known, print raw packet */
                if (!eflag)
                        ap1394_hdr_print((u_char *)fp, length + FIREWIRE_HDRLEN);
index e086d1660c090c8b2dd160051e0d996067ec3903..dc6e78cb9d21ca97aacd7ccc71378ff9e07c1ce6 100644 (file)
@@ -23,6 +23,7 @@ static const char rcsid[] _U_ =
     "@(#) $Header: /tcpdump/master/tcpdump/print-ether.c,v 1.106 2008-02-06 10:47:53 guy Exp $ (LBL)";
 #endif
 
+#define NETDISSECT_REWORKED
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -84,7 +85,8 @@ const struct tok ethertype_values[] = {
 };
 
 static inline void
-ether_hdr_print(register const u_char *bp, u_int length)
+ether_hdr_print(netdissect_options *ndo,
+                const u_char *bp, u_int length)
 {
        register const struct ether_header *ep;
        u_int16_t ether_type;
@@ -96,7 +98,7 @@ ether_hdr_print(register const u_char *bp, u_int length)
                     etheraddr_string(EDST(ep)));
 
        ether_type = EXTRACT_16BITS(&ep->ether_type);
-       if (!qflag) {
+       if (!ndo->ndo_qflag) {
                if (ether_type <= ETHERMTU)
                          (void)printf(", 802.3");
                 else 
@@ -120,8 +122,9 @@ ether_hdr_print(register const u_char *bp, u_int length)
  * frame's protocol, and an argument to pass to that function.
  */
 void
-ether_print(const u_char *p, u_int length, u_int caplen,
-    void (*print_encap_header)(const u_char *), const u_char *encap_header_arg)
+ether_print(netdissect_options *ndo,
+            const u_char *p, u_int length, u_int caplen,
+            void (*print_encap_header)(netdissect_options *ndo, const u_char *), const u_char *encap_header_arg)
 {
        struct ether_header *ep;
        u_int orig_length;
@@ -133,10 +136,10 @@ ether_print(const u_char *p, u_int length, u_int caplen,
                return;
        }
 
-       if (eflag) {
+       if (ndo->ndo_eflag) {
                if (print_encap_header != NULL)
-                       (*print_encap_header)(encap_header_arg);
-               ether_hdr_print(p, length);
+                       (*print_encap_header)(ndo, encap_header_arg);
+               ether_hdr_print(ndo, p, length);
        }
        orig_length = length;
 
@@ -156,14 +159,14 @@ recurse:
                if (llc_print(p, length, caplen, ESRC(ep), EDST(ep),
                    &extracted_ether_type) == 0) {
                        /* ether_type not known, print raw packet */
-                       if (!eflag) {
+                       if (!ndo->ndo_eflag) {
                                if (print_encap_header != NULL)
-                                       (*print_encap_header)(encap_header_arg);
-                               ether_hdr_print((u_char *)ep, orig_length);
+                                       (*print_encap_header)(ndo, encap_header_arg);
+                               ether_hdr_print(ndo, (u_char *)ep, orig_length);
                        }
 
-                       if (!suppress_default_print)
-                               default_print(p, caplen);
+                       if (!ndo->ndo_suppress_default_print)
+                               ndo->ndo_default_print(ndo, p, caplen);
                }
        } else if (ether_type == ETHERTYPE_8021Q) {
                /*
@@ -174,7 +177,7 @@ recurse:
                        printf("[|vlan]");
                        return;
                }
-               if (eflag) {
+               if (ndo->ndo_eflag) {
                        u_int16_t tag = EXTRACT_16BITS(p);
 
                        printf("vlan %u, p %u%s, ",
@@ -184,7 +187,7 @@ recurse:
                }
 
                ether_type = EXTRACT_16BITS(p + 2);
-               if (eflag && ether_type > ETHERMTU)
+               if (ndo->ndo_eflag && ether_type > ETHERMTU)
                        printf("ethertype %s, ", tok2str(ethertype_values,"0x%04x", ether_type));
                p += 4;
                length -= 4;
@@ -204,26 +207,26 @@ recurse:
                if (llc_print(p, length, caplen, ESRC(ep), EDST(ep),
                    &extracted_ether_type) == 0) {
                        /* ether_type not known, print raw packet */
-                       if (!eflag) {
+                       if (!ndo->ndo_eflag) {
                                if (print_encap_header != NULL)
-                                       (*print_encap_header)(encap_header_arg);
-                               ether_hdr_print((u_char *)ep, orig_length);
+                                       (*print_encap_header)(ndo, encap_header_arg);
+                               ether_hdr_print(ndo, (u_char *)ep, orig_length);
                        }
 
-                       if (!suppress_default_print)
-                               default_print(p, caplen);
+                       if (!ndo->ndo_suppress_default_print)
+                               ndo->ndo_default_print(ndo, p, caplen);
                }
        } else {
-               if (ethertype_print(ether_type, p, length, caplen) == 0) {
+               if (ethertype_print(ndo, ether_type, p, length, caplen) == 0) {
                        /* ether_type not known, print raw packet */
-                       if (!eflag) {
+                       if (!ndo->ndo_eflag) {
                                if (print_encap_header != NULL)
-                                       (*print_encap_header)(encap_header_arg);
-                               ether_hdr_print((u_char *)ep, orig_length);
+                                       (*print_encap_header)(ndo, encap_header_arg);
+                               ether_hdr_print(ndo, (u_char *)ep, orig_length);
                        }
 
-                       if (!suppress_default_print)
-                               default_print(p, caplen);
+                       if (!ndo->ndo_suppress_default_print)
+                               ndo->ndo_default_print(ndo, p, caplen);
                }
        }
 }
@@ -235,9 +238,10 @@ recurse:
  * is the number of bytes actually captured.
  */
 u_int
-ether_if_print(const struct pcap_pkthdr *h, const u_char *p)
+ether_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h,
+               const u_char *p)
 {
-       ether_print(p, h->len, h->caplen, NULL, NULL);
+       ether_print(ndo, p, h->len, h->caplen, NULL, NULL);
 
        return (ETHER_HDRLEN);
 }
@@ -250,85 +254,87 @@ ether_if_print(const struct pcap_pkthdr *h, const u_char *p)
  */
 
 int
-ethertype_print(u_short ether_type, const u_char *p, u_int length, u_int caplen)
+ethertype_print(netdissect_options *ndo,
+                u_short ether_type, const u_char *p,
+                u_int length, u_int caplen)
 {
        switch (ether_type) {
 
        case ETHERTYPE_IP:
-               ip_print(gndo, p, length);
+               ip_print(ndo, p, length);
                return (1);
 
 #ifdef INET6
        case ETHERTYPE_IPV6:
-               ip6_print(p, length);
+               ip6_print(/*ndo,*/ p, length);
                return (1);
 #endif /*INET6*/
 
        case ETHERTYPE_ARP:
        case ETHERTYPE_REVARP:
-               arp_print(gndo, p, length, caplen);
+               arp_print(ndo, p, length, caplen);
                return (1);
 
        case ETHERTYPE_DN:
-               decnet_print(p, length, caplen);
+               decnet_print(/*ndo,*/p, length, caplen);
                return (1);
 
        case ETHERTYPE_ATALK:
-               if (vflag)
+               if (ndo->ndo_vflag)
                        fputs("et1 ", stdout);
-               atalk_print(p, length);
+               atalk_print(/*ndo,*/p, length);
                return (1);
 
        case ETHERTYPE_AARP:
-               aarp_print(p, length);
+               aarp_print(/*ndo,*/p, length);
                return (1);
 
        case ETHERTYPE_IPX:
                printf("(NOV-ETHII) ");
-               ipx_print(p, length);
+               ipx_print(/*ndo,*/p, length);
                return (1);
 
         case ETHERTYPE_ISO:
-                isoclns_print(p+1, length-1, length-1);
+                isoclns_print(/*ndo,*/p+1, length-1, length-1);
                 return(1);
 
        case ETHERTYPE_PPPOED:
        case ETHERTYPE_PPPOES:
        case ETHERTYPE_PPPOED2:
        case ETHERTYPE_PPPOES2:
-               pppoe_print(p, length);
+               pppoe_print(/*ndo,*/p, length);
                return (1);
 
        case ETHERTYPE_EAPOL:
-               eap_print(gndo, p, length);
+               eap_print(ndo, p, length);
                return (1);
 
        case ETHERTYPE_RRCP:
-               rrcp_print(gndo, p - 14 , length + 14);
+               rrcp_print(ndo, p - 14 , length + 14);
                return (1);
 
        case ETHERTYPE_PPP:
                if (length) {
                        printf(": ");
-                       ppp_print(p, length);
+                       ppp_print(/*ndo,*/p, length);
                }
                return (1);
 
        case ETHERTYPE_MPCP:
-               mpcp_print(p, length);
+               mpcp_print(/*ndo,*/p, length);
                return (1);
 
        case ETHERTYPE_SLOW:
-               slow_print(p, length);
+               slow_print(/*ndo,*/p, length);
                return (1);
 
        case ETHERTYPE_CFM:
        case ETHERTYPE_CFM_OLD:
-               cfm_print(p, length);
+               cfm_print(/*ndo,*/p, length);
                return (1);
 
        case ETHERTYPE_LLDP:
-               lldp_print(p, length);
+               lldp_print(/*ndo,*/p, length);
                return (1);
 
         case ETHERTYPE_LOOPBACK:
@@ -336,7 +342,7 @@ ethertype_print(u_short ether_type, const u_char *p, u_int length, u_int caplen)
 
        case ETHERTYPE_MPLS:
        case ETHERTYPE_MPLS_MULTI:
-               mpls_print(p, length);
+               mpls_print(/*ndo,*/p, length);
                return (1);
 
        case ETHERTYPE_LAT:
index 8f1409e98592ac46fdabb734e3e92f750f7a1f58..6a7c49ddf97d81a9d6eb6cf251d467bfa315225e 100644 (file)
@@ -256,7 +256,7 @@ fr_print(register const u_char *p, u_int length)
                 if (eflag)
                     fr_hdr_print(length, addr_len, dlci, flags, extracted_ethertype);
 
-                if (ethertype_print(extracted_ethertype,
+                if (ethertype_print(gndo, extracted_ethertype,
                                       p+addr_len+ETHERTYPE_LEN,
                                       length-addr_len-ETHERTYPE_LEN,
                                       length-addr_len-ETHERTYPE_LEN) == 0)
index 106e6fd3111abd173fdd49418bbc18148047e821..b45c5b07b068ba1fc7247f8ef121b26b788ca36d 100644 (file)
@@ -226,7 +226,7 @@ gre_print_0(const u_char *bp, u_int length)
                isoclns_print(bp, len, len);
                break;
        case ETHERTYPE_TEB:
-               ether_print(bp, len, len, NULL, NULL);
+               ether_print(gndo, bp, len, len, NULL, NULL);
                break;
        default:
                printf("gre-proto-0x%x", prot);
index acf3bd8be9fe0de2a466231ed54087ac960c7e92..890085c74a5cc3cf35aeeb29eba4e905da449c43 100644 (file)
@@ -573,7 +573,7 @@ ip_print(netdissect_options *ndo,
         else if (!eflag)
            printf("IP ");
 
-       if ((u_char *)(ipds->ip + 1) > snapend) {
+       if ((u_char *)(ipds->ip + 1) > ndo->ndo_snapend) {
                printf("[|ip]");
                return;
        }
@@ -611,8 +611,8 @@ ip_print(netdissect_options *ndo,
         * Cut off the snapshot length to the end of the IP payload.
         */
        ipend = bp + ipds->len;
-       if (ipend < snapend)
-               snapend = ipend;
+       if (ipend < ndo->ndo_snapend)
+               ndo->ndo_snapend = ipend;
 
        ipds->len -= hlen;
 
@@ -658,7 +658,7 @@ ip_print(netdissect_options *ndo,
                 printf(")");
             }
 
-           if (!Kflag && (u_char *)ipds->ip + hlen <= snapend) {
+           if (!Kflag && (u_char *)ipds->ip + hlen <= ndo->ndo_snapend) {
                sum = in_cksum((const u_short *)ipds->ip, hlen, 0);
                if (sum != 0) {
                    ip_sum = EXTRACT_16BITS(&ipds->ip->ip_sum);
index 55ca1c9c640522c4fc0b5519b495416c968cfdb8..901db3238550fc5dd2570f78babf3848cde28961 100644 (file)
@@ -647,7 +647,7 @@ juniper_pppoe_print(const struct pcap_pkthdr *h, register const u_char *p)
 
         p+=l2info.header_len;
         /* this DLT contains nothing but raw ethernet frames */
-        ether_print(p, l2info.length, l2info.caplen, NULL, NULL);
+        ether_print(gndo, p, l2info.length, l2info.caplen, NULL, NULL);
         return l2info.header_len;
 }
 #endif
@@ -664,7 +664,7 @@ juniper_ether_print(const struct pcap_pkthdr *h, register const u_char *p)
 
         p+=l2info.header_len;
         /* this DLT contains nothing but raw Ethernet frames */
-        ether_print(p, l2info.length, l2info.caplen, NULL, NULL);
+        ether_print(gndo, p, l2info.length, l2info.caplen, NULL, NULL);
         return l2info.header_len;
 }
 #endif
@@ -736,7 +736,7 @@ juniper_pppoe_atm_print(const struct pcap_pkthdr *h, register const u_char *p)
         extracted_ethertype = EXTRACT_16BITS(p);
         /* this DLT contains nothing but raw PPPoE frames,
          * prepended with a type field*/
-        if (ethertype_print(extracted_ethertype,
+        if (ethertype_print(gndo, extracted_ethertype,
                               p+ETHERTYPE_LEN,
                               l2info.length-ETHERTYPE_LEN,
                               l2info.caplen-ETHERTYPE_LEN) == 0)
@@ -987,7 +987,7 @@ juniper_atm2_print(const struct pcap_pkthdr *h, register const u_char *p)
 
         if (l2info.direction != JUNIPER_BPF_PKT_IN && /* ether-over-1483 encaps ? */
             (EXTRACT_32BITS(l2info.cookie) & ATM2_GAP_COUNT_MASK)) {
-            ether_print(p, l2info.length, l2info.caplen, NULL, NULL);
+            ether_print(gndo, p, l2info.length, l2info.caplen, NULL, NULL);
             return l2info.header_len;
         }
 
index 54c68c82aa2b426b69432f63a61f8cae2c297d1f..6ebe09029582c2ef07d30810378b09deb875cae9 100644 (file)
@@ -61,7 +61,7 @@ static const struct tok lecop2str[] = {
 };
 
 static void
-lane_hdr_print(const u_char *bp)
+lane_hdr_print(netdissect_options *ndo, const u_char *bp)
 {
        (void)printf("lecid:%x ", EXTRACT_16BITS(bp));
 }
@@ -106,7 +106,7 @@ lane_print(const u_char *p, u_int length, u_int caplen)
         * Now print the encapsulated frame, under the assumption
         * that it's an Ethernet frame.
         */
-       ether_print(p, length, caplen, lane_hdr_print, p - 2);
+       ether_print(gndo, p, length, caplen, lane_hdr_print, p - 2);
 }
 
 u_int
index d20fbdf13c36a151952bc66a0ab7fcaf225b2cb0..a1934715c18843abaf98d4884b5cfe5e7d0f5af5 100644 (file)
@@ -417,7 +417,7 @@ snap_print(const u_char *p, u_int length, u_int caplen, u_int bridge_pad)
                 * Cisco hardware; the protocol ID is
                 * an Ethernet protocol type.
                 */
-               ret = ethertype_print(et, p, length, caplen);
+               ret = ethertype_print(gndo, et, p, length, caplen);
                if (ret)
                        return (ret);
                break;
@@ -432,7 +432,7 @@ snap_print(const u_char *p, u_int length, u_int caplen, u_int bridge_pad)
                         * but used 0x000000 and an Ethernet
                         * packet type for AARP packets.
                         */
-                       ret = ethertype_print(et, p, length, caplen);
+                       ret = ethertype_print(gndo, et, p, length, caplen);
                        if (ret)
                                return (ret);
                }
@@ -479,7 +479,7 @@ snap_print(const u_char *p, u_int length, u_int caplen, u_int bridge_pad)
                        /*
                         * What remains is an Ethernet packet.
                         */
-                       ether_print(p, length, caplen, NULL, NULL);
+                       ether_print(gndo, p, length, caplen, NULL, NULL);
                        return (1);
 
                case PID_RFC2684_802_5_FCS:
index c9546585dcb1c3992611a9abf42e36034da2b16c..a044de6709fbe5ba666db7842e73e4e843f63e5a 100644 (file)
@@ -218,7 +218,7 @@ recurse:
                caplen -= 4;
                goto recurse;
        } else {
-               if (ethertype_print(ether_type, p, length, caplen) == 0) {
+               if (ethertype_print(gndo, ether_type, p, length, caplen) == 0) {
                        /* ether_type not known, print raw packet */
                        if (!eflag)
                                sll_print(sllp, length + SLL_HDR_LEN);
index 0fba8e534de4884bcdd800a2aba79e9decda6c09..8b4ee38c4093a3f23c40a49575616529178933b5 100644 (file)
@@ -107,7 +107,7 @@ symantec_if_print(const struct pcap_pkthdr *h, const u_char *p)
 
                if (!suppress_default_print)
                        default_print(p, caplen);
-       } else if (ethertype_print(ether_type, p, length, caplen) == 0) {
+       } else if (ethertype_print(gndo, ether_type, p, length, caplen) == 0) {
                /* ether_type not known, print raw packet */
                if (!eflag)
                        symantec_hdr_print((u_char *)sp, length + sizeof (struct symantec_header));
index 1ae612acd869b9c4fcbfcf8927a2e74cf689fec5..83bfc8063ae017bd64e5f7f4e7a84bce6bb6c486 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -154,7 +154,6 @@ static struct printer printers[] = {
 #ifdef DLT_ARCNET_LINUX
        { arcnet_linux_if_print, DLT_ARCNET_LINUX },
 #endif
-       { ether_if_print,       DLT_EN10MB },
        { token_if_print,       DLT_IEEE802 },
 #ifdef DLT_LANE8023
        { lane_if_print,        DLT_LANE8023 },
@@ -306,6 +305,7 @@ static struct printer printers[] = {
 };
 
 static struct ndo_printer ndo_printers[] = {
+       { ether_if_print,       DLT_EN10MB },
 #ifdef DLT_IPNET
        { ipnet_if_print,       DLT_IPNET },
 #endif