From owner-freebsd-bugs Fri Sep 17 7:10:10 1999 Delivered-To: freebsd-bugs@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (Postfix) with ESMTP id 204A414BFF for ; Fri, 17 Sep 1999 07:10:03 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.3/8.9.2) id HAA56371; Fri, 17 Sep 1999 07:10:03 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Date: Fri, 17 Sep 1999 07:10:03 -0700 (PDT) Message-Id: <199909171410.HAA56371@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: TATEOKA Takamichi Subject: Re: bin/13691: tcpslice cannot extract over 2GB part of trace file Reply-To: TATEOKA Takamichi Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org The following reply was made to PR bin/13691; it has been noted by GNATS. From: TATEOKA Takamichi To: sheldonh@uunet.co.za Cc: tate@spa.is.uec.ac.jp Subject: Re: bin/13691: tcpslice cannot extract over 2GB part of trace file Date: Tue, 14 Sep 1999 21:36:15 +0900 ----Next_Part(Tue_Sep_14_21:36:15_1999)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit From: Sheldon Hearn > Pity. Like I said, the patch wasn't tested and it really was a shot in > the dark. I'll take a closer look some time soon, but let me know anyway > how it went on 3.2R . It makes same errors even on 3.2R box. I looked the patch closer and I found a small bug. I attach a new patch (it is against to original tcpslice source). It seems to work! A bug is simple mistake about a cast came from original code. In function sf_find_end:search.c, the code say: u_int num_bytes; .... num_bytes = MAX_BYTES_FOR_DEFINITE_HEADER; if ( fseeko( pcap_file( p ), (off_t) -num_bytes, 2 ) < 0 ) return 0; The 2nd argument of fseeko() becomes 4294966960 instead of -336 because -num_bytes is still u_int type. I tested on a sample that I reported on send-pr. I'll split a whole file from now, however, I'm not sure I can report it works well since it will take a long time and output files are too large to check them. Thanks a lot! -- Takamichi ----Next_Part(Tue_Sep_14_21:36:15_1999)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit *** search.c.orig Wed Aug 23 14:18:57 1995 --- search.c Tue Sep 14 21:13:37 1999 *************** *** 281,287 **** * end of the file. */ num_bytes = MAX_BYTES_FOR_DEFINITE_HEADER; ! if ( fseek( pcap_file( p ), (long) -num_bytes, 2 ) < 0 ) return 0; buf = (u_char *)malloc((u_int) num_bytes); --- 281,287 ---- * end of the file. */ num_bytes = MAX_BYTES_FOR_DEFINITE_HEADER; ! if ( fseeko( pcap_file( p ), -(off_t)num_bytes, 2 ) < 0 ) return 0; buf = (u_char *)malloc((u_int) num_bytes); *************** *** 346,353 **** 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()" ); done: free( (char *) buf ); --- 346,353 ---- status = 1; /* Seek so that the next read will start at last valid packet. */ ! if ( fseeko( pcap_file( p ), -(off_t) (bufend - hdrpos), 2 ) < 0 ) ! error( "final fseeko() failed in sf_find_end()" ); done: free( (char *) buf ); *************** *** 384,403 **** * negative value if the desired_time is outside the given range. */ ! static long ! interpolated_position( struct timeval *min_time, long min_pos, ! struct timeval *max_time, long max_pos, struct timeval *desired_time ) { double full_span = timeval_diff( max_time, min_time ); double desired_span = timeval_diff( desired_time, min_time ); ! long full_span_pos = max_pos - min_pos; double fractional_offset = desired_span / full_span; if ( fractional_offset < 0.0 || fractional_offset > 1.0 ) return -1; ! return min_pos + (long) (fractional_offset * (double) full_span_pos); } --- 384,403 ---- * negative value if the desired_time is outside the given range. */ ! static off_t ! interpolated_position( struct timeval *min_time, off_t min_pos, ! struct timeval *max_time, off_t max_pos, struct timeval *desired_time ) { double full_span = timeval_diff( max_time, min_time ); double desired_span = timeval_diff( desired_time, min_time ); ! off_t full_span_pos = max_pos - min_pos; double fractional_offset = desired_span / full_span; if ( fractional_offset < 0.0 || fractional_offset > 1.0 ) return -1; ! return min_pos + (fractional_offset * full_span_pos); } *************** *** 412,425 **** { struct pcap_pkthdr hdr; const u_char *buf; ! long pos; int status; for ( ; ; ) { struct timeval *timestamp; ! pos = ftell( pcap_file( p ) ); buf = pcap_next( p, &hdr ); if ( buf == 0 ) --- 412,425 ---- { struct pcap_pkthdr hdr; const u_char *buf; ! off_t pos; int status; for ( ; ; ) { struct timeval *timestamp; ! pos = ftello( pcap_file( p ) ); buf = pcap_next( p, &hdr ); if ( buf == 0 ) *************** *** 443,450 **** } } ! if ( fseek( pcap_file( p ), pos, 0 ) < 0 ) ! error( "fseek() failed in read_up_to()" ); return (status); } --- 443,450 ---- } } ! if ( fseeko( pcap_file( p ), pos, 0 ) < 0 ) ! error( "fseeko() failed in read_up_to()" ); return (status); } *************** *** 466,480 **** int sf_find_packet( pcap_t *p, ! struct timeval *min_time, long min_pos, ! struct timeval *max_time, long max_pos, struct timeval *desired_time ) { int status = 1; 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; u_char *buf, *hdrpos; struct pcap_pkthdr hdr; --- 466,480 ---- int sf_find_packet( pcap_t *p, ! struct timeval *min_time, off_t min_pos, ! struct timeval *max_time, off_t max_pos, struct timeval *desired_time ) { int status = 1; struct timeval min_time_copy, max_time_copy; u_int num_bytes = MAX_BYTES_FOR_DEFINITE_HEADER; int num_bytes_read; ! off_t desired_pos, present_pos; u_char *buf, *hdrpos; struct pcap_pkthdr hdr; *************** *** 501,507 **** break; } ! present_pos = ftell( pcap_file( p ) ); if ( present_pos <= desired_pos && desired_pos - present_pos < STRAIGHT_SCAN_THRESHOLD ) --- 501,507 ---- break; } ! present_pos = ftello( pcap_file( p ) ); if ( present_pos <= desired_pos && desired_pos - present_pos < STRAIGHT_SCAN_THRESHOLD ) *************** *** 517,523 **** 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 = --- 517,523 ---- if ( desired_pos < min_pos ) desired_pos = min_pos; ! if ( fseeko( pcap_file( p ), desired_pos, 0 ) < 0 ) error( "fseek() failed in sf_find_packet()" ); num_bytes_read = *************** *** 540,546 **** 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 ) ) --- 540,546 ---- desired_pos += (hdrpos - buf); /* Seek to the beginning of the header. */ ! if ( fseeko( pcap_file( p ), desired_pos, 0 ) < 0 ) error( "fseek() failed in sf_find_packet()" ); if ( sf_timestamp_less_than( &hdr.ts, desired_time ) ) *** tcpslice.c.orig Thu Jan 21 03:33:13 1999 --- tcpslice.c Tue Sep 14 06:16:10 1999 *************** *** 451,459 **** extract_slice(char filename[], char write_file_name[], struct timeval *start_time, struct timeval *stop_time) { - long start_pos, stop_pos; struct timeval file_start_time, file_stop_time; struct pcap_pkthdr hdr; pcap_t *p; char errbuf[PCAP_ERRBUF_SIZE]; --- 451,459 ---- extract_slice(char filename[], char write_file_name[], struct timeval *start_time, struct timeval *stop_time) { struct timeval file_start_time, file_stop_time; struct pcap_pkthdr hdr; + off_t start_pos, stop_pos; pcap_t *p; char errbuf[PCAP_ERRBUF_SIZE]; *************** *** 462,468 **** error( "bad tcpdump file %s: %s", filename, errbuf ); snaplen = pcap_snapshot( p ); ! start_pos = ftell( pcap_file( p ) ); if ( ! dumper ) { --- 462,468 ---- error( "bad tcpdump file %s: %s", filename, errbuf ); snaplen = pcap_snapshot( p ); ! start_pos = ftello( pcap_file( p ) ); if ( ! dumper ) { *************** *** 483,489 **** 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 --- 483,489 ---- error( "problems finding end packet of file %s", filename ); ! stop_pos = ftello( pcap_file( p ) ); /* sf_find_packet() requires that the time it's passed as its last ----Next_Part(Tue_Sep_14_21:36:15_1999)---- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message