Skip to Content
[CAIDA - Center for Applied Internet Data Analysis logo]
The Center for Applied Internet Data Analysis
corsaro_file.h
Go to the documentation of this file.
1 /*
2  * corsaro
3  *
4  * Alistair King, CAIDA, UC San Diego
5  * corsaro-info@caida.org
6  *
7  * Copyright (C) 2012 The Regents of the University of California.
8  *
9  * This file is part of corsaro.
10  *
11  * corsaro is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * corsaro is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with corsaro. If not, see <http://www.gnu.org/licenses/>.
23  *
24  */
25 
26 #ifndef __CORSARO_FILE_H
27 #define __CORSARO_FILE_H
28 
29 #include "config.h"
30 #include "corsaro_int.h"
31 
32 #include <fcntl.h>
33 #include <stdarg.h>
34 
35 #include "libtrace.h"
36 #include "wandio.h"
37 
51 #define CORSARO_FILE_COMPRESS_LEVEL_DEFAULT 6
52 
54 #define CORSARO_FILE_ZLIB_SUFFIX ".gz"
55 
57 #define CORSARO_FILE_BZ2_SUFFIX ".bz2"
58 
60 typedef struct corsaro_file
61 {
64 
66  union
67  {
69  struct
70  {
72  iow_t *io;
73  } ms_wandio;
74 
76  struct
77  {
79  libtrace_out_t *trace;
80  } ms_trace;
81  } mode_state;
82 
84 
86 typedef struct corsaro_file_in
87 {
90 
92  union
93  {
95  struct
96  {
98  io_t *io;
99  } ms_wandio;
100 
102  struct
103  {
105  libtrace_t *trace;
106  } ms_trace;
107  } mode_state;
108 
110 
112 /* this is what the 'public' should use to retrieve the mode */
113 #define CORSARO_FILE_MODE(file) (file->mode)
114 
116 #define state_wandio mode_state.ms_wandio
117 
118 #define wand_io mode_state.ms_wandio.io
119 
121 #define state_trace mode_state.ms_trace
122 
123 #define trace_io mode_state.ms_trace.trace
124 
139 
151  const char *filename,
152  corsaro_file_mode_t mode,
153  corsaro_file_compress_t compress_type,
154  int compress_level,
155  int flags);
156 
165 off_t corsaro_file_write(struct corsaro *corsaro,
166  corsaro_file_t *file, const void *buffer, off_t len);
167 
168 
180  corsaro_file_t *file, libtrace_packet_t *packet);
181 
193 off_t corsaro_file_vprintf(struct corsaro *corsaro, corsaro_file_t *file,
194  const char *format, va_list args);
195 
207 off_t corsaro_file_printf(struct corsaro *corsaro, corsaro_file_t *file,
208  const char *format, ...);
209 
215 void corsaro_file_flush(struct corsaro *corsaro, corsaro_file_t *file);
216 
222 void corsaro_file_close(struct corsaro *corsaro, corsaro_file_t *file);
223 
245 corsaro_file_in_t *corsaro_file_ropen(const char *filename);
246 
254 off_t corsaro_file_rread(corsaro_file_in_t *file, void *buffer, off_t len);
255 
268 off_t corsaro_file_rgets(corsaro_file_in_t *file, void *buffer, off_t len);
269 
281  libtrace_packet_t *packet,
282  uint16_t len);
283 
292 off_t corsaro_file_rpeek(corsaro_file_in_t *file, void *buffer, off_t len);
293 
306 off_t corsaro_file_rseek(corsaro_file_in_t *file, off_t offset, int whence);
307 
314 
320 
323 #endif /* __CORSARO_FILE_H */
libtrace_t * trace
The libtrace object used to create the trace.
Definition: corsaro_file.h:105
An opaque structure defining an corsaro input file.
Definition: corsaro_file.h:86
struct corsaro_file::@0::@2 ms_trace
Trace mode state.
union corsaro_file::@0 mode_state
Per-framework state for the file.
off_t corsaro_file_rgets(corsaro_file_in_t *file, void *buffer, off_t len)
Reads a string from an corsaro input file into the provided buffer.
Definition: corsaro_file.c:343
An opaque structure defining an corsaro output file.
Definition: corsaro_file.h:60
off_t corsaro_file_printf(struct corsaro *corsaro, corsaro_file_t *file, const char *format,...)
Print a string to an corsaro file.
Definition: corsaro_file.c:214
off_t corsaro_file_rtell(corsaro_file_in_t *file)
Returns the current offset of the read pointer for an corsaro input file.
Definition: corsaro_file.c:417
off_t corsaro_file_write_packet(struct corsaro *corsaro, corsaro_file_t *file, libtrace_packet_t *packet)
Write a libtrace packet to an corsaro output file.
Definition: corsaro_file.c:154
off_t corsaro_file_rpeek(corsaro_file_in_t *file, void *buffer, off_t len)
Reads from an corsaro input file into the provided buffer, but does not update the read pointer...
Definition: corsaro_file.c:395
void corsaro_file_close(struct corsaro *corsaro, corsaro_file_t *file)
Closes an corsaro output file and frees the writer structure.
Definition: corsaro_file.c:230
io_t * io
The wandio input file handle.
Definition: corsaro_file.h:98
static libtrace_packet_t * packet
A pointer to a libtrace packet.
Definition: corsaro_main.c:67
corsaro_file_mode_t mode
The requested output format for the file.
Definition: corsaro_file.h:63
void corsaro_file_flush(struct corsaro *corsaro, corsaro_file_t *file)
Force all buffered data for the file to be written out.
Definition: corsaro_file.c:224
void corsaro_file_rclose(corsaro_file_in_t *file)
Closes an corsaro input file and frees the reader structure.
Definition: corsaro_file.c:428
union corsaro_file_in::@3 mode_state
Per-framework state for the file.
struct corsaro_file_in::@3::@5 ms_trace
Trace mode state.
struct corsaro_file corsaro_file_t
An opaque structure defining an corsaro output file.
off_t corsaro_file_vprintf(struct corsaro *corsaro, corsaro_file_t *file, const char *format, va_list args)
Print a string to an corsaro file.
Definition: corsaro_file.c:200
enum corsaro_file_compress corsaro_file_compress_t
Supported compression types (must be kept in sync with wandio)
off_t corsaro_file_rseek(corsaro_file_in_t *file, off_t offset, int whence)
Changes the read pointer offset to the specified value for an corsaro input file. ...
Definition: corsaro_file.c:406
libtrace_out_t * trace
The libtrace object used to create the trace.
Definition: corsaro_file.h:79
off_t corsaro_file_rread(corsaro_file_in_t *file, void *buffer, off_t len)
Reads from an corsaro input file into the provided buffer.
Definition: corsaro_file.c:332
off_t corsaro_file_write(struct corsaro *corsaro, corsaro_file_t *file, const void *buffer, off_t len)
Writes the contents of a buffer using an corsaro output file.
Definition: corsaro_file.c:142
struct corsaro_file_in::@3::@4 ms_wandio
ASCII & Binary mode state.
iow_t * io
The wandio output file handle.
Definition: corsaro_file.h:72
corsaro_file_mode_t mode
The requested/detected input format for the file.
Definition: corsaro_file.h:89
corsaro_file_t * corsaro_file_open(struct corsaro *corsaro, const char *filename, corsaro_file_mode_t mode, corsaro_file_compress_t compress_type, int compress_level, int flags)
Creates a new corsaro file write and opens the provided file for writing.
Definition: corsaro_file.c:59
struct corsaro_file_in corsaro_file_in_t
An opaque structure defining an corsaro input file.
Corsaro output state.
Definition: corsaro_int.h:230
corsaro_file_compress_t corsaro_file_detect_compression(char *filename)
Attempts to detect the type of compression for a file based on the suffix.
Definition: corsaro_file.c:54
corsaro_file_in_t * corsaro_file_ropen(const char *filename)
Creates a new corsaro file reader and opens the provided file for reading.
Definition: corsaro_file.c:256
enum corsaro_file_mode corsaro_file_mode_t
Enum of supported file modes.
struct corsaro_file::@0::@1 ms_wandio
ASCII & Binary mode state.
Header file dealing with the internal corsaro functions.
off_t corsaro_file_rread_packet(corsaro_file_in_t *file, libtrace_packet_t *packet, uint16_t len)
Read a libtrace packet from an corsaro input file.
Definition: corsaro_file.c:356