Skip to content

Commit

Permalink
Make "tflag" count the number of "-t"s, to make it more obvious what
Browse files Browse the repository at this point in the history
tflag values correspond to what output formats (e.g., 4 means "-tttt").

Switch on the tflag value to determine whether to call "gmt2local()" to
set "thiszone", just as we switch on it to determine the format for time
stamps, to make it more obvious in what cases we call it.
  • Loading branch information
yuguy committed Jun 15, 2004
1 parent 9974f43 commit 791d0e8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
12 changes: 8 additions & 4 deletions tcpdump.c
Expand Up @@ -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.243 2004-06-15 00:00:04 guy Exp $ (LBL)";
"@(#) $Header: /tcpdump/master/tcpdump/tcpdump.c,v 1.244 2004-06-15 23:05:05 guy Exp $ (LBL)";
#endif

/*
Expand Down Expand Up @@ -420,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;
Expand Down Expand Up @@ -644,7 +643,7 @@ main(int argc, char **argv)
break;

case 't':
--tflag;
++tflag;
break;

case 'T':
Expand Down Expand Up @@ -741,8 +740,13 @@ main(int argc, char **argv)
/* NOTREACHED */
}

if (tflag > 0 || tflag == -3)
switch (tflag) {

case 0: /* Default */
case 4: /* Default + Date*/
thiszone = gmt2local(0);
break;
}

#ifdef WITH_CHROOT
/* if run as root, prepare for chrooting */
Expand Down
19 changes: 13 additions & 6 deletions util.c
Expand Up @@ -21,7 +21,7 @@

#ifndef lint
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.93 2004-04-29 02:15:16 mcr Exp $ (LBL)";
"@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.94 2004-06-15 23:05:06 guy Exp $ (LBL)";
#endif

#ifdef HAVE_CONFIG_H
Expand Down Expand Up @@ -116,19 +116,25 @@ ts_print(register const struct timeval *tvp)
static unsigned b_sec;
static unsigned b_usec;

switch(tflag) {
case 1: /* Default */
switch (tflag) {

case 0: /* Default */
s = (tvp->tv_sec + thiszone) % 86400;
(void)printf("%02d:%02d:%02d.%06u ",
s / 3600, (s % 3600) / 60, s % 60,
(unsigned)tvp->tv_usec);
break;
case -1: /* Unix timeval style */

case 1: /* No time stamp */
break;

case 2: /* Unix timeval style */
(void)printf("%u.%06u ",
(unsigned)tvp->tv_sec,
(unsigned)tvp->tv_usec);
break;
case -2:

case 3: /* Microseconds since previous packet */
if (b_sec == 0) {
printf("000000 ");
} else {
Expand All @@ -146,7 +152,8 @@ ts_print(register const struct timeval *tvp)
b_sec = tvp->tv_sec;
b_usec = tvp->tv_usec;
break;
case -3: /* Default + Date*/

case 4: /* Default + Date*/
s = (tvp->tv_sec + thiszone) % 86400;
Time = (tvp->tv_sec + thiszone) - s;
tm = gmtime (&Time);
Expand Down

0 comments on commit 791d0e8

Please sign in to comment.