Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 11 Feb 2000 09:00:04 -0800 (PST)
From:      bmah@CA.Sandia.GOV (Bruce A. Mah)
To:        freebsd-bugs@FreeBSD.org
Subject:   bin/13691: tcpslice problems
Message-ID:  <200002111700.JAA07442@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/13691; it has been noted by GNATS.

From: bmah@CA.Sandia.GOV (Bruce A. Mah)
To: sheldonh@uunet.co.za, tate@spa.is.uec.ac.jp,
	freebsd-gnats-submit@freebsd.org
Cc: bmah@CA.Sandia.GOV, vern@ee.lbl.gov, obrien@freebsd.org
Subject: bin/13691: tcpslice problems
Date: Fri, 11 Feb 2000 08:50:46 -0800

 Hi all--
 
 Came across PR bin/13691 while I was researching a Y2K bug in
 tcpslice.  Right now I see three problems with the version of tcpslice
 in the FreeBSD base distribution:
 
 1.  tcpslice doesn't work correctly on >2GB files.
 
 2.  Timezone conversions aren't right.  (See PR bin/10633, filed by
 me.)
 
 3.  Y2K bug (tcpslice doesn't handle dates correctly on traces that
 start in year 2000 or later).
 
 To fix all three of these, I propose the following:
 
 A.  Contribify tcpslice-1.1a3, as I described in bin/10633.  This
 fixes #2 and, according to Tateoka-san's follow-up to bin/13691, will
 fix part of #1 by giving us a tcpslice that uses off_t instead of long
 for file offsets.
 
 B.  Apply the patch attached here, to replace all of the fseek/ftell
 calls with fsetpos/fgetpos calls.  Another way to do this is to
 replace fseek/ftell with fseeko/ftello.  The patch from Vern (cited by
 Sheldon) replaces two of the ftell calls with ftello, but doesn't
 touch any of the fseek calls.
 
 (My patch uses fsetpos/fgetpos because that's what I was familiar with
 at the time.  Using fseeko/ftello may in fact be better because it
 involves fewer code changes.)
 
 The attached patch also has a diff for gwtm2secs.c to fix the Y2K
 problem in #3.
 
 I realize this doesn't stand much of a chance of happening in the
 middle of the 4.0 code freeze, but I wanted to write this up while
 it's still fresh in my mind.
 
 (Vern: I sent you a CC on this in case you're still doing work on
 tcpslice.  You can get some of the background info leading up to this
 discussion at:
 	   http://www.freebsd.org/cgi/query-pr-summary.cgi
 )
 
 (David: I don't mean to hassle you over bin/10633, but I thought you'd
 probably be interested.)
 
 Thanks all!
 
 Bruce.
 
 diff -c -r tcpslice-1.1a3-dist/gwtm2secs.c tcpslice-1.1a3/gwtm2secs.c
 *** tcpslice-1.1a3-dist/gwtm2secs.c	Sat Dec 21 19:56:52 1996
 --- tcpslice-1.1a3/gwtm2secs.c	Fri Feb 11 08:17:02 2000
 ***************
 *** 62,67 ****
 --- 62,74 ----
   		else
   			year += 2000;
   
 + 	/* Make sure our year is still >= 1970.  We fix 3-digit years
 + 	 * this way, because localtime(3) can return tm_year >= 100,
 + 	 * starting in year 2000.
 + 	 */
 + 	if ( year < 1970 )
 + 		year += 1900;
 + 
   	days = 0;
   	for ( i = 1970; i < year; ++i )
   		{
 diff -c -r tcpslice-1.1a3-dist/search.c tcpslice-1.1a3/search.c
 *** tcpslice-1.1a3-dist/search.c	Sat Dec 21 19:56:37 1996
 --- tcpslice-1.1a3/search.c	Wed Apr 21 08:00:42 1999
 ***************
 *** 295,301 ****
   	 * end of the file.
   	 */
   	num_bytes = MAX_BYTES_FOR_DEFINITE_HEADER;
 ! 	if ( fseek( pcap_file( p ), (off_t) -num_bytes, 2 ) < 0 )
   		return 0;
   
   	buf = (u_char *)malloc((u_int) num_bytes);
 --- 295,301 ----
   	 * end of the file.
   	 */
   	num_bytes = MAX_BYTES_FOR_DEFINITE_HEADER;
 ! 	if ( fseek( pcap_file( p ), (off_t) -num_bytes, SEEK_END ) < 0 )
   		return 0;
   
   	buf = (u_char *)malloc((u_int) num_bytes);
 ***************
 *** 360,366 ****
   	status = 1;
   
   	/* Seek so that the next read will start at last valid packet. */
 ! 	if ( fseek( pcap_file( p ), (off_t) -(bufend - hdrpos), 2 ) < 0 )
   		error( "final fseek() failed in sf_find_end()" );
   
       done:
 --- 360,366 ----
   	status = 1;
   
   	/* Seek so that the next read will start at last valid packet. */
 ! 	if ( fseek( pcap_file( p ), (off_t) -(bufend - hdrpos), SEEK_END ) < 0 )
   		error( "final fseek() failed in sf_find_end()" );
   
       done:
 ***************
 *** 433,439 ****
   		{
   		struct timeval *timestamp;
   
 ! 		pos = ftell( pcap_file( p ) );
   		buf = pcap_next( p, &hdr );
   
   		if ( buf == 0 )
 --- 433,439 ----
   		{
   		struct timeval *timestamp;
   
 ! 		fgetpos( pcap_file( p ), &pos );
   		buf = pcap_next( p, &hdr );
   
   		if ( buf == 0 )
 ***************
 *** 457,464 ****
   			}
   		}
   
 ! 	if ( fseek( pcap_file( p ), pos, 0 ) < 0 )
 ! 		error( "fseek() failed in read_up_to()" );
   
   	return (status);
   	}
 --- 457,464 ----
   			}
   		}
   
 ! 	if ( fsetpos( pcap_file( p ), &pos ) < 0 )
 ! 		error( "fsetpos() failed in read_up_to()" );
   
   	return (status);
   	}
 ***************
 *** 515,521 ****
   			break;
   			}
   
 ! 		present_pos = ftell( pcap_file( p ) );
   
   		if ( present_pos <= desired_pos &&
   		     desired_pos - present_pos < STRAIGHT_SCAN_THRESHOLD )
 --- 515,521 ----
   			break;
   			}
   
 ! 		fgetpos( pcap_file( p ), &present_pos );
   
   		if ( present_pos <= desired_pos &&
   		     desired_pos - present_pos < STRAIGHT_SCAN_THRESHOLD )
 ***************
 *** 531,538 ****
   		if ( desired_pos < min_pos )
   			desired_pos = min_pos;
   
 ! 		if ( fseek( pcap_file( p ), desired_pos, 0 ) < 0 )
 ! 			error( "fseek() failed in sf_find_packet()" );
   
   		num_bytes_read =
   			fread( (char *) buf, 1, num_bytes, pcap_file( p ) );
 --- 531,538 ----
   		if ( desired_pos < min_pos )
   			desired_pos = min_pos;
   
 ! 		if ( fsetpos( pcap_file( p ), &desired_pos ) < 0 )
 ! 			error( "fsetpos() failed in sf_find_packet()" );
   
   		num_bytes_read =
   			fread( (char *) buf, 1, num_bytes, pcap_file( p ) );
 ***************
 *** 554,561 ****
   		desired_pos += (hdrpos - buf);
   
   		/* Seek to the beginning of the header. */
 ! 		if ( fseek( pcap_file( p ), desired_pos, 0 ) < 0 )
 ! 			error( "fseek() failed in sf_find_packet()" );
   
   		if ( sf_timestamp_less_than( &hdr.ts, desired_time ) )
   			{ /* too early in the file */
 --- 554,561 ----
   		desired_pos += (hdrpos - buf);
   
   		/* Seek to the beginning of the header. */
 ! 		if ( fsetpos( pcap_file( p ), &desired_pos ) < 0 )
 ! 			error( "fsetpos() failed in sf_find_packet()" );
   
   		if ( sf_timestamp_less_than( &hdr.ts, desired_time ) )
   			{ /* too early in the file */
 diff -c -r tcpslice-1.1a3-dist/tcpslice.c tcpslice-1.1a3/tcpslice.c
 *** tcpslice-1.1a3-dist/tcpslice.c	Fri Jan 24 13:36:09 1997
 --- tcpslice-1.1a3/tcpslice.c	Wed Apr 21 08:01:01 1999
 ***************
 *** 470,476 ****
   		error( "bad tcpdump file %s: %s", filename, errbuf );
   
   	snaplen = pcap_snapshot( p );
 ! 	start_pos = ftell( pcap_file( p ) );
   
   	if ( ! dumper )
   		{
 --- 470,476 ----
   		error( "bad tcpdump file %s: %s", filename, errbuf );
   
   	snaplen = pcap_snapshot( p );
 ! 	fgetpos( pcap_file( p ), &start_pos );
   
   	if ( ! dumper )
   		{
 ***************
 *** 491,497 ****
   		error( "problems finding end packet of file %s",
   			filename );
   
 ! 	stop_pos = ftell( pcap_file( p ) );
   
   
   	/* sf_find_packet() requires that the time it's passed as its last
 --- 491,497 ----
   		error( "problems finding end packet of file %s",
   			filename );
   
 ! 	fgetpos( pcap_file( p ), &stop_pos );
   
   
   	/* sf_find_packet() requires that the time it's passed as its last
 


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200002111700.JAA07442>