diff options
author | Gilbert Ramirez <gram@alumni.rice.edu> | 1998-11-12 00:06:47 +0000 |
---|---|---|
committer | Gilbert Ramirez <gram@alumni.rice.edu> | 1998-11-12 00:06:47 +0000 |
commit | fcb4c78a6a01d22f0db9d6de870342511030cb01 (patch) | |
tree | d32b2d7467b0266e722aa763c9b48cf0df2c802c /wiretap/ngsniffer.c | |
parent | c2eeef9467d44eb4ea2cd6bd08f62f5c9c293810 (diff) |
A lengthy patch to add the wiretap library. Wiretap is not used by default
because it is still in its infancy, but it can be compiled in optionally.
The library exists in its own subdirectory ethereal/wiretap. This patch also
edits all the packet-*.c files to remove the #include <pcap.h> line which is
unnecessary in these files. In the ethereal code, file.c is the most heavily
modified with #ifdef WITH_WIRETAP lines for the optional library.
svn path=/trunk/; revision=82
Diffstat (limited to 'wiretap/ngsniffer.c')
-rw-r--r-- | wiretap/ngsniffer.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/wiretap/ngsniffer.c b/wiretap/ngsniffer.c new file mode 100644 index 0000000000..dbe6bd57cf --- /dev/null +++ b/wiretap/ngsniffer.c @@ -0,0 +1,36 @@ +#include "wtap.h" +#include "ngsniffer.h" + +int ngsniffer_read(wtap *wth) +{ + struct ngsniffer_hdr frame_hdr; + int bytes_read, packet_size; + + bytes_read = fread(&frame_hdr, 1, sizeof(struct ngsniffer_hdr), wth->fh); + + if (bytes_read == sizeof(struct ngsniffer_hdr)) { + wth->frame_number++; + packet_size = frame_hdr.bytes; + buffer_assure_space(&wth->frame_buffer, packet_size); + + bytes_read = fread(buffer_start_ptr(&wth->frame_buffer), 1, + frame_hdr.bytes, wth->fh); + + if (bytes_read != packet_size) { + g_error("no good fread for data: %d bytes out of %d read\n", + bytes_read, packet_size); + return 0; + } + + wth->file_byte_offset += sizeof(struct ngsniffer_hdr) + packet_size; + + wth->phdr.ts.tv_sec = 0; + wth->phdr.ts.tv_usec = 0; + wth->phdr.caplen = packet_size; + wth->phdr.len = packet_size; + + return 1; + } + + return 0; +} |