diff options
author | Michael Tüxen <tuexen@fh-muenster.de> | 2012-12-21 14:34:26 +0000 |
---|---|---|
committer | Michael Tüxen <tuexen@fh-muenster.de> | 2012-12-21 14:34:26 +0000 |
commit | 2440176cabced62995e30373cbd48615a91f0137 (patch) | |
tree | 2084e95c58f2c441121a93640341f1f31745d2d7 /text2pcap.c | |
parent | edc47dbf8883f4f9e8b16ad0b8270629266ca59f (diff) | |
download | wireshark-2440176cabced62995e30373cbd48615a91f0137.tar.gz wireshark-2440176cabced62995e30373cbd48615a91f0137.tar.bz2 wireshark-2440176cabced62995e30373cbd48615a91f0137.zip |
Use pcapio routines. This concludes the preperation for
adding pcapng support.
svn path=/trunk/; revision=46673
Diffstat (limited to 'text2pcap.c')
-rw-r--r-- | text2pcap.c | 46 |
1 files changed, 16 insertions, 30 deletions
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); } } |