aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap/wtap.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/wtap.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/wtap.c')
-rw-r--r--wiretap/wtap.c52
1 files changed, 11 insertions, 41 deletions
diff --git a/wiretap/wtap.c b/wiretap/wtap.c
index 1da8f4ed23..f8e02cd8e8 100644
--- a/wiretap/wtap.c
+++ b/wiretap/wtap.c
@@ -1,6 +1,6 @@
/* wtap.c
*
- * $Id: wtap.c,v 1.2 1998/11/12 06:01:26 gram Exp $
+ * $Id: wtap.c,v 1.3 1998/11/15 05:29:16 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
@@ -23,19 +23,9 @@
#include "wtap.h"
-static
-void pcap_callback_wrapper(u_char *user, const struct pcap_pkthdr *phdr,
- const u_char *buf);
-
-wtap_handler wtap_callback = NULL;
-
FILE* wtap_file(wtap *wth)
{
- if (wth->file_type == WTAP_FILE_PCAP) {
- return pcap_file(wth->capture.pcap);
- }
- else
- return wth->fh;
+ return wth->fh;
}
int wtap_file_type(wtap *wth)
@@ -51,44 +41,24 @@ int wtap_encapsulation(wtap *wth)
int wtap_snapshot_length(wtap *wth)
{
- if (wth->file_type == WTAP_FILE_PCAP)
- return pcap_snapshot(wth->capture.pcap);
- else
- /* this is obviously *very* temporary :-) */
- return 5000;
+ return wth->snapshot_length;
}
void wtap_close(wtap *wth)
{
- if (wth->file_type == WTAP_FILE_PCAP)
- pcap_close(wth->capture.pcap);
- else
- fclose(wth->fh);
+ /* XXX - free up memory? */
+ fclose(wth->fh);
}
void wtap_loop(wtap *wth, int count, wtap_handler callback, u_char* user)
{
int i = 0;
+ int data_offset;
- if (wth->file_type == WTAP_FILE_PCAP) {
- wtap_callback = callback;
- pcap_loop(wth->capture.pcap, count, pcap_callback_wrapper, user);
- }
- else {
- /*while (ngsniffer_read(wth)) {*/
- while (wth->subtype_read(wth)) {
- i++;
- /*g_message("Parsing packet %d", i);*/
- callback(user, &wth->phdr, buffer_start_ptr(&wth->frame_buffer));
- }
+ while ((data_offset = wth->subtype_read(wth)) > 0) {
+ i++;
+ /*g_message("Parsing packet %d", i);*/
+ callback(user, &wth->phdr, data_offset,
+ buffer_start_ptr(&wth->frame_buffer));
}
}
-
-static
-void pcap_callback_wrapper(u_char *user, const struct pcap_pkthdr *phdr,
- const u_char *buf)
-{
-/* struct wtap_pkthdr whdr;
- memcpy(&whdr, phdr, sizeof(struct wtap_pkthdr));*/
- wtap_callback(user, (struct wtap_pkthdr*) phdr, buf);
-}