|
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 */ |