]> The Tcpdump Group git mirrors - tcpdump/blobdiff - tcpdump.c
Use double rather than float.
[tcpdump] / tcpdump.c
index eb1241ad3859b937ef4eb3984daa5fbbadfd3490..43457eae900465b8e28339e714a6673adcae0835 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -57,12 +57,6 @@ The Regents of the University of California.  All rights reserved.\n";
 #include <netdissect-stdinc.h>
 
 #ifdef _WIN32
-#ifndef _WINSOCKAPI_
-#define _WINSOCKAPI_ /* Prevent inclusion of winsock.h in windows.h */
-#endif /* _WINSOCKAPI_ */
-#include <windows.h>
-#include <winsock2.h>
-extern int SIZE_BUF;
 #define off_t long
 #define uint UINT
 #endif /* _WIN32 */
@@ -736,18 +730,20 @@ main(int argc, char **argv)
        cap_rights_t rights;
        int cansandbox;
 #endif /* HAVE_CAPSICUM */
-       int Bflag=0;                    /* buffer size */
-       int jflag=-1;                   /* packet time stamp source */
-       int Oflag=1;                    /* run filter code optimizer */
-       int pflag=0;                    /* don't go promiscuous */
+       int Bflag = 0;                  /* buffer size */
+       int jflag = -1;                 /* packet time stamp source */
+       int Oflag = 1;                  /* run filter code optimizer */
+       int pflag = 0;                  /* don't go promiscuous */
+       int yflag_dlt = -1;
+       const char *yflag_dlt_name = NULL;
+
        netdissect_options Ndo;
        netdissect_options *ndo = &Ndo;
+       int immediate_mode = 0;
 
        memset(ndo, 0, sizeof(*ndo));
-       ndo->ndo_dlt=-1;
        ndo_set_function_pointers(ndo);
        ndo->ndo_snaplen = DEFAULT_SNAPLEN;
-       ndo->ndo_immediate = 0;
 
        cnt = -1;
        device = NULL;
@@ -1110,11 +1106,11 @@ main(int argc, char **argv)
                        break;
 
                case 'y':
-                       ndo->ndo_dltname = optarg;
-                       ndo->ndo_dlt =
-                         pcap_datalink_name_to_val(ndo->ndo_dltname);
-                       if (ndo->ndo_dlt < 0)
-                               error("invalid data link type %s", ndo->ndo_dltname);
+                       yflag_dlt_name = optarg;
+                       yflag_dlt =
+                               pcap_datalink_name_to_val(yflag_dlt_name);
+                       if (yflag_dlt < 0)
+                               error("invalid data link type %s", yflag_dlt_name);
                        break;
 
 #if defined(HAVE_PCAP_DEBUG) || defined(HAVE_YYDEBUG)
@@ -1162,7 +1158,7 @@ main(int argc, char **argv)
 
 #ifdef HAVE_PCAP_SET_IMMEDIATE_MODE
                case OPTION_IMMEDIATE_MODE:
-                       ndo->ndo_immediate = 1;
+                       immediate_mode = 1;
                        break;
 #endif
 
@@ -1209,7 +1205,7 @@ main(int argc, char **argv)
         * probably expecting to see packets pop up immediately.
         */
        if (WFileName == NULL && isatty(1))
-               ndo->ndo_immediate = 1;
+               immediate_mode = 1;
 #endif
 
 #ifdef WITH_CHROOT
@@ -1338,7 +1334,7 @@ main(int argc, char **argv)
 #endif
 
 #ifdef HAVE_PCAP_SET_IMMEDIATE_MODE
-               if (ndo->ndo_immediate) {
+               if (immediate_mode) {
                        status = pcap_set_immediate_mode(pd, 1);
                        if (status != 0)
                                error("%s: Can't set immediate mode: %s",
@@ -1427,7 +1423,8 @@ main(int argc, char **argv)
 #endif /* HAVE_PCAP_SETDIRECTION */
 #else
                *ebuf = '\0';
-               pd = pcap_open_live(device, snaplen, !pflag, 1000, ebuf);
+               pd = pcap_open_live(device, ndo->ndo_snaplen, !pflag, 1000,
+                   ebuf);
                if (pd == NULL)
                        error("%s", ebuf);
                else if (*ebuf)
@@ -1448,9 +1445,9 @@ main(int argc, char **argv)
 #endif /* !defined(HAVE_PCAP_CREATE) && defined(_WIN32) */
                if (Lflag)
                        show_dlts_and_exit(device);
-               if (ndo->ndo_dlt >= 0) {
+               if (yflag_dlt >= 0) {
 #ifdef HAVE_PCAP_SET_DATALINK
-                       if (pcap_set_datalink(pd, ndo->ndo_dlt) < 0)
+                       if (pcap_set_datalink(pd, yflag_dlt) < 0)
                                error("%s", pcap_geterr(pd));
 #else
                        /*
@@ -1458,13 +1455,13 @@ main(int argc, char **argv)
                         * data link type, so we only let them
                         * set it to what it already is.
                         */
-                       if (ndo->ndo_dlt != pcap_datalink(pd)) {
+                       if (yflag_dlt != pcap_datalink(pd)) {
                                error("%s is not one of the DLTs supported by this device\n",
-                                     ndo->ndo_dltname);
+                                     yflag_dlt_name);
                        }
 #endif
                        (void)fprintf(stderr, "%s: data link type %s\n",
-                                     program_name, ndo->ndo_dltname);
+                                     program_name, yflag_dlt_name);
                        (void)fflush(stderr);
                }
                i = pcap_snapshot(pd);