]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Move if_printer to structure netdissect_options
authorFrancois-Xavier Le Bail <[email protected]>
Mon, 14 Sep 2015 13:34:13 +0000 (15:34 +0200)
committerFrancois-Xavier Le Bail <[email protected]>
Mon, 14 Sep 2015 13:54:54 +0000 (15:54 +0200)
The structure 'netdissect_options' can hold if_printer.
Thus the structure 'print_info' is useless now.

Moreover:
Delete useless blank lines
Fix indent

netdissect.h
print.c
print.h
tcpdump.c

index 552d46a940c80b09dd2921304ded23e3c75df6c6..57d3f7c2a62c1f1eaeb874baaf88ccaa11fef154 100644 (file)
@@ -37,6 +37,7 @@
 /* snprintf et al */
 
 #include <stdarg.h>
+#include <pcap.h>
 
 #include "ip.h" /* struct ip for nextproto4_cksum() */
 
@@ -88,6 +89,9 @@ extern char *bittok2str_nosep(const struct tok *, const char *, u_int);
 
 typedef struct netdissect_options netdissect_options;
 
+typedef u_int (*if_printer)(netdissect_options *ndo,
+                           const struct pcap_pkthdr *, const u_char *);
+
 struct netdissect_options {
   int ndo_bflag;               /* print 4 byte ASes in ASDOT notation */
   int ndo_eflag;               /* print ethernet header */
@@ -130,9 +134,12 @@ struct netdissect_options {
   const u_char *ndo_packetp;
   const u_char *ndo_snapend;
 
+  /* pointer to the if_printer function */
+  if_printer ndo_if_printer;
+
   /* pointer to void function to output stuff */
   void (*ndo_default_print)(netdissect_options *,
-                     register const u_char *bp, register u_int length);
+                           register const u_char *bp, register u_int length);
 
   /* pointer to function to do regular output */
   int  (*ndo_printf)(netdissect_options *,
@@ -338,13 +345,8 @@ extern int mask62plen(const u_char *);
 
 /* The printer routines. */
 
-#include <pcap.h>
-
 extern char *q922_string(netdissect_options *ndo, const u_char *, u_int);
 
-typedef u_int (*if_printer)(struct netdissect_options *ndo,
-                               const struct pcap_pkthdr *, const u_char *);
-
 extern if_printer lookup_printer(int);
 
 extern void eap_print(netdissect_options *,const u_char *, u_int);
diff --git a/print.c b/print.c
index 8f68bae380381ec1fdffc085a9cc8e259fd1e4e6..05e052272b50e394c91508c656c379dc8bbaa174 100644 (file)
--- a/print.c
+++ b/print.c
@@ -223,7 +223,6 @@ static const struct printer printers[] = {
        { NULL,                 0 },
 };
 
-
 static void    ndo_default_print(netdissect_options *ndo, const u_char *bp,
                    u_int length);
 
@@ -295,19 +294,17 @@ lookup_printer(int type)
 int
 has_printer(int type)
 {
-
        return (lookup_printer(type) != NULL);
 }
 
-struct print_info
-get_print_info(netdissect_options *ndo, int type)
+if_printer
+get_if_printer(netdissect_options *ndo, int type)
 {
        const char *dltname;
-       struct print_info printinfo;
+       if_printer printer;
 
-       printinfo.ndo = ndo;
-       printinfo.printer = lookup_printer(type);
-       if (printinfo.printer == NULL) {
+       printer = lookup_printer(type);
+       if (printer == NULL) {
                dltname = pcap_datalink_val_to_name(type);
                if (dltname != NULL)
                        (*ndo->ndo_error)(ndo,
@@ -317,17 +314,14 @@ get_print_info(netdissect_options *ndo, int type)
                        (*ndo->ndo_error)(ndo,
                                          "packet printing is not supported for link type %d: use -w", type);
        }
-       return (printinfo);
+       return printer;
 }
 
 void
-pretty_print_packet(struct print_info *print_info, const struct pcap_pkthdr *h,
+pretty_print_packet(netdissect_options *ndo, const struct pcap_pkthdr *h,
     const u_char *sp, u_int packets_captured)
 {
        u_int hdrlen;
-        netdissect_options *ndo;
-
-        ndo = print_info->ndo;
 
        if(ndo->ndo_packet_number)
                ND_PRINT((ndo, "%5u  ", packets_captured));
@@ -342,7 +336,7 @@ pretty_print_packet(struct print_info *print_info, const struct pcap_pkthdr *h,
         */
        ndo->ndo_snapend = sp + h->caplen;
 
-        hdrlen = (*print_info->printer)(print_info->ndo, h, sp);
+        hdrlen = (ndo->ndo_if_printer)(ndo, h, sp);
 
        /*
         * Restore the original snapend, as a printer might have
@@ -474,7 +468,6 @@ ndo_printf(netdissect_options *ndo _U_, const char *fmt, ...)
 void
 ndo_set_function_pointers(netdissect_options *ndo)
 {
-
        ndo->ndo_default_print=ndo_default_print;
        ndo->ndo_printf=ndo_printf;
        ndo->ndo_error=ndo_error;
diff --git a/print.h b/print.h
index f69c2ff4e23e4621dcd0769dd7078b254dec8315..50b172005e291ed1faae09b99e413d77f163b736 100644 (file)
--- a/print.h
+++ b/print.h
 #ifndef print_h
 #define print_h
 
-struct print_info {
-       netdissect_options *ndo;
-       if_printer printer;
-};
-
 void   init_print(netdissect_options *ndo, u_int32_t localnet, u_int32_t mask,
            uint32_t timezone_offset);
 
 int    has_printer(int type);
 
-struct print_info      get_print_info(netdissect_options *ndo, int type);
+if_printer get_if_printer(netdissect_options *ndo, int type);
 
-void   pretty_print_packet(struct print_info *print_info,
+void   pretty_print_packet(netdissect_options *ndo,
            const struct pcap_pkthdr *h, const u_char *sp,
            u_int packets_captured);
 
index 960a42f30a135853cc5aabe0154c0f45bf132109..eb1241ad3859b937ef4eb3984daa5fbbadfd3490 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -711,7 +711,6 @@ main(int argc, char **argv)
        int timezone_offset = 0;
        register char *cp, *infile, *cmdbuf, *device, *RFileName, *VFileName, *WFileName;
        pcap_handler callback;
-       int type;
        int dlt;
        int new_dlt;
        const char *dlt_name;
@@ -719,7 +718,6 @@ main(int argc, char **argv)
 #ifndef _WIN32
        RETSIGTYPE (*oldhandler)(int);
 #endif
-       struct print_info printinfo;
        struct dump_info dumpinfo;
        u_char *pcap_userdata;
        char ebuf[PCAP_ERRBUF_SIZE];
@@ -1646,10 +1644,10 @@ main(int argc, char **argv)
                        pcap_dump_flush(p);
 #endif
        } else {
-               type = pcap_datalink(pd);
-               printinfo = get_print_info(ndo, type);
+               dlt = pcap_datalink(pd);
+               ndo->ndo_if_printer = get_if_printer(ndo, dlt);
                callback = print_packet;
-               pcap_userdata = (u_char *)&printinfo;
+               pcap_userdata = (u_char *)ndo;
        }
 
 #ifdef SIGNAL_REQ_INFO
@@ -1767,7 +1765,7 @@ main(int argc, char **argv)
                                new_dlt = pcap_datalink(pd);
                                if (WFileName && new_dlt != dlt)
                                        error("%s: new dlt does not match original", RFileName);
-                               printinfo = get_print_info(ndo, new_dlt);
+                               ndo->ndo_if_printer = get_if_printer(ndo, new_dlt);
                                dlt_name = pcap_datalink_val_to_name(new_dlt);
                                if (dlt_name == NULL) {
                                        fprintf(stderr, "reading from file %s, link-type %u\n",
@@ -2150,15 +2148,11 @@ dump_packet(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
 static void
 print_packet(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
 {
-       struct print_info *print_info;
-
        ++packets_captured;
 
        ++infodelay;
 
-       print_info = (struct print_info *)user;
-
-       pretty_print_packet(print_info, h, sp, packets_captured);
+       pretty_print_packet((netdissect_options *)user, h, sp, packets_captured);
 
        --infodelay;
        if (infoprint)