From a9b9c86c8a0ccde5c1480bf5a0ba250d949a6d65 Mon Sep 17 00:00:00 2001 From: fenner Date: Tue, 27 May 1997 02:11:31 +0000 Subject: Virgin import of LBL tcpdump v3.3 --- contrib/tcpdump/util.c | 68 ++++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 38 deletions(-) (limited to 'contrib/tcpdump/util.c') diff --git a/contrib/tcpdump/util.c b/contrib/tcpdump/util.c index 9c74a3a..254a64e 100644 --- a/contrib/tcpdump/util.c +++ b/contrib/tcpdump/util.c @@ -20,8 +20,8 @@ */ #ifndef lint -static char rcsid[] = - "@(#) $Header: util.c,v 1.52 96/07/15 18:22:54 leres Exp $ (LBL)"; +static const char rcsid[] = + "@(#) $Header: util.c,v 1.55 96/09/26 23:36:51 leres Exp $ (LBL)"; #endif #include @@ -296,42 +296,34 @@ read_infile(char *fname) return (cp); } +/* + * Returns the difference between gmt and local time in seconds. + * Use gmtime() and localtime() to keep things simple. + */ int32_t -gmt2local() +gmt2local(void) { - register int t; -#if !defined(HAVE_ALTZONE) && !defined(HAVE_TIMEZONE) - struct timeval tv; - struct timezone tz; - register struct tm *tm; -#endif - - t = 0; -#if !defined(HAVE_ALTZONE) && !defined(HAVE_TIMEZONE) - if (gettimeofday(&tv, &tz) < 0) - error("gettimeofday"); - tm = localtime((time_t *)&tv.tv_sec); -#ifdef HAVE_TM_GMTOFF - t = tm->tm_gmtoff; -#else - t = tz.tz_minuteswest * -60; - /* XXX Some systems need this, some auto offset tz_minuteswest... */ - if (tm->tm_isdst) - t += 60 * 60; -#endif -#endif - -#ifdef HAVE_TIMEZONE - tzset(); - t = -timezone; - if (daylight) - t += 60 * 60; -#endif - -#ifdef HAVE_ALTZONE - tzset(); - t = -altzone; -#endif - - return (t); + register int dt, dir; + register struct tm *gmt, *loc; + time_t t; + struct tm sgmt; + + t = time(NULL); + gmt = &sgmt; + *gmt = *gmtime(&t); + loc = localtime(&t); + dt = (loc->tm_hour - gmt->tm_hour) * 60 * 60 + + (loc->tm_min - gmt->tm_min) * 60; + + /* + * If the year or julian day is different, we span 00:00 GMT + * and must add or subtract a day. Check the year first to + * avoid problems when the julian day wraps. + */ + dir = loc->tm_year - gmt->tm_year; + if (dir == 0) + dir = loc->tm_yday - gmt->tm_yday; + dt += dir * 24 * 60 * 60; + + return (dt); } -- cgit v1.1