/* file.c
*
- * $Id: file.c,v 1.18 1999/08/22 02:29:38 guy Exp $
+ * $Id: file.c,v 1.19 1999/08/28 01:19:43 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
/* initialization */
wth->file_encap = WTAP_ENCAP_UNKNOWN;
+ wth->data_offset = 0;
/* Try all file types */
for (i = 0; i < N_FILE_TYPES; i++) {
/* iptrace.c
*
- * $Id: iptrace.c,v 1.9 1999/08/24 03:19:34 guy Exp $
+ * $Id: iptrace.c,v 1.10 1999/08/28 01:19:43 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
char name[12];
fseek(wth->fh, 0, SEEK_SET);
+ wth->data_offset = 0;
errno = WTAP_ERR_CANT_READ;
bytes_read = fread(name, 1, 11, wth->fh);
if (bytes_read != 11) {
}
return 0;
}
+ wth->data_offset += 11;
name[11] = 0;
if (strcmp(name, "iptrace 2.0") != 0) {
return 0;
}
return 0;
}
+ wth->data_offset += 40;
packet_size = pntohs(&header[2]) - 32;
/* Read the packet data */
buffer_assure_space(wth->frame_buffer, packet_size);
- data_offset = ftell(wth->fh);
+ data_offset = wth->data_offset;
errno = WTAP_ERR_CANT_READ;
bytes_read = fread(buffer_start_ptr(wth->frame_buffer), 1,
packet_size, wth->fh);
*err = WTAP_ERR_SHORT_READ;
return -1;
}
+ wth->data_offset += packet_size;
wth->phdr.len = packet_size;
wth->phdr.caplen = packet_size;
/* lanalyzer.c
*
- * $Id: lanalyzer.c,v 1.13 1999/08/22 02:29:40 guy Exp $
+ * $Id: lanalyzer.c,v 1.14 1999/08/28 01:19:43 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
struct tm tm;
fseek(wth->fh, 0, SEEK_SET);
+ wth->data_offset = 0;
errno = WTAP_ERR_CANT_READ;
bytes_read = fread(LE_record_type, 1, 2, wth->fh);
bytes_read += fread(LE_record_length, 1, 2, wth->fh);
}
return 0;
}
+ wth->data_offset += 4;
record_type = pletohs(LE_record_type);
record_length = pletohs(LE_record_length); /* make sure to do this for while() loop */
/* Read records until we find the start of packets */
while (1) {
fseek(wth->fh, record_length, SEEK_CUR);
+ wth->data_offset += record_length;
errno = WTAP_ERR_CANT_READ;
bytes_read = fread(LE_record_type, 1, 2, wth->fh);
bytes_read += fread(LE_record_length, 1, 2, wth->fh);
g_free(wth->capture.lanalyzer);
return 0;
}
+ wth->data_offset += 4;
record_type = pletohs(LE_record_type);
record_length = pletohs(LE_record_length);
g_free(wth->capture.lanalyzer);
return 0;
}
+ wth->data_offset += sizeof summary;
/* Assume that the date of the creation of the trace file
* is the same date of the trace. Lanalyzer doesn't
/* Go back header number ob ytes so that lanalyzer_read
* can read this header */
fseek(wth->fh, -bytes_read, SEEK_CUR);
+ wth->data_offset -= bytes_read;
return 1;
default:
}
return 0;
}
+ wth->data_offset += 2;
bytes_read = fread(LE_record_length, 1, 2, wth->fh);
if (bytes_read != 2) {
if (ferror(wth->fh))
*err = WTAP_ERR_SHORT_READ;
return -1;
}
+ wth->data_offset += 2;
record_type = pletohs(LE_record_type);
record_length = pletohs(LE_record_length);
*err = WTAP_ERR_SHORT_READ;
return -1;
}
+ wth->data_offset += DESCRIPTOR_LEN;
/* Read the packet data */
buffer_assure_space(wth->frame_buffer, packet_size);
- data_offset = ftell(wth->fh);
+ data_offset = wth->data_offset;
errno = WTAP_ERR_CANT_READ;
bytes_read = fread(buffer_start_ptr(wth->frame_buffer), 1,
packet_size, wth->fh);
*err = WTAP_ERR_SHORT_READ;
return -1;
}
+ wth->data_offset += packet_size;
true_size = pletohs(&descriptor[4]);
time_low = pletohs(&descriptor[8]);
/* libpcap.c
*
- * $Id: libpcap.c,v 1.15 1999/08/24 03:19:34 guy Exp $
+ * $Id: libpcap.c,v 1.16 1999/08/28 01:19:44 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
/* Read in the number that should be at the start of a "libpcap" file */
fseek(wth->fh, 0, SEEK_SET);
+ wth->data_offset = 0;
errno = WTAP_ERR_CANT_READ;
bytes_read = fread(&magic, 1, sizeof magic, wth->fh);
if (bytes_read != sizeof magic) {
}
return 0;
}
+ wth->data_offset += sizeof magic;
if (magic == PCAP_SWAPPED_MAGIC) {
/* Host that wrote it has a byte order opposite to ours. */
}
return 0;
}
+ wth->data_offset += sizeof hdr;
if (byte_swapped) {
/* Byte-swap the header fields about which we care. */
}
return 0;
}
+ wth->data_offset += sizeof hdr;
if (wth->capture.pcap->byte_swapped) {
/* Byte-swap the record header fields. */
}
buffer_assure_space(wth->frame_buffer, packet_size);
- data_offset = ftell(wth->fh);
+ data_offset = wth->data_offset;
errno = WTAP_ERR_CANT_READ;
bytes_read = fread(buffer_start_ptr(wth->frame_buffer), 1,
packet_size, wth->fh);
*err = WTAP_ERR_SHORT_READ;
return -1;
}
+ wth->data_offset += packet_size;
wth->phdr.ts.tv_sec = hdr.ts_sec;
wth->phdr.ts.tv_usec = hdr.ts_usec;
/* netmon.c
*
- * $Id: netmon.c,v 1.12 1999/08/24 03:19:33 guy Exp $
+ * $Id: netmon.c,v 1.13 1999/08/28 01:19:44 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
/* Seek to the beginning of the data records. */
fseek(wth->fh, CAPTUREFILE_HEADER_SIZE, SEEK_SET);
+ wth->data_offset = CAPTUREFILE_HEADER_SIZE;
return 1;
}
double t;
/* Have we reached the end of the packet data? */
- data_offset = ftell(wth->fh);
- if (data_offset >= wth->capture.netmon->end_offset) {
+ if (wth->data_offset >= wth->capture.netmon->end_offset) {
/* Yes. */
return 0;
}
/* Read record header. */
- /* Read record header. */
switch (wth->capture.netmon->version_major) {
case 1:
}
return 0;
}
- data_offset += hdr_size;
+ wth->data_offset += hdr_size;
switch (wth->capture.netmon->version_major) {
return -1;
}
buffer_assure_space(wth->frame_buffer, packet_size);
+ data_offset = wth->data_offset;
errno = WTAP_ERR_CANT_READ;
bytes_read = fread(buffer_start_ptr(wth->frame_buffer), 1,
packet_size, wth->fh);
*err = WTAP_ERR_SHORT_READ;
return -1;
}
+ wth->data_offset += packet_size;
t = (double)wth->capture.netmon->start_usecs;
switch (wth->capture.netmon->version_major) {
/* netxray.c
*
- * $Id: netxray.c,v 1.12 1999/08/24 03:19:33 guy Exp $
+ * $Id: netxray.c,v 1.13 1999/08/28 01:19:44 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
/* Read in the string that should be at the start of a NetXRay
* file */
fseek(wth->fh, 0, SEEK_SET);
+ wth->data_offset = 0;
errno = WTAP_ERR_CANT_READ;
bytes_read = fread(magic, 1, sizeof magic, wth->fh);
if (bytes_read != sizeof magic) {
}
return 0;
}
+ wth->data_offset += sizeof magic;
if (memcmp(magic, netxray_magic, sizeof netxray_magic) != 0) {
return 0;
}
return 0;
}
+ wth->data_offset += sizeof hdr;
/* It appears that version 1.1 files (as produced by Windows
* Sniffer Pro 2.0.01) have the time stamp in microseconds,
/* Seek to the beginning of the data records. */
fseek(wth->fh, pletohl(&hdr.start_offset), SEEK_SET);
+ wth->data_offset = pletohl(&hdr.start_offset);
return 1;
}
reread:
/* Have we reached the end of the packet data? */
- data_offset = ftell(wth->fh);
- if (data_offset == wth->capture.netxray->end_offset) {
+ if (wth->data_offset == wth->capture.netxray->end_offset) {
/* Yes. */
return 0;
}
/* Yes. Remember that we did. */
wth->capture.netxray->wrapped = 1;
fseek(wth->fh, CAPTUREFILE_HEADER_SIZE, SEEK_SET);
+ wth->data_offset = CAPTUREFILE_HEADER_SIZE;
goto reread;
}
/* We've already wrapped - don't wrap again. */
return 0;
}
- data_offset += hdr_size;
+ wth->data_offset += hdr_size;
packet_size = pletohs(&hdr.hdr_1_x.incl_len);
buffer_assure_space(wth->frame_buffer, packet_size);
+ data_offset = wth->data_offset;
errno = WTAP_ERR_CANT_READ;
bytes_read = fread(buffer_start_ptr(wth->frame_buffer), 1,
packet_size, wth->fh);
*err = WTAP_ERR_SHORT_READ;
return -1;
}
+ wth->data_offset += packet_size;
t = (double)pletohl(&hdr.hdr_1_x.timelo)
+ (double)pletohl(&hdr.hdr_1_x.timehi)*4294967296.0;
/* ngsniffer.c
*
- * $Id: ngsniffer.c,v 1.20 1999/08/24 03:19:32 guy Exp $
+ * $Id: ngsniffer.c,v 1.21 1999/08/28 01:19:44 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
/* Read in the string that should be at the start of a Sniffer file */
fseek(wth->fh, 0, SEEK_SET);
+ wth->data_offset = 0;
errno = WTAP_ERR_CANT_READ;
bytes_read = fread(magic, 1, 17, wth->fh);
if (bytes_read != 17) {
}
return 0;
}
+ wth->data_offset += 17;
magic[17] = 0;
}
return 0;
}
+ wth->data_offset += 6;
type = pletohs(record_type);
length = pletohs(record_length);
}
return 0;
}
+ wth->data_offset += sizeof version;
/* Make sure this is an uncompressed Sniffer file */
if (version.format != 1) {
}
return 0;
}
+ wth->data_offset += 2;
errno = WTAP_ERR_CANT_READ;
bytes_read = fread(record_length, 1, 4, wth->fh);
if (bytes_read != 4) {
*err = WTAP_ERR_SHORT_READ;
return -1;
}
+ wth->data_offset += 4;
type = pletohs(record_type);
length = pletohs(record_length);
*err = WTAP_ERR_SHORT_READ;
return -1;
}
+ wth->data_offset += sizeof frame2;
time_low = pletohs(&frame2.time_low);
time_med = pletohs(&frame2.time_med);
time_high = pletohs(&frame2.time_high);
*err = WTAP_ERR_SHORT_READ;
return -1;
}
+ wth->data_offset += sizeof frame4;
time_low = pletohs(&frame4.time_low);
time_med = pletohs(&frame4.time_med);
time_high = frame4.time_high;
* portion, and keep looping.
*/
fseek(wth->fh, length, SEEK_CUR);
+ wth->data_offset += length;
}
found:
* Read the packet data.
*/
buffer_assure_space(wth->frame_buffer, length);
- data_offset = ftell(wth->fh);
+ data_offset = wth->data_offset;
errno = WTAP_ERR_CANT_READ;
bytes_read = fread(buffer_start_ptr(wth->frame_buffer), 1,
length, wth->fh);
*err = WTAP_ERR_SHORT_READ;
return -1;
}
+ wth->data_offset += length;
t = t/1000000.0 * wth->capture.ngsniffer->timeunit; /* t = # of secs */
t += wth->capture.ngsniffer->start;
}
}*/
- if (wth->file_encap == WTAP_ENCAP_ETHERNET)
+ if (wth->file_encap == WTAP_ENCAP_ETHERNET) {
fseek(wth->fh, 294, SEEK_CUR);
- else if (wth->file_encap == WTAP_ENCAP_LAPB)
+ wth->data_offset = 294;
+ } else if (wth->file_encap == WTAP_ENCAP_LAPB) {
fseek(wth->fh, 297, SEEK_CUR);
+ wth->data_offset = 297;
+ }
return 1;
char dce;
fseek(wth->fh, 4, SEEK_CUR);
+ wth->data_offset += 4;
/*
* Read the frame size
}
return 0;
}
+ wth->data_offset += 2;
if (wth->file_encap == WTAP_ENCAP_LAPB)
length -= 2; /* FCS */
wth->phdr.caplen = length;
fseek(wth->fh, 5, SEEK_CUR);
+ wth->data_offset += 5;
errno = WTAP_ERR_CANT_READ;
bytes_read = fread(&date, 1, sizeof(struct frame_date), wth->fh);
if (bytes_read != sizeof(struct frame_date)) {
*err = WTAP_ERR_SHORT_READ;
return -1;
}
+ wth->data_offset += sizeof(struct frame_date);
tm.tm_year = date.year-1900;
tm.tm_mon = date.month-1;
wth->phdr.ts.tv_usec = date.usec;
fseek(wth->fh, 6, SEEK_CUR);
+ wth->data_offset += 6;
errno = WTAP_ERR_CANT_READ;
bytes_read = fread(&dce, 1, 1, wth->fh);
if (bytes_read != 1) {
*err = WTAP_ERR_SHORT_READ;
return -1;
}
+ wth->data_offset += 1;
wth->phdr.pseudo_header.x25.flags = (dce & 0x1) ? 0x00 : 0x80;
fseek(wth->fh, 9, SEEK_CUR);
* Read the packet data.
*/
buffer_assure_space(wth->frame_buffer, length);
- data_offset = ftell(wth->fh);
+ data_offset = wth->data_offset;
errno = WTAP_ERR_CANT_READ;
bytes_read = fread(buffer_start_ptr(wth->frame_buffer), 1,
length, wth->fh);
*err = WTAP_ERR_SHORT_READ;
return -1;
}
+ wth->data_offset += length;
wth->phdr.pkt_encap = wth->file_encap;
- if (wth->file_encap == WTAP_ENCAP_LAPB)
+ if (wth->file_encap == WTAP_ENCAP_LAPB) {
fseek(wth->fh, 2, SEEK_CUR); /* FCS */
+ wth->data_offset += 2;
+ }
return data_offset;
}
/* snoop.c
*
- * $Id: snoop.c,v 1.8 1999/08/24 03:19:32 guy Exp $
+ * $Id: snoop.c,v 1.9 1999/08/28 01:19:45 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
/* Read in the string that should be at the start of a "snoop" file */
fseek(wth->fh, 0, SEEK_SET);
+ wth->data_offset = 0;
errno = WTAP_ERR_CANT_READ;
bytes_read = fread(magic, 1, sizeof magic, wth->fh);
if (bytes_read != sizeof magic) {
}
return 0;
}
+ wth->data_offset += sizeof magic;
if (memcmp(magic, snoop_magic, sizeof snoop_magic) != 0) {
return 0;
}
return 0;
}
+ wth->data_offset += sizeof hdr;
hdr.version = ntohl(hdr.version);
if (hdr.version != 2) {
}
return 0;
}
+ wth->data_offset += sizeof hdr;
packet_size = ntohl(hdr.incl_len);
if (packet_size > WTAP_MAX_PACKET_SIZE) {
return -1;
}
buffer_assure_space(wth->frame_buffer, packet_size);
- data_offset = ftell(wth->fh);
+ data_offset = wth->data_offset;
errno = WTAP_ERR_CANT_READ;
bytes_read = fread(buffer_start_ptr(wth->frame_buffer), 1,
packet_size, wth->fh);
*err = WTAP_ERR_SHORT_READ;
return -1;
}
+ wth->data_offset += packet_size;
wth->phdr.ts.tv_sec = ntohl(hdr.ts_sec);
wth->phdr.ts.tv_usec = ntohl(hdr.ts_usec);
/* Skip over the padding. */
fseek(wth->fh, ntohl(hdr.rec_len) - (sizeof hdr + packet_size),
SEEK_CUR);
+ wth->data_offset += ntohl(hdr.rec_len) - (sizeof hdr + packet_size);
return data_offset;
}
/* wtap.h
*
- * $Id: wtap.h,v 1.34 1999/08/24 03:19:34 guy Exp $
+ * $Id: wtap.h,v 1.35 1999/08/28 01:19:45 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
struct Buffer *frame_buffer;
struct wtap_pkthdr phdr;
+ long data_offset;
+
union {
libpcap_t *pcap;
lanalyzer_t *lanalyzer;