Ethereal-dev: Re: [ethereal-dev] Checked in Wiretap changes to eliminate "ftell()" calls

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Olivier Abad <abad@xxxxxxxxxxxxx>
Date: Mon, 30 Aug 1999 22:28:14 +0200
On lun, aoû 30, 1999 at 12:52:25 -0700, Guy Harris wrote:
> > Does changing that code to
> > 
> > 	if (wth->file_encap == WTAP_ENCAP_ETHERNET) {
> > 		fseek(wth->fh, 294, SEEK_CUR);
> > 		wth->data_offset += 294;
> > 	} else if (wth->file_encap == WTAP_ENCAP_LAPB) {
> > 		fseek(wth->fh, 297, SEEK_CUR);
> > 		wth->data_offset += 297;
> > 	}
> > 
> > also work?

No. There are other fseek() before.

Here is a new patch with no ftell() (I didn't read the subject carefully
enough the first time).

> Well, it seems to work as well as the vanilla Ethereal 0.7.2 I have here
> does...
> 
> ...unfortunately, that's not very well, as it complains that the file is
> truncated, and the time stamps look bogus, as does some of the data.
> 
> I note that "radcom.c" doesn't do any "pntoh[ls]()" or "pletoh[ls]()"
> calls, which means it'd probably work only on a machine with the same
> byte order as the machine that wrote out the data; the RADCOM boxes have
> both a RISC processor and a PC in them (at least as I read the stuff on
> their Web site), and if the PC is what's writing stuff out, that would
> explain why the file doesn't work on the (big-endian) SPARC box I tried
> it on.

You're right. The PC is writing the capture files. It works for me on my
Linux/i386 boxes, so I forgot to take byte order into account...

> I'll put "pletoh[ls]()"s in it, and see if that works better.

Thanks.

BTW, ethereal also tells me that the file is truncated. I think that the
end of the file is not frame data, but something else. I'll try to find
out about it tomorrow.

Here is the patch :

Index: wiretap/radcom.c
===================================================================
RCS file: /cvsroot/ethereal/wiretap/radcom.c,v
retrieving revision 1.5
diff -u -r1.5 radcom.c
--- radcom.c	1999/08/28 01:19:45	1.5
+++ radcom.c	1999/08/30 20:02:55
@@ -70,6 +70,7 @@
 	}
 
 	fseek(wth->fh, 0x8B, SEEK_SET);
+	wth->data_offset = 0x8B;
 	errno = WTAP_ERR_CANT_READ;
 	bytes_read = fread(&byte, 1, 1, wth->fh);
 	if (bytes_read != 1) {
@@ -79,6 +80,7 @@
 		}
 		return 0;
 	}
+	wth->data_offset += 1;
 	while (byte) {
 		errno = WTAP_ERR_CANT_READ;
 		bytes_read = fread(&byte, 1, 1, wth->fh);
@@ -89,8 +91,10 @@
 			}
 			return 0;
 		}
+		wth->data_offset += 1;
 	}
 	fseek(wth->fh, 1, SEEK_CUR);
+	wth->data_offset += 1;
 
 	/* Get capture start time */
 	errno = WTAP_ERR_CANT_READ;
@@ -102,6 +106,7 @@
 		}
 		return 0;
 	}
+	wth->data_offset += sizeof(struct frame_date);
 
 	/* This is a radcom file */
 	wth->file_type = WTAP_FILE_RADCOM;
@@ -119,26 +124,32 @@
 	wth->capture.radcom->start = mktime(&tm);
 
 	fseek(wth->fh, sizeof(struct frame_date), SEEK_CUR);
+	wth->data_offset += sizeof(struct frame_date);
 
 	errno = WTAP_ERR_CANT_READ;
 	bytes_read = fread(search_encap, 1, 7, wth->fh);
 	if (bytes_read != 7) {
 		goto read_error;
 	}
+	wth->data_offset += 7;
 	while (memcmp(encap_magic, search_encap, 7)) {
 		fseek(wth->fh, -6, SEEK_CUR);
+		wth->data_offset -= 6;
 		errno = WTAP_ERR_CANT_READ;
 		bytes_read = fread(search_encap, 1, 7, wth->fh);
 		if (bytes_read != 7) {
 			goto read_error;
 		}
+		wth->data_offset += 7;
 	}
 	fseek(wth->fh, 12, SEEK_CUR);
+	wth->data_offset += 12;
 	errno = WTAP_ERR_CANT_READ;
 	bytes_read = fread(search_encap, 1, 4, wth->fh);
 	if (bytes_read != 4) {
 		goto read_error;
 	}
+	wth->data_offset += 4;
 	if (!memcmp(search_encap, "LAPB", 4))
 		wth->file_encap = WTAP_ENCAP_LAPB;
 	else if (!memcmp(search_encap, "Ethe", 4))
@@ -167,10 +178,10 @@
 
 	if (wth->file_encap == WTAP_ENCAP_ETHERNET) {
 		fseek(wth->fh, 294, SEEK_CUR);
-		wth->data_offset = 294;
+		wth->data_offset += 294;
 	} else if (wth->file_encap == WTAP_ENCAP_LAPB) {
 		fseek(wth->fh, 297, SEEK_CUR);
-		wth->data_offset = 297;
+		wth->data_offset += 297;
 	}
 
 	return 1;
@@ -260,6 +271,7 @@
 	wth->phdr.pseudo_header.x25.flags = (dce & 0x1) ? 0x00 : 0x80;
 
 	fseek(wth->fh, 9, SEEK_CUR);
+	wth->data_offset += 9;
 
 	/*
 	 * Read the packet data.

-- 
"In matters of principle, stand like a rock; in matters of taste, swim with 
the current."
-- Thomas Jefferson