summaryrefslogtreecommitdiffstats
path: root/usr.sbin/tcpdump
diff options
context:
space:
mode:
authorbms <bms@FreeBSD.org>2006-09-23 21:12:23 +0000
committerbms <bms@FreeBSD.org>2006-09-23 21:12:23 +0000
commit34aba10f3ed2ff933f21131f8fb1038d6a1baaf4 (patch)
tree7c1313452ee8e98098970c8ddc7180a499086d48 /usr.sbin/tcpdump
parent8140b075eea72a4e4a5a6ae02d3112a605bab6e3 (diff)
downloadFreeBSD-src-34aba10f3ed2ff933f21131f8fb1038d6a1baaf4.zip
FreeBSD-src-34aba10f3ed2ff933f21131f8fb1038d6a1baaf4.tar.gz
Fix our ancient tcpslice for >2GB limits.
PR: bin/13691 MFC after: 1 week Submitted by: Bruce A. Mah
Diffstat (limited to 'usr.sbin/tcpdump')
-rw-r--r--usr.sbin/tcpdump/tcpslice/gwtm2secs.c7
-rw-r--r--usr.sbin/tcpdump/tcpslice/search.c26
-rw-r--r--usr.sbin/tcpdump/tcpslice/tcpslice.c6
3 files changed, 23 insertions, 16 deletions
diff --git a/usr.sbin/tcpdump/tcpslice/gwtm2secs.c b/usr.sbin/tcpdump/tcpslice/gwtm2secs.c
index 249454e..f8d2e91 100644
--- a/usr.sbin/tcpdump/tcpslice/gwtm2secs.c
+++ b/usr.sbin/tcpdump/tcpslice/gwtm2secs.c
@@ -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 )
{
diff --git a/usr.sbin/tcpdump/tcpslice/search.c b/usr.sbin/tcpdump/tcpslice/search.c
index a460ffa..75db360 100644
--- a/usr.sbin/tcpdump/tcpslice/search.c
+++ b/usr.sbin/tcpdump/tcpslice/search.c
@@ -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 */
diff --git a/usr.sbin/tcpdump/tcpslice/tcpslice.c b/usr.sbin/tcpdump/tcpslice/tcpslice.c
index adca2f5..ab5de7b 100644
--- a/usr.sbin/tcpdump/tcpslice/tcpslice.c
+++ b/usr.sbin/tcpdump/tcpslice/tcpslice.c
@@ -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
OpenPOWER on IntegriCloud