]> The Tcpdump Group git mirrors - tcpdump/blobdiff - tcpdump.c
Add missing bounds checking to the DVMRP and PIM print routines.
[tcpdump] / tcpdump.c
index e99334ac8b81060c1dac895bf7446d183e9e791d..0969b7b938678654194225beeca956558fdc46af 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
  *     Seth Webster <[email protected]>
  */
 
+#ifndef lint
+static const char copyright[] _U_ =
+    "@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000\n\
+The Regents of the University of California.  All rights reserved.\n";
+static const char rcsid[] _U_ =
+    "@(#) $Header: /tcpdump/master/tcpdump/tcpdump.c,v 1.216.2.4 2003-11-18 23:12:11 guy Exp $ (LBL)";
+#endif
 
 /*
  * tcpdump - monitor tcp/ip traffic on an ethernet.
@@ -62,13 +69,6 @@ extern int SIZE_BUF;
 #include "gmt2local.h"
 #include "pcap-missing.h"
 
-#ifndef lint
-static const char copyright[] _U_ =
-    "@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000\n\
-The Regents of the University of California.  All rights reserved.\n";
-static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/tcpdump.c,v 1.216.2.1 2003-11-15 22:29:19 guy Exp $ (LBL)";
-#endif
 int dflag;                     /* print filter code */
 int eflag;                     /* print ethernet header */
 int fflag;                     /* don't translate "foreign" IP address */
@@ -256,7 +256,8 @@ show_dlts_and_exit(pcap_t *pd)
        while (--n_dlts >= 0) {
                dlt_name = pcap_datalink_val_to_name(dlts[n_dlts]);
                if (dlt_name != NULL) {
-                       (void) fprintf(stderr, "  %s", dlt_name);
+                       (void) fprintf(stderr, "  %s (%s)", dlt_name,
+                           pcap_datalink_val_to_description(dlts[n_dlts]));
 
                        /*
                         * OK, does tcpdump handle that type?
@@ -454,11 +455,24 @@ main(int argc, char **argv)
                        break;
 
                case 'l':
+#ifdef WIN32
+                       /*
+                        * _IOLBF is the same as _IOFBF in Microsoft's C
+                        * libraries; the only alternative they offer
+                        * is _IONBF.
+                        *
+                        * XXX - this should really be checking for MSVC++,
+                        * not WIN32, if, for example, MinGW has its own
+                        * C library that is more UNIX-compatible.
+                        */
+                       setvbuf(stdout, NULL, _IONBF, 0);
+#else /* WIN32 */
 #ifdef HAVE_SETLINEBUF
                        setlinebuf(stdout);
 #else
                        setvbuf(stdout, NULL, _IOLBF, 0);
 #endif
+#endif /* WIN32 */
                        break;
 
                case 'n':
@@ -621,10 +635,14 @@ main(int argc, char **argv)
                        error("%s", ebuf);
                dlt = pcap_datalink(pd);
                dlt_name = pcap_datalink_val_to_name(dlt);
-               if (dlt_name == NULL)
-                       dlt_name = "???";
-                printf("reading from file %s, link-type %u (%s)\n",
-                      RFileName, dlt, dlt_name);
+               if (dlt_name == NULL) {
+                       printf("reading from file %s, link-type %u\n",
+                           RFileName, dlt);
+               } else {
+                       printf("reading from file %s, link-type %s (%s)\n",
+                           RFileName, dlt_name,
+                           pcap_datalink_val_to_description(dlt));
+               }
                localnet = 0;
                netmask = 0;
                if (fflag != 0)
@@ -651,7 +669,7 @@ main(int argc, char **argv)
                fflush(stderr); 
 #endif /* WIN32 */
                *ebuf = '\0';
-               pd = pcap_open_live(device, snaplen, !pflag, 10000, ebuf);
+               pd = pcap_open_live(device, snaplen, !pflag, 1000, ebuf);
                if (pd == NULL)
                        error("%s", ebuf);
                else if (*ebuf)
@@ -770,10 +788,14 @@ main(int argc, char **argv)
                        (void)fprintf(stderr, "%s: ", program_name);
                dlt = pcap_datalink(pd);
                dlt_name = pcap_datalink_val_to_name(dlt);
-               if (dlt_name == NULL)
-                       dlt_name = "???";
-               (void)fprintf(stderr, "listening on %s, link-type %u (%s), capture size %u bytes\n",
-                   device, dlt, dlt_name, snaplen);
+               if (dlt_name == NULL) {
+                       (void)fprintf(stderr, "listening on %s, link-type %u, capture size %u bytes\n",
+                           device, dlt, snaplen);
+               } else {
+                       (void)fprintf(stderr, "listening on %s, link-type %s (%s), capture size %u bytes\n",
+                           device, dlt_name,
+                           pcap_datalink_val_to_description(dlt), snaplen);
+               }
                (void)fflush(stderr);
        }
 #endif /* WIN32 */