aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap/lanalyzer.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>1998-11-15 05:29:17 +0000
committerGuy Harris <guy@alum.mit.edu>1998-11-15 05:29:17 +0000
commit86bf1fc851b5564f5700a937de3213e8354aa52e (patch)
tree46a497072e194a9ed5f20733549362347c4d6eef /wiretap/lanalyzer.c
parent8efdf8a74c3f0c32a380d15aeed0a3f6aff56a29 (diff)
Add support to wiretap for reading Sun "snoop" capture files.
That requires that, in the packet-reading loop, we pass to the callback routine the offset in the file of a packet's data, because we can no longer compute that offset by subtracting the size of the captured packet data from the offset in the file after the data was read - "snoop" may stick padding in after the packet data to align packet headers on 4-byte boundaries. Doing that required that we arrange that we do that for "libpcap" capture files as well; the cleanest way to do that was to write our own code for reading "libpcap" capture files, rather than using the "libpcap" code to do it. Make "wtap_dispatch_cb()" and "pcap_dispatch_cb()" static to "file.c", as they're not used elsewhere. If we're using wiretap, don't define in "file.h" stuff used only when we're not using wiretap. Update the wiretap README to reflect Gilbert's and my recent changes. Clean up some memory leaks in "wiretap/lanalyzer.c" and "wiretap/ngsniffer.c", where the capture-file-format-specific data wasn't freed if the open failed. svn path=/trunk/; revision=91
Diffstat (limited to 'wiretap/lanalyzer.c')
-rw-r--r--wiretap/lanalyzer.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/wiretap/lanalyzer.c b/wiretap/lanalyzer.c
index 91bdf86ea4..811fa1b901 100644
--- a/wiretap/lanalyzer.c
+++ b/wiretap/lanalyzer.c
@@ -1,6 +1,6 @@
/* lanalyzer.c
*
- * $Id: lanalyzer.c,v 1.1 1998/11/12 06:01:22 gram Exp $
+ * $Id: lanalyzer.c,v 1.2 1998/11/15 05:29:10 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
@@ -20,6 +20,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
+#include <stdlib.h>
#include "wtap.h"
#include "lanalyzer.h"
@@ -50,6 +51,7 @@ int lanalyzer_open(wtap *wth)
* Let's get some info from it */
wth->capture.lanalyzer = g_malloc(sizeof(lanalyzer_t));
wth->subtype_read = lanalyzer_read;
+ wth->snapshot_length = 16384; /* XXX - available in header? */
/* Read records until we find the start of packets */
@@ -58,6 +60,7 @@ int lanalyzer_open(wtap *wth)
bytes_read = fread(record_type, 1, 2, wth->fh);
bytes_read += fread(record_length, 1, 2, wth->fh);
if (bytes_read != 4) {
+ free(wth->capture.lanalyzer);
return WTAP_FILE_UNKNOWN;
}
@@ -106,6 +109,7 @@ int lanalyzer_read(wtap *wth)
char record_length[2];
guint16 type, length;
gchar descriptor[32];
+ int data_offset;
/* If this is the very first packet, then the fh cursor will already
* be at the start of the packet data instead of at the start of the Trace
@@ -142,13 +146,18 @@ int lanalyzer_read(wtap *wth)
}
buffer_assure_space(&wth->frame_buffer, packet_size);
+ data_offset = ftell(wth->fh);
bytes_read = fread(buffer_start_ptr(&wth->frame_buffer), 1,
packet_size, wth->fh);
if (bytes_read != packet_size) {
- g_error("lanalyzer_read: fread for data: %d bytes out of %d read",
- bytes_read, packet_size);
- return 0;
+ if (ferror(wth->fh)) {
+ g_error("lanalyzer_read: fread for data: read error\n");
+ } else {
+ g_error("lanalyzer_read: fread for data: %d bytes out of %d read",
+ bytes_read, packet_size);
+ }
+ return -1;
}
wth->phdr.ts.tv_sec = 0;
@@ -156,7 +165,5 @@ int lanalyzer_read(wtap *wth)
wth->phdr.caplen = packet_size;
wth->phdr.len = packet_size;
-
- return 1;
+ return data_offset;
}
-