]> The Tcpdump Group git mirrors - tcpdump/blobdiff - tcpdump.c
Check for a TCP header length that's too short, report more information
[tcpdump] / tcpdump.c
index 2ea43168e76ce061ba5357cd5be54a9b272edea3..1889ce30c7ba9127503cef5c15deccf7439f6d27 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -30,7 +30,7 @@ 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.241 2004-04-06 13:04:17 risso Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/tcpdump.c,v 1.245 2004-06-15 23:09:46 guy Exp $ (LBL)";
 #endif
 
 /*
@@ -68,6 +68,7 @@ extern int SIZE_BUF;
 #ifndef WIN32
 #include <pwd.h>
 #include <grp.h>
+#include <errno.h>
 #endif /* WIN32 */
 
 #include "netdissect.h"
@@ -320,7 +321,7 @@ droproot(const char *username, const char *chroot_dir)
        struct passwd *pw = NULL;
 
        if (chroot_dir && !username) {
-               fprintf(stderr, "Chroot without dropping root is insecure\n");
+               fprintf(stderr, "tcpdump: Chroot without dropping root is insecure\n");
                exit(1);
        }
        
@@ -328,19 +329,24 @@ droproot(const char *username, const char *chroot_dir)
        if (pw) {
                if (chroot_dir) {
                        if (chroot(chroot_dir) != 0 || chdir ("/") != 0) {
-                               fprintf(stderr, "Couldn't chroot/chdir to '%.64s'\n", chroot_dir);
+                               fprintf(stderr, "tcpdump: Couldn't chroot/chdir to '%.64s': %s\n",
+                                   chroot_dir, pcap_strerror(errno));
                                exit(1);
                        }
                }
-               if (initgroups(pw->pw_name, pw->pw_gid) != 0 || setgid(pw->pw_gid) != 0 ||
-                                setuid(pw->pw_uid) != 0) {
-                       fprintf(stderr, "Couldn't change to '%.32s' uid=%d gid=%d\n", username, 
-                                                       pw->pw_uid, pw->pw_gid);
+               if (initgroups(pw->pw_name, pw->pw_gid) != 0 ||
+                   setgid(pw->pw_gid) != 0 || setuid(pw->pw_uid) != 0) {
+                       fprintf(stderr, "tcpdump: Couldn't change to '%.32s' uid=%lu gid=%lu: %s\n",
+                           username, 
+                           (unsigned long)pw->pw_uid,
+                           (unsigned long)pw->pw_gid,
+                           pcap_strerror(errno));
                        exit(1);
                }
        }
        else {
-               fprintf(stderr, "Couldn't find user '%.32s'\n", username);
+               fprintf(stderr, "tcpdump: Couldn't find user '%.32s'\n",
+                   username);
                exit(1);
        }
 }
@@ -414,7 +420,6 @@ main(int argc, char **argv)
 
         gndo->ndo_Oflag=1;
        gndo->ndo_Rflag=1;
-       gndo->ndo_tflag=1;
        gndo->ndo_dlt=-1;
        gndo->ndo_printf=tcpdump_printf;
        gndo->ndo_error=ndo_error;
@@ -638,7 +643,7 @@ main(int argc, char **argv)
                        break;
 
                case 't':
-                       --tflag;
+                       ++tflag;
                        break;
 
                case 'T':
@@ -735,8 +740,22 @@ main(int argc, char **argv)
                        /* NOTREACHED */
                }
 
-       if (tflag > 0)
+       switch (tflag) {
+
+       case 0: /* Default */
+       case 4: /* Default + Date*/
                thiszone = gmt2local(0);
+               break;
+
+       case 1: /* No time stamp */
+       case 2: /* Unix timeval style */
+       case 3: /* Microseconds since previous packet */
+               break;
+
+       default: /* Not supported */
+               error("only -t, -tt, -ttt, and -tttt are supported");
+               break;
+       }
 
 #ifdef WITH_CHROOT
        /* if run as root, prepare for chrooting */
@@ -1297,9 +1316,9 @@ usage(void)
        (void)fprintf(stderr,
 "\t\t[ -E algo:secret ] [ -F file ] [ -i interface ] [ -M secret ]\n");
        (void)fprintf(stderr,
-"\t\t[ -r file ] [ -s snaplen ] [ -T type ] [ -w file ] [ -W filecount ]\n");
+"\t\t[ -r file ] [ -s snaplen ] [ -T type ] [ -w file ]\n");
        (void)fprintf(stderr,
-"\t\t[ -y datalinktype ] [ -Z user ]\n");
+"\t\t[ -W filecount ] [ -y datalinktype ] [ -Z user ]\n");
        (void)fprintf(stderr,
 "\t\t[ expression ]\n");
        exit(1);