]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Pass an ndo to the print API rather than using gndo.
authorBrooks Davis <[email protected]>
Fri, 24 Apr 2015 15:22:05 +0000 (15:22 +0000)
committerBrooks Davis <[email protected]>
Mon, 27 Apr 2015 00:10:23 +0000 (00:10 +0000)
Since gndo is only referenced in main() move it there.

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

index 1773e8788340b83ec755d765034363e6d72c6ace..2eb59272da3869e4897bc5cdaab6a0cdf20bc5c3 100644 (file)
@@ -615,6 +615,4 @@ extern int esp_print_decrypt_buffer_by_ikev2(netdissect_options *ndo,
 extern void geonet_print(netdissect_options *ndo,const u_char *eth_hdr,const u_char *geo_pck, u_int len);
 extern void calm_fast_print(netdissect_options *ndo,const u_char *eth_hdr,const u_char *calm_pck, u_int len);
 
-extern netdissect_options *gndo;
-
 #endif  /* netdissect_h */
diff --git a/print.c b/print.c
index 648a899317e9aa20fc682e222213e92c47ba7067..69aa45899ac9af911cb8b957b5a0c6e13877f764 100644 (file)
--- a/print.c
+++ b/print.c
@@ -247,11 +247,12 @@ static int        tcpdump_printf(netdissect_options *ndo _U_, const char *fmt, ...)
                     ;
 
 void
-init_print(u_int32_t localnet, u_int32_t mask, uint32_t timezone_offset)
+init_print(netdissect_options *ndo, u_int32_t localnet, u_int32_t mask,
+    uint32_t timezone_offset)
 {
 
        thiszone = timezone_offset;
-       init_addrtoname(gndo, localnet, mask);
+       init_addrtoname(ndo, localnet, mask);
        init_checksum();
 }
 
@@ -300,17 +301,18 @@ has_printer(int type)
 }
 
 struct print_info
-get_print_info(int type)
+get_print_info(netdissect_options *ndo, int type)
 {
+       const char *dltname;
        struct print_info printinfo;
 
-       printinfo.ndo = gndo;
+       printinfo.ndo = ndo;
        printinfo.printer = lookup_printer(type);
        if (printinfo.printer == NULL) {
-               gndo->ndo_dltname = pcap_datalink_val_to_name(type);
-               if (gndo->ndo_dltname != NULL)
+               dltname = pcap_datalink_val_to_name(type);
+               if (dltname != NULL)
                        error("packet printing is not supported for link type %s: use -w",
-                             gndo->ndo_dltname);
+                             dltname);
                else
                        error("packet printing is not supported for link type %d: use -w", type);
        }
diff --git a/print.h b/print.h
index 048359da47ed2bb16b7d0374368c82b5e37b52d6..f69c2ff4e23e4621dcd0769dd7078b254dec8315 100644 (file)
--- a/print.h
+++ b/print.h
@@ -33,12 +33,12 @@ struct print_info {
        if_printer printer;
 };
 
-void   init_print(u_int32_t localnet, u_int32_t mask,
+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(int type);
+struct print_info      get_print_info(netdissect_options *ndo, int type);
 
 void   pretty_print_packet(struct print_info *print_info,
            const struct pcap_pkthdr *h, const u_char *sp,
index c9f62a5160815399657b3ce59e7a84602e6e670c..0d58e9d8788067b4c24e36d8fdf60261464d0be7 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -134,9 +134,6 @@ extern int SIZE_BUF;
 #define SIGNAL_REQ_INFO SIGUSR1
 #endif
 
-netdissect_options Gndo;
-netdissect_options *gndo = &Gndo;
-
 static int Cflag;                      /* rotate dump files after this many bytes */
 static int Cflag_count;                        /* Keep track of which file number we're writing */
 static int Dflag;                      /* list available devices and exit */
@@ -738,11 +735,14 @@ main(int argc, char **argv)
        int jflag=-1;                   /* packet time stamp source */
        int Oflag=1;                    /* run filter code optimizer */
        int pflag=0;                    /* don't go promiscuous */
+       netdissect_options Gndo;
+       netdissect_options *gndo = &Gndo;
 
 #ifdef WIN32
        if(wsockinit() != 0) return 1;
 #endif /* WIN32 */
 
+       memset(gndo, 0, sizeof(*gndo));
        gndo->ndo_Rflag=1;
        gndo->ndo_dlt=-1;
        ndo_set_function_pointers(gndo);
@@ -1487,7 +1487,7 @@ main(int argc, char **argv)
                free(cmdbuf);
                exit(0);
        }
-       init_print(localnet, netmask, timezone_offset);
+       init_print(gndo, localnet, netmask, timezone_offset);
 
 #ifndef WIN32
        (void)setsignal(SIGPIPE, cleanup);
@@ -1636,7 +1636,7 @@ main(int argc, char **argv)
 #endif
        } else {
                type = pcap_datalink(pd);
-               printinfo = get_print_info(type);
+               printinfo = get_print_info(gndo, type);
                callback = print_packet;
                pcap_userdata = (u_char *)&printinfo;
        }
@@ -1758,7 +1758,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(new_dlt);
+                               printinfo = get_print_info(gndo, 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",