aboutsummaryrefslogtreecommitdiffstats
path: root/pcapio.c
diff options
context:
space:
mode:
authorMichael Tüxen <tuexen@fh-muenster.de>2009-04-26 15:51:25 +0000
committerMichael Tüxen <tuexen@fh-muenster.de>2009-04-26 15:51:25 +0000
commitf5547c0d7815ff8f6b52b0c70ca3c8b9fcd5db54 (patch)
tree057f7caabc8decd89bba902c01517115a72fcb53 /pcapio.c
parentc68e3442845308c0cdc18068885874ce31f92d96 (diff)
Make ringbuffer.[ch] file format agnostic.
Move write routines to dumpcap.c This is a preparation for pcapng support. svn path=/trunk/; revision=28155
Diffstat (limited to 'pcapio.c')
-rw-r--r--pcapio.c31
1 files changed, 18 insertions, 13 deletions
diff --git a/pcapio.c b/pcapio.c
index d6df7840ae..bed260c0ae 100644
--- a/pcapio.c
+++ b/pcapio.c
@@ -92,21 +92,27 @@ struct pcaprec_hdr {
guint32 orig_len; /* actual length of packet */
};
-/* Returns a FILE * to write to on success, NULL on failure; sets "*err" to
- an error code, or 0 for a short write, on failure */
+/* Returns a FILE * to write to on success, NULL on failure */
FILE *
-libpcap_fdopen(int fd, int linktype, int snaplen, long *bytes_written,
- int *err)
+libpcap_fdopen(int fd, int *err)
{
FILE *fp;
- struct pcap_hdr file_hdr;
- size_t nwritten;
fp = fdopen(fd, "wb");
if (fp == NULL) {
*err = errno;
- return NULL;
}
+ return fp;
+}
+
+/* Write the file header to a dump file.
+ Returns TRUE on success, FALSE on failure.
+ Sets "*err" to an error code, or 0 for a short write, on failure*/
+gboolean
+libpcap_write_file_header(FILE *fp, int linktype, int snaplen, long *bytes_written, int *err)
+{
+ struct pcap_hdr file_hdr;
+ size_t nwritten;
file_hdr.magic = PCAP_MAGIC;
/* current "libpcap" format is 2.4 */
@@ -116,18 +122,17 @@ libpcap_fdopen(int fd, int linktype, int snaplen, long *bytes_written,
file_hdr.sigfigs = 0; /* unknown, but also apparently unused */
file_hdr.snaplen = snaplen;
file_hdr.network = linktype;
- nwritten = fwrite(&file_hdr, 1, sizeof file_hdr, fp);
- if (nwritten != sizeof file_hdr) {
+ nwritten = fwrite(&file_hdr, 1, sizeof(file_hdr), fp);
+ if (nwritten != sizeof(file_hdr)) {
if (nwritten == 0 && ferror(fp))
*err = errno;
else
*err = 0; /* short write */
- fclose(fp);
- return NULL;
+ return FALSE;
}
- *bytes_written = sizeof file_hdr;
+ *bytes_written += sizeof(file_hdr);
- return fp;
+ return TRUE;
}
/* Write a record for a packet to a dump file.