]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Get rid of support for non-NDOified printers.
authorGuy Harris <[email protected]>
Tue, 10 Mar 2015 20:25:52 +0000 (13:25 -0700)
committerGuy Harris <[email protected]>
Tue, 10 Mar 2015 20:25:52 +0000 (13:25 -0700)
Remove the TTEST{2}/TCHECK{2} macros.  Rename all "ndo_printer" routines,
structures, and structure members to just "printer", and get rid of the
old routines/structures/structure members with those names.

addrtoname.c
interface.h
netdissect.h
print-pktap.c
print-ppi.c
tcpdump.c

index d0437fe490a37e11f3fb399264cfd8347dec44ca..6d957389ba4ac3a9d86aae3232b4a92e7a92b152 100644 (file)
@@ -205,7 +205,7 @@ static uint32_t f_localnet;
  *
  * NOTE: ap is *NOT* necessarily part of the packet data (not even if
  * this is being called with the "ipaddr_string()" macro), so you
- * *CANNOT* use the TCHECK{2}/TTEST{2} macros on it.  Furthermore,
+ * *CANNOT* use the ND_TCHECK{2}/ND_TTEST{2} macros on it.  Furthermore,
  * even in cases where it *is* part of the packet data, the caller
  * would still have to check for a null return value, even if it's
  * just printing the return value with "%s" - not all versions of
index 59c1eefdb790d4747dc93e38dd3722c7d55978d5..2389c2e1e1ab9f1d26f39fac65789e76b3305b35 100644 (file)
@@ -97,38 +97,6 @@ extern char *program_name;   /* used to generate self-identifying messages */
 
 extern int32_t thiszone;       /* seconds offset from gmt to local time */
 
-/*
- * True if  "l" bytes of "var" were captured.
- *
- * The "snapend - (l) <= snapend" checks to make sure "l" isn't so large
- * that "snapend - (l)" underflows.
- *
- * The check is for <= rather than < because "l" might be 0.
- *
- * We cast the pointers to uintptr_t to make sure that the compiler
- * doesn't optimize away any of these tests (which it is allowed to
- * do, as adding an integer to, or subtracting an integer from, a
- * pointer assumes that the pointer is a pointer to an element of an
- * array and that the result of the addition or subtraction yields a
- * pointer to another member of the array, so that, for example, if
- * you subtract a positive integer from a pointer, the result is
- * guaranteed to be less than the original pointer value). See
- *
- *     http://www.kb.cert.org/vuls/id/162289
- */
-#define TTEST2(var, l) \
-       ((uintptr_t)snapend - (l) <= (uintptr_t)snapend && \
-          (uintptr_t)&(var) <= (uintptr_t)snapend - (l))
-
-/* True if "var" was captured */
-#define TTEST(var) TTEST2(var, sizeof(var))
-
-/* Bail if "l" bytes of "var" were not captured */
-#define TCHECK2(var, l) if (!TTEST2(var, l)) goto trunc
-
-/* Bail if "var" was not captured */
-#define TCHECK(var) TCHECK2(var, sizeof(var))
-
 extern int mask2plen(uint32_t);
 extern const char *tok2strary_internal(const char **, int, const char *, int);
 #define        tok2strary(a,f,i) tok2strary_internal(a, sizeof(a)/sizeof(a[0]),f,i)
index 4580e73dd26fda80b911028d96d97f01637a0d93..b25f4c9fd5e79487f4d22e9858deb63b8f42bec3 100644 (file)
@@ -360,11 +360,9 @@ extern const char *dnnum_string(netdissect_options *, u_short);
 
 extern char *q922_string(netdissect_options *ndo, const u_char *, u_int);
 
-typedef u_int (*if_ndo_printer)(struct netdissect_options *ndo,
+typedef u_int (*if_printer)(struct netdissect_options *ndo,
                                const struct pcap_pkthdr *, const u_char *);
-typedef u_int (*if_printer)(const struct pcap_pkthdr *, const u_char *);
 
-extern if_ndo_printer lookup_ndo_printer(int);
 extern if_printer lookup_printer(int);
 
 extern void eap_print(netdissect_options *,const u_char *, u_int);
index 46a187de2f33df4bf4517b484d446318ce38f170..e376cc6e6ab96c7336bdc2dc448fbcb1509ae140 100644 (file)
@@ -99,8 +99,7 @@ pktap_if_print(netdissect_options *ndo,
        uint32_t dlt, hdrlen, rectype;
        u_int caplen = h->caplen;
        u_int length = h->len;
-       if_ndo_printer ndo_printer;
-        if_printer printer;
+       if_printer printer;
        pktap_header_t *hdr;
 
        if (caplen < sizeof(pktap_header_t) || length < sizeof(pktap_header_t)) {
@@ -142,9 +141,7 @@ pktap_if_print(netdissect_options *ndo,
 
        case PKT_REC_PACKET:
                if ((printer = lookup_printer(dlt)) != NULL) {
-                       printer(h, p);
-               } else if ((ndo_printer = lookup_ndo_printer(dlt)) != NULL) {
-                       ndo_printer(ndo, h, p);
+                       printer(ndo, h, p);
                } else {
                        if (!ndo->ndo_eflag)
                                pktap_header_print(ndo, (u_char *)hdr,
index b403536362464ba049724d911b6e7f168f3ef977..06678b0f65aaa86acafd0e1c5a807cef98a0b0b0 100644 (file)
@@ -49,8 +49,7 @@ static void
 ppi_print(netdissect_options *ndo,
                const struct pcap_pkthdr *h, const u_char *p)
 {
-       if_ndo_printer ndo_printer;
-        if_printer printer;
+       if_printer printer;
        ppi_header_t *hdr;
        u_int caplen = h->caplen;
        u_int length = h->len;
@@ -82,9 +81,7 @@ ppi_print(netdissect_options *ndo,
        p += len;
 
        if ((printer = lookup_printer(dlt)) != NULL) {
-               printer(h, p);
-       } else if ((ndo_printer = lookup_ndo_printer(dlt)) != NULL) {
-               ndo_printer(ndo, h, p);
+               printer(ndo, h, p);
        } else {
                if (!ndo->ndo_eflag)
                        ppi_header_print(ndo, (u_char *)hdr, length + len);
index 2fd1617728e9e668d561239320db53fe680aec44..2a32adbabb6468fdd05152373636c7b21a5b5fdb 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -193,22 +193,12 @@ static void info(int);
 static u_int packets_captured;
 
 struct printer {
-        if_printer f;
-       int type;
-};
-
-
-struct ndo_printer {
-        if_ndo_printer f;
+       if_printer f;
        int type;
 };
 
 
 static const struct printer printers[] = {
-       { NULL,                 0 },
-};
-
-static const struct ndo_printer ndo_printers[] = {
        { ether_if_print,       DLT_EN10MB },
 #ifdef DLT_IPNET
        { ipnet_if_print,       DLT_IPNET },
@@ -408,19 +398,6 @@ lookup_printer(int type)
                if (type == p->type)
                        return p->f;
 
-       return NULL;
-       /* NOTREACHED */
-}
-
-if_ndo_printer
-lookup_ndo_printer(int type)
-{
-       const struct ndo_printer *p;
-
-       for (p = ndo_printers; p->f; ++p)
-               if (type == p->type)
-                       return p->f;
-
 #if defined(DLT_USER2) && defined(DLT_PKTAP)
        /*
         * Apple incorrectly chose to use DLT_USER2 for their PKTAP
@@ -439,7 +416,7 @@ lookup_ndo_printer(int type)
         * that.
         */
        if (type == DLT_USER2) {
-               for (p = ndo_printers; p->f; ++p)
+               for (p = printers; p->f; ++p)
                        if (DLT_PKTAP == p->type)
                                return p->f;
        }
@@ -459,11 +436,7 @@ extern char *optarg;
 
 struct print_info {
         netdissect_options *ndo;
-        union {
-                if_printer     printer;
-                if_ndo_printer ndo_printer;
-        } p;
-        int ndo_type;
+        if_printer printer;
 };
 
 struct dump_info {
@@ -548,8 +521,7 @@ show_dlts_and_exit(const char *device, pcap_t *pd)
                        /*
                         * OK, does tcpdump handle that type?
                         */
-                       if (lookup_printer(dlts[n_dlts]) == NULL
-                            && lookup_ndo_printer(dlts[n_dlts]) == NULL)
+                       if (lookup_printer(dlts[n_dlts]) == NULL)
                                (void) fprintf(stderr, " (printing not supported)");
                        fprintf(stderr, "\n");
                } else {
@@ -862,20 +834,15 @@ get_print_info(int type)
 {
        struct print_info printinfo;
 
-       printinfo.ndo_type = 1;
        printinfo.ndo = gndo;
-       printinfo.p.ndo_printer = lookup_ndo_printer(type);
-       if (printinfo.p.ndo_printer == NULL) {
-               printinfo.p.printer = lookup_printer(type);
-               printinfo.ndo_type = 0;
-               if (printinfo.p.printer == NULL) {
-                       gndo->ndo_dltname = pcap_datalink_val_to_name(type);
-                       if (gndo->ndo_dltname != NULL)
-                               error("packet printing is not supported for link type %s: use -w",
-                                     gndo->ndo_dltname);
-                       else
-                               error("packet printing is not supported for link type %d: use -w", type);
-               }
+       printinfo.printer = lookup_printer(type);
+       if (printinfo.printer == NULL) {
+               gndo->ndo_dltname = pcap_datalink_val_to_name(type);
+               if (gndo->ndo_dltname != NULL)
+                       error("packet printing is not supported for link type %s: use -w",
+                             gndo->ndo_dltname);
+               else
+                       error("packet printing is not supported for link type %d: use -w", type);
        }
        return (printinfo);
 }
@@ -2465,11 +2432,7 @@ print_packet(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
         */
        ndo->ndo_snapend = sp + h->caplen;
 
-        if(print_info->ndo_type) {
-                hdrlen = (*print_info->p.ndo_printer)(print_info->ndo, h, sp);
-        } else {
-                hdrlen = (*print_info->p.printer)(h, sp);
-        }
+        hdrlen = (*print_info->printer)(print_info->ndo, h, sp);
 
        /*
         * Restore the original snapend, as a printer might have