"@(#) 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
/*
#ifndef WIN32
#include <pwd.h>
#include <grp.h>
+#include <errno.h>
#endif /* WIN32 */
#include "netdissect.h"
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);
}
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);
}
}
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;
break;
case 't':
- --tflag;
+ ++tflag;
break;
case 'T':
/* 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 */
(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);