aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Tüxen <tuexen@fh-muenster.de>2012-12-20 15:20:10 +0000
committerMichael Tüxen <tuexen@fh-muenster.de>2012-12-20 15:20:10 +0000
commit9a2f4c8e9da59c9d5bef6ef987e03802e0c25dc6 (patch)
treefdb4c6e0e23bd429c12a6ffef870196f78f5148a
parent7e84abf005afa5952b046d11584d3ff36522c721 (diff)
Don't use an pcap structures in pcapio.[ch].
Currently, pcapio is only used by dumpcap, which is only compiled if there is pcap support. However, making pcapio independent from libpcap allows it also to be used from text2pcap, which does not rely on libpcap. svn path=/trunk/; revision=46637
-rw-r--r--dumpcap.c14
-rw-r--r--pcapio.c48
-rw-r--r--pcapio.h12
3 files changed, 44 insertions, 30 deletions
diff --git a/dumpcap.c b/dumpcap.c
index 95e54400ed..6df3a0d5f2 100644
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -3982,9 +3982,19 @@ capture_loop_write_packet_cb(u_char *pcap_opts_p, const struct pcap_pkthdr *phdr
If this fails, set "ld->go" to FALSE, to stop the capture, and set
"ld->err" to the error. */
if (global_capture_opts.use_pcapng) {
- successful = libpcap_write_enhanced_packet_block(global_ld.pdh, phdr, pcap_opts->interface_id, ts_mul, pd, 0, &global_ld.bytes_written, &err);
+ successful = libpcap_write_enhanced_packet_block(global_ld.pdh,
+ phdr->ts.tv_sec, phdr->ts.tv_usec,
+ phdr->caplen, phdr->len,
+ pcap_opts->interface_id,
+ ts_mul,
+ pd, 0,
+ &global_ld.bytes_written, &err);
} else {
- successful = libpcap_write_packet(global_ld.pdh, phdr, pd, &global_ld.bytes_written, &err);
+ successful = libpcap_write_packet(global_ld.pdh,
+ phdr->ts.tv_sec, phdr->ts.tv_usec,
+ phdr->caplen, phdr->len,
+ pd,
+ &global_ld.bytes_written, &err);
}
if (!successful) {
global_ld.go = FALSE;
diff --git a/pcapio.c b/pcapio.c
index f4bb7f30dc..2ce52849a8 100644
--- a/pcapio.c
+++ b/pcapio.c
@@ -42,14 +42,13 @@
#include "config.h"
-#ifdef HAVE_LIBPCAP
-
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
-
-#include <pcap.h>
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
#include <glib.h>
@@ -227,16 +226,19 @@ libpcap_write_file_header(FILE *fp, int linktype, int snaplen, gboolean ts_nsecs
/* Write a record for a packet to a dump file.
Returns TRUE on success, FALSE on failure. */
gboolean
-libpcap_write_packet(FILE *fp, const struct pcap_pkthdr *phdr, const u_char *pd,
- long *bytes_written, int *err)
+libpcap_write_packet(FILE *fp,
+ guint32 sec, guint32 usec,
+ guint32 caplen, guint32 len,
+ const unsigned char *pd,
+ long *bytes_written, int *err)
{
struct pcaprec_hdr rec_hdr;
size_t nwritten;
- rec_hdr.ts_sec = phdr->ts.tv_sec;
- rec_hdr.ts_usec = phdr->ts.tv_usec;
- rec_hdr.incl_len = phdr->caplen;
- rec_hdr.orig_len = phdr->len;
+ rec_hdr.ts_sec = sec;
+ rec_hdr.ts_usec = usec;
+ rec_hdr.incl_len = caplen;
+ rec_hdr.orig_len = len;
nwritten = fwrite(&rec_hdr, sizeof(rec_hdr), 1, fp);
if (nwritten != 1) {
if (ferror(fp))
@@ -247,7 +249,7 @@ libpcap_write_packet(FILE *fp, const struct pcap_pkthdr *phdr, const u_char *pd,
}
*bytes_written += sizeof rec_hdr;
- nwritten = fwrite(pd, phdr->caplen, 1, fp);
+ nwritten = fwrite(pd, caplen, 1, fp);
if (nwritten != 1) {
if (ferror(fp))
*err = errno;
@@ -255,7 +257,7 @@ libpcap_write_packet(FILE *fp, const struct pcap_pkthdr *phdr, const u_char *pd,
*err = 0; /* short write */
return FALSE;
}
- *bytes_written += phdr->caplen;
+ *bytes_written += caplen;
return TRUE;
}
@@ -538,10 +540,11 @@ libpcap_write_interface_description_block(FILE *fp,
Returns TRUE on success, FALSE on failure. */
gboolean
libpcap_write_enhanced_packet_block(FILE *fp,
- const struct pcap_pkthdr *phdr,
+ guint32 sec, guint32 usec,
+ guint32 caplen, guint32 len,
guint32 interface_id,
guint ts_mul,
- const u_char *pd,
+ const unsigned char *pd,
guint32 flags,
long *bytes_written,
int *err)
@@ -553,24 +556,23 @@ libpcap_write_enhanced_packet_block(FILE *fp,
const guint32 padding = 0;
block_total_length = sizeof(struct epb) +
- ADD_PADDING(phdr->caplen) +
+ ADD_PADDING(caplen) +
sizeof(guint32);
if (flags != 0) {
block_total_length += 2 * sizeof(struct option) + sizeof(guint32);
}
- timestamp = (guint64)(phdr->ts.tv_sec) * ts_mul +
- (guint64)(phdr->ts.tv_usec);
+ timestamp = (guint64)sec * ts_mul + (guint64)usec;
epb.block_type = ENHANCED_PACKET_BLOCK_TYPE;
epb.block_total_length = block_total_length;
epb.interface_id = interface_id;
epb.timestamp_high = (guint32)((timestamp>>32) & 0xffffffff);
epb.timestamp_low = (guint32)(timestamp & 0xffffffff);
- epb.captured_len = phdr->caplen;
- epb.packet_len = phdr->len;
+ epb.captured_len = caplen;
+ epb.packet_len = len;
WRITE_DATA(fp, &epb, sizeof(struct epb), *bytes_written, err);
- WRITE_DATA(fp, pd, phdr->caplen, *bytes_written, err);
- if (phdr->caplen % 4) {
- WRITE_DATA(fp, &padding, 4 - phdr->caplen % 4, *bytes_written, err);
+ WRITE_DATA(fp, pd, caplen, *bytes_written, err);
+ if (caplen % 4) {
+ WRITE_DATA(fp, &padding, 4 - caplen % 4, *bytes_written, err);
}
if (flags != 0) {
option.type = EPB_FLAGS;
@@ -738,8 +740,6 @@ libpcap_write_interface_statistics_block(FILE *fp,
return TRUE;
}
-#endif /* HAVE_LIBPCAP */
-
/*
* Editor modelines - http://www.wireshark.org/tools/modelines.html
*
diff --git a/pcapio.h b/pcapio.h
index 1d0a1446ad..780c626f74 100644
--- a/pcapio.h
+++ b/pcapio.h
@@ -34,8 +34,11 @@ libpcap_write_file_header(FILE *fp, int linktype, int snaplen, gboolean ts_nsecs
/** Write a record for a packet to a dump file.
Returns TRUE on success, FALSE on failure. */
extern gboolean
-libpcap_write_packet(FILE *fp, const struct pcap_pkthdr *phdr, const u_char *pd,
- long *bytes_written, int *err);
+libpcap_write_packet(FILE *fp,
+ guint32 sec, guint32 usec,
+ guint32 caplen, guint32 len,
+ const unsigned char *pd,
+ long *bytes_written, int *err);
/** Write a section header block (SHB)
*
@@ -85,10 +88,11 @@ libpcap_write_interface_statistics_block(FILE *fp,
extern gboolean
libpcap_write_enhanced_packet_block(FILE *fp,
- const struct pcap_pkthdr *phdr,
+ guint32 sec, guint32 usec,
+ guint32 caplen, guint32 len,
guint32 interface_id,
guint ts_mul,
- const u_char *pd,
+ const unsigned char *pd,
guint32 flags,
long *bytes_written,
int *err);