Subject: bin/2269: tcpdump displays timestamps in gmt, not local time
To: None <gnats-bugs@NetBSD.ORG>
From: None <kenh@cmf.nrl.navy.mil>
List: netbsd-bugs
Date: 03/27/1996 23:12:02
>Number:         2269
>Category:       bin
>Synopsis:       tcpdump displays packet timestamps in GMT instead of local time
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Mar 27 23:35:01 1996
>Last-Modified:
>Originator:     Ken Hornstein
>Organization:
None
	
>Release:        960325 sources <NetBSD-current source date>
>Environment:
	
System: NetBSD excalibur 1.1B NetBSD 1.1B (EXCALIBUR) #14: Wed Mar 27 00:15:10 EST 1996 kenh@excalibur:/usr/src/sys/arch/i386/compile/EXCALIBUR i386


>Description:
	
Tcpdump has code in it to display the packet timestamps in local time.
However, it uses gettimeofday() to get the current timezone.  Since NetBSD
no longer keeps the timezone in the kernel, the timezone it gets is bogus,
and as a result the packet timestamps are displayed in GMT.
>How-To-Repeat:
	
Run tcpdump.  Look at the packet timestamps.  Compare their time to the
time returned by date, and notice they are different (unless you happen
to live in England :-) ).
>Fix:
	
This patch seems to do the job.

--- util.c.old	Wed Mar 27 22:51:32 1996
+++ util.c	Wed Mar 27 22:56:50 1996
@@ -321,15 +321,13 @@
 {
 #ifndef SOLARIS
 	struct timeval now;
-	struct timezone tz;
-	long t;
+	struct tm *tm;
 
-	if (gettimeofday(&now, &tz) < 0)
+	if (gettimeofday(&now, (struct timezone *) NULL) < 0)
 		error("gettimeofday");
-	t = tz.tz_minuteswest * -60;
-	if (localtime((time_t *)&now.tv_sec)->tm_isdst)
-		t += 3600;
-	return (t);
+	tm = localtime((time_t *)&now.tv_sec);
+
+	return (tm->tm_gmtoff);
 #else
 	tzset();
 	return (-altzone);
>Audit-Trail:
>Unformatted: