]> The Tcpdump Group git mirrors - tcpdump/commitdiff
NDOize CIP, IPComp and IPFC decoders
authorDenis Ovsienko <[email protected]>
Fri, 28 Feb 2014 09:42:37 +0000 (13:42 +0400)
committerDenis Ovsienko <[email protected]>
Fri, 28 Feb 2014 14:42:47 +0000 (18:42 +0400)
Also remove some unneeded includes while at it.

interface.h
netdissect.h
print-cip.c
print-ip.c
print-ip6.c
print-ipcomp.c
print-ipfc.c
tcpdump.c

index f636e482069dae26555404a8a82cd31b03102133..fd7b6f77873848c3eee36de54b0af14891ee557d 100644 (file)
@@ -219,7 +219,6 @@ extern void icmp_print(const u_char *, u_int, const u_char *, int);
 extern void igmp_print(const u_char *, u_int);
 extern void igrp_print(const u_char *, u_int, const u_char *);
 extern void ipN_print(const u_char *, u_int);
-extern u_int ipfc_if_print(const struct pcap_pkthdr *, const u_char *);
 extern void ipx_print(const u_char *, u_int);
 extern void isoclns_print(const u_char *, u_int, u_int);
 extern void krb_print(const u_char *);
@@ -265,7 +264,6 @@ extern void rip_print(const u_char *, u_int);
 extern u_int sl_if_print(const struct pcap_pkthdr *, const u_char *);
 extern void lane_print(const u_char *, u_int, u_int);
 extern u_int lane_if_print(const struct pcap_pkthdr *, const u_char *);
-extern u_int cip_if_print(const struct pcap_pkthdr *, const u_char *);
 extern u_int sl_bsdos_if_print(const struct pcap_pkthdr *, const u_char *);
 extern u_int chdlc_if_print(const struct pcap_pkthdr *, const u_char *);
 extern u_int chdlc_print(register const u_char *, u_int);
@@ -295,7 +293,6 @@ extern void udld_print(const u_char *, u_int);
 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 int ipcomp_print(register const u_char *, int *);
 extern void rx_print(register const u_char *, int, int, int, u_char *);
 extern void netbeui_print(u_short, const u_char *, int);
 extern void ipx_netbios_print(const u_char *, u_int);
index 15c127f164e7d71de2ec747206a7c3519ee4b075..54474157cae6a564deb6a3c054502da9724156a7 100644 (file)
@@ -371,6 +371,9 @@ extern void hex_print(netdissect_options *,const char *ident, const u_char *cp,u
 extern int ah_print(netdissect_options *, register const u_char *);
 extern void beep_print(netdissect_options *, const u_char *, u_int);
 extern void dtp_print(netdissect_options *, const u_char *, u_int);
+extern u_int cip_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *);
+extern int ipcomp_print(netdissect_options *, register const u_char *, int *);
+extern u_int ipfc_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *);
 
 /* stuff that has not yet been rototiled */
 extern const u_char * ns_nprint (register const u_char *, register const u_char *);
@@ -474,7 +477,6 @@ extern void sctp_print(netdissect_options *ndo,
 extern void sl_if_print(u_char *,const struct pcap_pkthdr *, const u_char *);
 
 extern void lane_if_print(u_char *,const struct pcap_pkthdr *,const u_char *);
-extern void cip_if_print(u_char *,const struct pcap_pkthdr *,const u_char *);
 extern void sl_bsdos_if_print(u_char *,
                              const struct pcap_pkthdr *, const u_char *);
 extern void sll_if_print(u_char *,
@@ -491,8 +493,6 @@ 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 int ipcomp_print(netdissect_options *,register const u_char *,
-                       register const u_char *, int *);
 extern void rx_print(netdissect_options *,register const u_char *,
                     int, int, int, u_char *);
 extern void netbeui_print(netdissect_options *,u_short,
index 83e08ded0cdafc2dcd7d5caa33bb14e67017021b..8ac2f04ef40784cba8a222b2bcad16c45b3949d0 100644 (file)
 
 #include <tcpdump-stdinc.h>
 
-#include <stdio.h>
-
 #include "interface.h"
 #include "addrtoname.h"
-#include "ethertype.h"
-#include "ether.h"
 
 #define RFC1483LLC_LEN 8
 
@@ -46,12 +42,12 @@ static const unsigned char rfcllc[] = {
        0x00 };
 
 static inline void
-cip_print(int length)
+cip_print(netdissect_options *ndo, int length)
 {
        /*
         * There is no MAC-layer header, so just print the length.
         */
-       printf("%d: ", length);
+       ND_PRINT((ndo, "%d: ", length));
 }
 
 /*
@@ -61,19 +57,19 @@ cip_print(int length)
  * is the number of bytes actually captured.
  */
 u_int
-cip_if_print(const struct pcap_pkthdr *h, const u_char *p)
+cip_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p)
 {
        u_int caplen = h->caplen;
        u_int length = h->len;
        u_short extracted_ethertype;
 
        if (memcmp(rfcllc, p, sizeof(rfcllc))==0 && caplen < RFC1483LLC_LEN) {
-               printf("[|cip]");
+               ND_PRINT((ndo, "[|cip]"));
                return (0);
        }
 
-       if (eflag)
-               cip_print(length);
+       if (ndo->ndo_eflag)
+               cip_print(ndo, length);
 
        if (memcmp(rfcllc, p, sizeof(rfcllc)) == 0) {
                /*
@@ -82,20 +78,20 @@ cip_if_print(const struct pcap_pkthdr *h, const u_char *p)
                if (llc_print(p, length, caplen, NULL, NULL,
                    &extracted_ethertype) == 0) {
                        /* ether_type not known, print raw packet */
-                       if (!eflag)
-                               cip_print(length);
+                       if (!ndo->ndo_eflag)
+                               cip_print(ndo, length);
                        if (extracted_ethertype) {
-                               printf("(LLC %s) ",
-                              etherproto_string(htons(extracted_ethertype)));
+                               ND_PRINT((ndo, "(LLC %s) ",
+                              etherproto_string(htons(extracted_ethertype))));
                        }
-                       if (!suppress_default_print)
-                               default_print(p, caplen);
+                       if (!ndo->ndo_suppress_default_print)
+                               ndo->ndo_default_print(ndo, p, caplen);
                }
        } else {
                /*
                 * LLC header is absent; treat it as just IP.
                 */
-               ip_print(gndo, p, length);
+               ip_print(ndo, p, length);
        }
 
        return (0);
index b069e4de30979817d8c0890659aa8b470b026245..cdbd30806071f60b352a7ed31b4cf0f00394c214 100644 (file)
@@ -351,7 +351,7 @@ again:
        case IPPROTO_IPCOMP:
        {
                int enh;
-               ipds->advance = ipcomp_print(ipds->cp, &enh);
+               ipds->advance = ipcomp_print(ndo, ipds->cp, &enh);
                if (ipds->advance <= 0)
                        break;
                ipds->cp += ipds->advance;
index 8e088cd573cc8f4a6a79e281bd3ea3130de3947c..a2d35ffec3fbf0712d9716bea46603074f92f451 100644 (file)
@@ -219,7 +219,7 @@ ip6_print(netdissect_options *ndo, const u_char *bp, u_int length)
                case IPPROTO_IPCOMP:
                    {
                        int enh;
-                       advance = ipcomp_print(cp, &enh);
+                       advance = ipcomp_print(ndo, cp, &enh);
                        nh = enh & 0xff;
                        break;
                    }
index 67cb9fffa42f2ad897295ab5ec7a3cfc873f9172..e5a38b6a52affce3c12189b668b8ce2be48baa0e 100644 (file)
 #include "config.h"
 #endif
 
-#include <string.h>
 #include <tcpdump-stdinc.h>
 
-#include <stdio.h>
-
 struct ipcomp {
        u_int8_t comp_nxt;      /* Next Header */
        u_int8_t comp_flags;    /* Length of data, in 32bit */
@@ -38,11 +35,11 @@ struct ipcomp {
 #include <zlib.h>
 #endif
 
-#include "interface.h"
+#include "netdissect.h"
 #include "extract.h"
 
 int
-ipcomp_print(register const u_char *bp, int *nhdr _U_)
+ipcomp_print(netdissect_options *ndo, register const u_char *bp, int *nhdr _U_)
 {
        register const struct ipcomp *ipcomp;
        register const u_char *ep;
@@ -55,13 +52,13 @@ ipcomp_print(register const u_char *bp, int *nhdr _U_)
        cpi = EXTRACT_16BITS(&ipcomp->comp_cpi);
 
        /* 'ep' points to the end of available data. */
-       ep = snapend;
+       ep = ndo->ndo_snapend;
 
        if ((u_char *)(ipcomp + 1) >= ep - sizeof(struct ipcomp)) {
-               fputs("[|IPCOMP]", stdout);
+               ND_PRINT((ndo, "[|IPCOMP]"));
                goto fail;
        }
-       printf("IPComp(cpi=0x%04x)", cpi);
+       ND_PRINT((ndo, "IPComp(cpi=0x%04x)", cpi));
 
 #if defined(HAVE_LIBZ) && defined(HAVE_ZLIB_H)
        if (1)
@@ -76,7 +73,7 @@ ipcomp_print(register const u_char *bp, int *nhdr _U_)
                *nhdr = ipcomp->comp_nxt;
        advance = sizeof(struct ipcomp);
 
-       printf(": ");
+       ND_PRINT((ndo, ": "));
        return advance;
 
 #endif
index ea68f95b27b1d3e28912e1b2ed04834d1d1ca571..d03b590ef07dc6bb4a2e8ac2bd1b57898b379dd6 100644 (file)
 
 #include <tcpdump-stdinc.h>
 
-#include <stdio.h>
 #include <string.h>
 
 #include "interface.h"
 #include "addrtoname.h"
-#include "ethertype.h"
 
 #include "ether.h"
 
@@ -62,7 +60,8 @@ extract_ipfc_addrs(const struct ipfc_header *ipfcp, char *ipfcsrc,
  * Print the Network_Header
  */
 static inline void
-ipfc_hdr_print(register const struct ipfc_header *ipfcp _U_,
+ipfc_hdr_print(netdissect_options *ndo,
+          register const struct ipfc_header *ipfcp _U_,
           register u_int length, register const u_char *ipfcsrc,
           register const u_char *ipfcdst)
 {
@@ -74,18 +73,18 @@ ipfc_hdr_print(register const struct ipfc_header *ipfcp _U_,
        /*
         * XXX - show the upper 16 bits?  Do so only if "vflag" is set?
         */
-       (void) printf("%s %s %d: ", srcname, dstname, length);
+       ND_PRINT((ndo, "%s %s %d: ", srcname, dstname, length));
 }
 
 static void
-ipfc_print(const u_char *p, u_int length, u_int caplen)
+ipfc_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen)
 {
        const struct ipfc_header *ipfcp = (const struct ipfc_header *)p;
        struct ether_header ehdr;
        u_short extracted_ethertype;
 
        if (caplen < IPFC_HDRLEN) {
-               printf("[|ipfc]");
+               ND_PRINT((ndo, "[|ipfc]"));
                return;
        }
        /*
@@ -93,8 +92,8 @@ ipfc_print(const u_char *p, u_int length, u_int caplen)
         */
        extract_ipfc_addrs(ipfcp, (char *)ESRC(&ehdr), (char *)EDST(&ehdr));
 
-       if (eflag)
-               ipfc_hdr_print(ipfcp, length, ESRC(&ehdr), EDST(&ehdr));
+       if (ndo->ndo_eflag)
+               ipfc_hdr_print(ndo, ipfcp, length, ESRC(&ehdr), EDST(&ehdr));
 
        /* Skip over Network_Header */
        length -= IPFC_HDRLEN;
@@ -108,15 +107,15 @@ ipfc_print(const u_char *p, u_int length, u_int caplen)
                 * Some kinds of LLC packet we cannot
                 * handle intelligently
                 */
-               if (!eflag)
-                       ipfc_hdr_print(ipfcp, length + IPFC_HDRLEN,
+               if (!ndo->ndo_eflag)
+                       ipfc_hdr_print(ndo, ipfcp, length + IPFC_HDRLEN,
                            ESRC(&ehdr), EDST(&ehdr));
                if (extracted_ethertype) {
-                       printf("(LLC %s) ",
-               etherproto_string(htons(extracted_ethertype)));
+                       ND_PRINT((ndo, "(LLC %s) ",
+               etherproto_string(htons(extracted_ethertype))));
                }
-               if (!suppress_default_print)
-                       default_print(p, caplen);
+               if (!ndo->ndo_suppress_default_print)
+                       ndo->ndo_default_print(ndo, p, caplen);
        }
 }
 
@@ -127,9 +126,9 @@ ipfc_print(const u_char *p, u_int length, u_int caplen)
  * is the number of bytes actually captured.
  */
 u_int
-ipfc_if_print(const struct pcap_pkthdr *h, register const u_char *p)
+ipfc_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, register const u_char *p)
 {
-       ipfc_print(p, h->len, h->caplen);
+       ipfc_print(ndo, p, h->len, h->caplen);
 
        return (IPFC_HDRLEN);
 }
index 1e3d906d0a1210c070d6a39eab4cb0fab379f3f1..fc5b52ee0da718b38d33f8a2aad64decd6d94f18 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -174,12 +174,6 @@ static const struct printer printers[] = {
        { token_if_print,       DLT_IEEE802 },
 #ifdef DLT_LANE8023
        { lane_if_print,        DLT_LANE8023 },
-#endif
-#ifdef DLT_CIP
-       { cip_if_print,         DLT_CIP },
-#endif
-#ifdef DLT_ATM_CLIP
-       { cip_if_print,         DLT_ATM_CLIP },
 #endif
        { sl_if_print,          DLT_SLIP },
 #ifdef DLT_SLIP_BSDOS
@@ -232,9 +226,6 @@ static const struct printer printers[] = {
 #ifdef DLT_SUNATM
        { sunatm_if_print,      DLT_SUNATM },
 #endif
-#ifdef DLT_IP_OVER_FC
-       { ipfc_if_print,        DLT_IP_OVER_FC },
-#endif
 #ifdef DLT_PRISM_HEADER
        { prism_if_print,       DLT_PRISM_HEADER },
 #endif
@@ -343,6 +334,15 @@ static const struct ndo_printer ndo_printers[] = {
 #endif
 #if defined(DLT_NFLOG) && defined(HAVE_PCAP_NFLOG_H)
        { nflog_if_print,       DLT_NFLOG},
+#endif
+#ifdef DLT_CIP
+       { cip_if_print,         DLT_CIP },
+#endif
+#ifdef DLT_ATM_CLIP
+       { cip_if_print,         DLT_ATM_CLIP },
+#endif
+#ifdef DLT_IP_OVER_FC
+       { ipfc_if_print,        DLT_IP_OVER_FC },
 #endif
        { NULL,                 0 },
 };