Fix our ancient tcpslice for >2GB limits.

PR:		bin/13691
MFC after:	1 week
Submitted by:	Bruce A. Mah
This commit is contained in:
Bruce M Simpson 2006-09-23 21:12:23 +00:00
parent b611c801f0
commit 2c2da9973b
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=162589
3 changed files with 23 additions and 16 deletions

View File

@ -52,6 +52,13 @@ time_t gwtm2secs( struct tm *tm )
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 )
{

View File

@ -281,7 +281,7 @@ sf_find_end( pcap_t *p, struct timeval *first_timestamp,
* end of the file.
*/
num_bytes = MAX_BYTES_FOR_DEFINITE_HEADER;
if ( fseek( pcap_file( p ), (long) -num_bytes, 2 ) < 0 )
if ( fseeko( pcap_file( p ), (off_t)-num_bytes, 2 ) < 0 )
return 0;
buf = (u_char *)malloc((u_int) num_bytes);
@ -346,8 +346,8 @@ sf_find_end( pcap_t *p, struct timeval *first_timestamp,
status = 1;
/* Seek so that the next read will start at last valid packet. */
if ( fseek( pcap_file( p ), (long) -(bufend - hdrpos), 2 ) < 0 )
error( "final fseek() failed in sf_find_end()" );
if ( fseeko( pcap_file( p ), (off_t) -(bufend - hdrpos), 2 ) < 0 )
error( "final fseeko() failed in sf_find_end()" );
done:
free( (char *) buf );
@ -412,14 +412,14 @@ read_up_to( pcap_t *p, struct timeval *desired_time )
{
struct pcap_pkthdr hdr;
const u_char *buf;
long pos;
fpos_t pos;
int status;
for ( ; ; )
{
struct timeval *timestamp;
pos = ftell( pcap_file( p ) );
fgetpos( pcap_file( p ), &pos );
buf = pcap_next( p, &hdr );
if ( buf == 0 )
@ -443,8 +443,8 @@ read_up_to( pcap_t *p, struct timeval *desired_time )
}
}
if ( fseek( pcap_file( p ), pos, 0 ) < 0 )
error( "fseek() failed in read_up_to()" );
if ( fsetpos( pcap_file( p ), &pos ) < 0 )
error( "fsetpos() failed in read_up_to()" );
return (status);
}
@ -474,7 +474,7 @@ sf_find_packet( pcap_t *p,
struct timeval min_time_copy, max_time_copy;
u_int num_bytes = MAX_BYTES_FOR_DEFINITE_HEADER;
int num_bytes_read;
long desired_pos, present_pos;
fpos_t desired_pos, present_pos;
u_char *buf, *hdrpos;
struct pcap_pkthdr hdr;
@ -501,7 +501,7 @@ sf_find_packet( pcap_t *p,
break;
}
present_pos = ftell( pcap_file( p ) );
fgetpos( pcap_file( p ), &present_pos );
if ( present_pos <= desired_pos &&
desired_pos - present_pos < STRAIGHT_SCAN_THRESHOLD )
@ -517,8 +517,8 @@ sf_find_packet( pcap_t *p,
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()" );
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 ) );
@ -540,8 +540,8 @@ sf_find_packet( pcap_t *p,
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 ( 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 */

View File

@ -453,7 +453,7 @@ void
extract_slice(char filename[], char write_file_name[],
struct timeval *start_time, struct timeval *stop_time)
{
long start_pos, stop_pos;
off_t start_pos, stop_pos;
struct timeval file_start_time, file_stop_time;
struct pcap_pkthdr hdr;
pcap_t *p;
@ -464,7 +464,7 @@ extract_slice(char filename[], char write_file_name[],
error( "bad tcpdump file %s: %s", filename, errbuf );
snaplen = pcap_snapshot( p );
start_pos = ftell( pcap_file( p ) );
fgetpos( pcap_file( p ), &start_pos );
if ( ! dumper )
{
@ -485,7 +485,7 @@ extract_slice(char filename[], char write_file_name[],
error( "problems finding end packet of file %s",
filename );
stop_pos = ftell( pcap_file( p ) );
fgetpos( pcap_file( p ), &stop_pos );
/* sf_find_packet() requires that the time it's passed as its last