View | Details | Raw Unified | Return to bug 22730
Collapse All | Expand All

(-)gwtm2secs.c (+2 lines)
Lines 47-56 Link Here
47
	 * distinguishes them, since we can't represent any time < 1970.
47
	 * distinguishes them, since we can't represent any time < 1970.
48
	 */
48
	 */
49
	if ( year < 100 )
49
	if ( year < 100 )
50
		{
50
		if ( year >= 70 )
51
		if ( year >= 70 )
51
			year += 1900;
52
			year += 1900;
52
		else
53
		else
53
			year += 2000;
54
			year += 2000;
55
		}
54
56
55
	days = 0;
57
	days = 0;
56
	for ( i = 1970; i < year; ++i )
58
	for ( i = 1970; i < year; ++i )
(-)search.c (-19 / +17 lines)
Lines 378-403 Link Here
378
	        t1->tv_usec < t2->tv_usec);
378
	        t1->tv_usec < t2->tv_usec);
379
	}
379
	}
380
380
381
382
/* Given two timestamps on either side of desired_time and their positions,
381
/* Given two timestamps on either side of desired_time and their positions,
383
 * returns the interpolated position of the desired_time packet.  Returns a
382
 * returns the interpolated position of the desired_time packet.  Returns a
384
 * negative value if the desired_time is outside the given range.
383
 * negative value if the desired_time is outside the given range.
385
 */
384
 */
386
385
387
static long
386
static off_t
388
interpolated_position( struct timeval *min_time, long min_pos,
387
interpolated_position( struct timeval *min_time, off_t min_pos,
389
			struct timeval *max_time, long max_pos,
388
			struct timeval *max_time, off_t max_pos,
390
			struct timeval *desired_time )
389
			struct timeval *desired_time )
391
	{
390
	{
392
	double full_span = timeval_diff( max_time, min_time );
391
	double full_span = timeval_diff( max_time, min_time );
393
	double desired_span = timeval_diff( desired_time, min_time );
392
	double desired_span = timeval_diff( desired_time, min_time );
394
	long full_span_pos = max_pos - min_pos;
393
	off_t full_span_pos = max_pos - min_pos;
395
	double fractional_offset = desired_span / full_span;
394
	double fractional_offset = desired_span / full_span;
396
395
397
	if ( fractional_offset < 0.0 || fractional_offset > 1.0 )
396
	if ( fractional_offset < 0.0 || fractional_offset > 1.0 )
398
		return -1;
397
		return -1;
399
398
400
	return min_pos + (long) (fractional_offset * (double) full_span_pos);
399
	return min_pos + (off_t) (fractional_offset * (double) full_span_pos);
401
	}
400
	}
402
401
403
402
Lines 412-425 Link Here
412
	{
411
	{
413
	struct pcap_pkthdr hdr;
412
	struct pcap_pkthdr hdr;
414
	const u_char *buf;
413
	const u_char *buf;
415
	long pos;
414
	off_t pos;
416
	int status;
415
	int status;
417
416
418
	for ( ; ; )
417
	for ( ; ; )
419
		{
418
		{
420
		struct timeval *timestamp;
419
		struct timeval *timestamp;
421
420
422
		pos = ftell( pcap_file( p ) );
421
		pos = ftello( pcap_file( p ) );
423
		buf = pcap_next( p, &hdr );
422
		buf = pcap_next( p, &hdr );
424
423
425
		if ( buf == 0 )
424
		if ( buf == 0 )
Lines 443-455 Link Here
443
			}
442
			}
444
		}
443
		}
445
444
446
	if ( fseek( pcap_file( p ), pos, 0 ) < 0 )
445
	if ( fseeko( pcap_file( p ), pos, 0 ) < 0 )
447
		error( "fseek() failed in read_up_to()" );
446
		error( "fseeko() failed in read_up_to()" );
448
447
449
	return (status);
448
	return (status);
450
	}
449
	}
451
450
452
453
/* Positions the sf_readfile stream so that the next sf_read() will
451
/* Positions the sf_readfile stream so that the next sf_read() will
454
 * return the first packet with a time greater than or equal to
452
 * return the first packet with a time greater than or equal to
455
 * desired_time.  desired_time must be greater than min_time and less
453
 * desired_time.  desired_time must be greater than min_time and less
Lines 466-480 Link Here
466
464
467
int
465
int
468
sf_find_packet( pcap_t *p,
466
sf_find_packet( pcap_t *p,
469
		struct timeval *min_time, long min_pos,
467
		struct timeval *min_time, off_t min_pos,
470
		struct timeval *max_time, long max_pos,
468
		struct timeval *max_time, off_t max_pos,
471
		struct timeval *desired_time )
469
		struct timeval *desired_time )
472
	{
470
	{
473
	int status = 1;
471
	int status = 1;
474
	struct timeval min_time_copy, max_time_copy;
472
	struct timeval min_time_copy, max_time_copy;
475
	u_int num_bytes = MAX_BYTES_FOR_DEFINITE_HEADER;
473
	u_int num_bytes = MAX_BYTES_FOR_DEFINITE_HEADER;
476
	int num_bytes_read;
474
	int num_bytes_read;
477
	long desired_pos, present_pos;
475
	off_t desired_pos, present_pos;
478
	u_char *buf, *hdrpos;
476
	u_char *buf, *hdrpos;
479
	struct pcap_pkthdr hdr;
477
	struct pcap_pkthdr hdr;
480
478
Lines 501-507 Link Here
501
			break;
499
			break;
502
			}
500
			}
503
501
504
		present_pos = ftell( pcap_file( p ) );
502
		present_pos = ftello( pcap_file( p ) );
505
503
506
		if ( present_pos <= desired_pos &&
504
		if ( present_pos <= desired_pos &&
507
		     desired_pos - present_pos < STRAIGHT_SCAN_THRESHOLD )
505
		     desired_pos - present_pos < STRAIGHT_SCAN_THRESHOLD )
Lines 517-524 Link Here
517
		if ( desired_pos < min_pos )
515
		if ( desired_pos < min_pos )
518
			desired_pos = min_pos;
516
			desired_pos = min_pos;
519
517
520
		if ( fseek( pcap_file( p ), desired_pos, 0 ) < 0 )
518
		if ( fseeko( pcap_file( p ), desired_pos, 0 ) < 0 )
521
			error( "fseek() failed in sf_find_packet()" );
519
			error( "fseeko() failed in sf_find_packet()" );
522
520
523
		num_bytes_read =
521
		num_bytes_read =
524
			fread( (char *) buf, 1, num_bytes, pcap_file( p ) );
522
			fread( (char *) buf, 1, num_bytes, pcap_file( p ) );
Lines 540-547 Link Here
540
		desired_pos += (hdrpos - buf);
538
		desired_pos += (hdrpos - buf);
541
539
542
		/* Seek to the beginning of the header. */
540
		/* Seek to the beginning of the header. */
543
		if ( fseek( pcap_file( p ), desired_pos, 0 ) < 0 )
541
		if ( fseeko( pcap_file( p ), desired_pos, 0 ) < 0 )
544
			error( "fseek() failed in sf_find_packet()" );
542
			error( "fseeko() failed in sf_find_packet()" );
545
543
546
		if ( sf_timestamp_less_than( &hdr.ts, desired_time ) )
544
		if ( sf_timestamp_less_than( &hdr.ts, desired_time ) )
547
			{ /* too early in the file */
545
			{ /* too early in the file */
(-)tcpslice.c (-3 / +3 lines)
Lines 451-457 Link Here
451
extract_slice(char filename[], char write_file_name[],
451
extract_slice(char filename[], char write_file_name[],
452
		struct timeval *start_time, struct timeval *stop_time)
452
		struct timeval *start_time, struct timeval *stop_time)
453
{
453
{
454
	long start_pos, stop_pos;
454
	off_t start_pos, stop_pos;
455
	struct timeval file_start_time, file_stop_time;
455
	struct timeval file_start_time, file_stop_time;
456
	struct pcap_pkthdr hdr;
456
	struct pcap_pkthdr hdr;
457
	pcap_t *p;
457
	pcap_t *p;
Lines 462-468 Link Here
462
		error( "bad tcpdump file %s: %s", filename, errbuf );
462
		error( "bad tcpdump file %s: %s", filename, errbuf );
463
463
464
	snaplen = pcap_snapshot( p );
464
	snaplen = pcap_snapshot( p );
465
	start_pos = ftell( pcap_file( p ) );
465
	start_pos = ftello( pcap_file( p ) );
466
466
467
	if ( ! dumper )
467
	if ( ! dumper )
468
		{
468
		{
Lines 483-489 Link Here
483
		error( "problems finding end packet of file %s",
483
		error( "problems finding end packet of file %s",
484
			filename );
484
			filename );
485
485
486
	stop_pos = ftell( pcap_file( p ) );
486
	stop_pos = ftello( pcap_file( p ) );
487
487
488
488
489
	/* sf_find_packet() requires that the time it's passed as its last
489
	/* sf_find_packet() requires that the time it's passed as its last
(-)tcpslice.h (-2 / +2 lines)
Lines 52-59 Link Here
52
			struct timeval *last_timestamp );
52
			struct timeval *last_timestamp );
53
int	sf_timestamp_less_than( struct timeval *t1, struct timeval *t2 );
53
int	sf_timestamp_less_than( struct timeval *t1, struct timeval *t2 );
54
int	sf_find_packet( struct pcap *p,
54
int	sf_find_packet( struct pcap *p,
55
		struct timeval *min_time, long min_pos,
55
		struct timeval *min_time, off_t min_pos,
56
		struct timeval *max_time, long max_pos,
56
		struct timeval *max_time, off_t max_pos,
57
		struct timeval *desired_time );
57
		struct timeval *desired_time );
58
58
59
void	error(const char *fmt, ...);
59
void	error(const char *fmt, ...);

Return to bug 22730