From 4e3f76bebdc8b839f4930e8d1addeaf8653b98c2 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Wed, 5 Dec 2012 08:29:22 +0000 Subject: Add a bunch of #defines for converting between tm_year/tm_mon/tm_mday to a DOS date. Use them - which fixes a bug, bug 7998, wherein we were doing the wrong check to see whether tm_year would fit in a DOS date or not. svn path=/trunk/; revision=46387 --- wiretap/ngsniffer.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'wiretap') diff --git a/wiretap/ngsniffer.c b/wiretap/ngsniffer.c index ac8b9de065..cf92b54dff 100644 --- a/wiretap/ngsniffer.c +++ b/wiretap/ngsniffer.c @@ -490,6 +490,21 @@ typedef struct { GList *current_blob; /* list element for current blob */ } ngsniffer_t; +/* + * DOS date to "struct tm" conversion values. + */ +/* DOS year = upper 7 bits */ +#define DOS_YEAR_OFFSET (1980-1900) /* tm_year = year+1900, DOS date year year+1980 */ +#define DOS_YEAR_SHIFT 9 +#define DOS_YEAR_MASK (0x7F<>9) + 1980 - 1900; - tm.tm_mon = ((start_date&0x1e0)>>5) - 1; - tm.tm_mday = (start_date&0x1f); + tm.tm_year = ((start_date&DOS_YEAR_MASK)>>DOS_YEAR_SHIFT) + DOS_YEAR_OFFSET; + tm.tm_mon = ((start_date&DOS_MONTH_MASK)>>DOS_MONTH_SHIFT) + DOS_MONTH_OFFSET; + tm.tm_mday = ((start_date&DOS_DAY_MASK)>>DOS_DAY_SHIFT); #if 0 /* The time does not appear to act as an offset; only the date */ start_time = pletohs(&version.time); @@ -2122,10 +2137,10 @@ ngsniffer_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, else #endif tm = localtime(&phdr->ts.secs); - if (tm != NULL && tm->tm_year >= 1980) { - start_date = (tm->tm_year - (1980 - 1900)) << 9; - start_date |= (tm->tm_mon + 1) << 5; - start_date |= tm->tm_mday; + if (tm != NULL && tm->tm_year >= DOS_YEAR_OFFSET) { + start_date = (tm->tm_year - DOS_YEAR_OFFSET) << DOS_YEAR_SHIFT; + start_date |= (tm->tm_mon - DOS_MONTH_OFFSET) << DOS_MONTH_SHIFT; + start_date |= tm->tm_mday << DOS_DAY_SHIFT; /* record the start date, not the start time */ ngsniffer->start = phdr->ts.secs - (3600*tm->tm_hour + 60*tm->tm_min + tm->tm_sec); } else { -- cgit v1.2.1