Skip to Content
[CAIDA - Cooperative Association for Internet Data Analysis logo]
The Cooperative Association for 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 
34 #include "libtrace.h"
35 #include "wandio.h"
36 
50 #define CORSARO_FILE_COMPRESS_LEVEL_DEFAULT 6
51 
53 #define CORSARO_FILE_ZLIB_SUFFIX ".gz"
54 
56 #define CORSARO_FILE_BZ2_SUFFIX ".bz2"
57 
59 typedef struct corsaro_file
60 {
63 
65  union
66  {
68  struct
69  {
71  iow_t *io;
72  } ms_wandio;
73 
75  struct
76  {
78  libtrace_out_t *trace;
79  } ms_trace;
80  } mode_state;
81 
83 
85 typedef struct corsaro_file_in
86 {
89 
91  union
92  {
94  struct
95  {
97  io_t *io;
98  } ms_wandio;
99 
101  struct
102  {
104  libtrace_t *trace;
105  } ms_trace;
106  } mode_state;
107 
109 
111 /* this is what the 'public' should use to retrieve the mode */
112 #define CORSARO_FILE_MODE(file) (file->mode)
113 
115 #define state_wandio mode_state.ms_wandio
116 
117 #define wand_io mode_state.ms_wandio.io
118 
120 #define state_trace mode_state.ms_trace
121 
122 #define trace_io mode_state.ms_trace.trace
123 
138 corsaro_file_compress_t corsaro_file_detect_compression(struct corsaro *corsaro,
139  char *filename);
140 
151 corsaro_file_t *corsaro_file_open(struct corsaro *corsaro,
152  const char *filename,
153  corsaro_file_mode_t mode,
154  corsaro_file_compress_t compress_type,
155  int compress_level,
156  int flags);
157 
166 off_t corsaro_file_write(struct corsaro *corsaro,
167  corsaro_file_t *file, const void *buffer, off_t len);
168 
169 
180 off_t corsaro_file_write_packet(struct corsaro *corsaro,
181  corsaro_file_t *file, libtrace_packet_t *packet);
182 
194 off_t corsaro_file_vprintf(struct corsaro *corsaro, corsaro_file_t *file,
195  const char *format, va_list args);
196 
208 off_t corsaro_file_printf(struct corsaro *corsaro, corsaro_file_t *file,
209  const char *format, ...);
210 
216 void corsaro_file_flush(struct corsaro *corsaro, corsaro_file_t *file);
217 
223 void corsaro_file_close(struct corsaro *corsaro, corsaro_file_t *file);
224 
247 corsaro_file_in_t *corsaro_file_ropen(struct corsaro_in *corsaro, const char *filename);
248 
257 off_t corsaro_file_rread(struct corsaro_in *corsaro,
258  corsaro_file_in_t *file, void *buffer, off_t len);
259 
273 off_t corsaro_file_rgets(struct corsaro_in *corsaro,
274  corsaro_file_in_t *file, void *buffer, off_t len);
275 
287 off_t corsaro_file_rread_packet(struct corsaro_in *corsaro,
288  corsaro_file_in_t *file,
289  libtrace_packet_t *packet,
290  uint16_t len);
291 
301 off_t corsaro_file_rpeek(struct corsaro_in *corsaro,
302  corsaro_file_in_t *file, void *buffer, off_t len);
303 
317 off_t corsaro_file_rseek(struct corsaro_in *corsaro,
318  corsaro_file_in_t *file, off_t offset, int whence);
319 
326 off_t corsaro_file_rtell(struct corsaro_in *corsaro, corsaro_file_in_t *file);
327 
333 void corsaro_file_rclose(struct corsaro_in *corsaro, corsaro_file_in_t *file);
334 
337 #endif /* __CORSARO_FILE_H */