summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Tüxen <tuexen@fh-muenster.de>2012-12-21 14:34:26 +0000
committerMichael Tüxen <tuexen@fh-muenster.de>2012-12-21 14:34:26 +0000
commit2440176cabced62995e30373cbd48615a91f0137 (patch)
tree2084e95c58f2c441121a93640341f1f31745d2d7
parentedc47dbf8883f4f9e8b16ad0b8270629266ca59f (diff)
downloadwireshark-2440176cabced62995e30373cbd48615a91f0137.tar.gz
Use pcapio routines. This concludes the preperation for
adding pcapng support. svn path=/trunk/; revision=46673
-rw-r--r--CMakeLists.txt1
-rw-r--r--Makefile.common5
-rw-r--r--text2pcap.c46
3 files changed, 22 insertions, 30 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6a7e2f0ab9..a0a31e6ca9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -890,6 +890,7 @@ if(BUILD_text2pcap)
)
set(text2pcap_CLEAN_FILES
text2pcap.c
+ pcapio.c
)
set(text2pcap_FILES
${text2pcap_CLEAN_FILES}
diff --git a/Makefile.common b/Makefile.common
index 7a5b90b3bd..900d1afce2 100644
--- a/Makefile.common
+++ b/Makefile.common
@@ -159,9 +159,14 @@ rawshark_SOURCES = \
# text2pcap specifics
text2pcap_SOURCES = \
+ pcapio.c \
text2pcap.c \
text2pcap-scanner.l
+text2pcap_INCLUDES = \
+ pcapio.h \
+ text2pcap.h
+
# mergecap specifics
mergecap_SOURCES = \
mergecap.c \
diff --git a/text2pcap.c b/text2pcap.c
index e0c93297d3..f80061a140 100644
--- a/text2pcap.c
+++ b/text2pcap.c
@@ -133,6 +133,7 @@
# include "wsutil/strptime.h"
#endif
+#include "pcapio.h"
#include "text2pcap.h"
#include "svnversion.h"
@@ -201,6 +202,7 @@ static int packet_preamble_len = 0;
/* Number of packets read and written */
static unsigned long num_packets_read = 0;
static unsigned long num_packets_written = 0;
+static long bytes_written = 0;
/* Time code of packet, derived from packet_preamble */
static time_t ts_sec = 0;
@@ -576,7 +578,7 @@ write_current_packet (void)
{
unsigned long length = 0;
guint16 padding_length = 0;
- struct pcaprec_hdr ph;
+ int err;
if (curr_offset > header_length) {
/* Write the packet */
@@ -715,23 +717,19 @@ write_current_packet (void)
write_bytes((const char *)&tempbuf, 60 - length);
length = 60;
}
-
- /* Write PCAP packet header */
- ph.ts_sec = (guint32)ts_sec;
- ph.ts_usec = ts_usec;
+ if (!libpcap_write_packet(output_file,
+ ts_sec, ts_usec,
+ length, length,
+ packet_buf,
+ &bytes_written, &err)) {
+ fprintf(stderr, "File write error [%s] : %s\n",
+ output_filename, g_strerror(err));
+ exit(-1);
+ }
if (ts_fmt == NULL) {
/* fake packet counter */
ts_usec++;
}
- ph.incl_len = length;
- ph.orig_len = length;
- if (fwrite(&ph, sizeof(ph), 1, output_file) != 1) {
- goto write_current_packet_err;
- }
- /* Write packet */
- if (fwrite(packet_buf, length, 1, output_file) != 1) {
- goto write_current_packet_err;
- }
if (!quiet) {
fprintf(stderr, "Wrote packet of %lu bytes.\n", length);
}
@@ -741,11 +739,6 @@ write_current_packet (void)
packet_start += curr_offset;
curr_offset = header_length;
return;
-
-write_current_packet_err:
- fprintf(stderr, "File write error [%s] : %s\n",
- output_filename, g_strerror(errno));
- exit(-1);
}
/*----------------------------------------------------------------------
@@ -754,19 +747,12 @@ write_current_packet_err:
static void
write_file_header (void)
{
- struct pcap_hdr fh;
-
- fh.magic = PCAP_MAGIC;
- fh.version_major = 2;
- fh.version_minor = 4;
- fh.thiszone = 0;
- fh.sigfigs = 0;
- fh.snaplen = 102400;
- fh.network = pcap_link_type;
+ int err;
- if (fwrite(&fh, sizeof(fh), 1, output_file) != 1) {
+ if (!libpcap_write_file_header(output_file, pcap_link_type, 102400,
+ FALSE, &bytes_written, &err)) {
fprintf(stderr, "File write error [%s] : %s\n",
- output_filename, g_strerror(errno));
+ output_filename, g_strerror(err));
exit(-1);
}
}