Header file dealing with the low-level file IO. More...

Go to the source code of this file.
Data Structures | |
| struct | corsaro_file |
| An opaque structure defining an corsaro output file. More... | |
| struct | corsaro_file_in |
| An opaque structure defining an corsaro input file. More... | |
Macros | |
| #define | CORSARO_FILE_COMPRESS_LEVEL_DEFAULT 6 |
| The default compression level. | |
| #define | CORSARO_FILE_ZLIB_SUFFIX ".gz" |
| The suffix used to detect gzip output is desired. | |
| #define | CORSARO_FILE_BZ2_SUFFIX ".bz2" |
| The suffix used to detect bzip output is desired. | |
| #define | CORSARO_FILE_MODE(file) (file->mode) |
| Accessor macro for getting the mode of a file. | |
| #define | state_wandio mode_state.ms_wandio |
| Shortcut to the non-trace (wandio) state structure. | |
| #define | wand_io mode_state.ms_wandio.io |
| Shortcut to a non-trace io object. | |
| #define | state_trace mode_state.ms_trace |
| Shortcut to the trace state structure. | |
| #define | trace_io mode_state.ms_trace.trace |
| Shortcut to the libtrace object. | |
Typedefs | |
| typedef struct corsaro_file | corsaro_file_t |
| An opaque structure defining an corsaro output file. | |
| typedef struct corsaro_file_in | corsaro_file_in_t |
| An opaque structure defining an corsaro input file. | |
Functions | |
Corsaro file output API functions | |
These are the functions that should be called by the plugins to open and write to files with the corsaro IO sub-system. | |
| corsaro_file_compress_t | corsaro_file_detect_compression (struct corsaro *corsaro, char *filename) |
| Attempts to detect the type of compression for a file based on the suffix. | |
| 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. | |
| 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. | |
| 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. | |
| 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. | |
| off_t | corsaro_file_printf (struct corsaro *corsaro, corsaro_file_t *file, const char *format,...) |
| Print a string to an corsaro file. | |
| void | corsaro_file_flush (struct corsaro *corsaro, corsaro_file_t *file) |
| Force all buffered data for the file to be written out. | |
| void | corsaro_file_close (struct corsaro *corsaro, corsaro_file_t *file) |
| Closes an corsaro output file and frees the writer structure. | |
Corsaro file input API functions | |
These are the functions that should be called by the plugins to open and read from files with the corsaro IO sub-system.
| |
| corsaro_file_in_t * | corsaro_file_ropen (struct corsaro_in *corsaro, const char *filename) |
| Creates a new corsaro file reader and opens the provided file for reading. | |
| off_t | corsaro_file_rread (struct corsaro_in *corsaro, corsaro_file_in_t *file, void *buffer, off_t len) |
| Reads from an corsaro input file into the provided buffer. | |
| off_t | corsaro_file_rgets (struct corsaro_in *corsaro, corsaro_file_in_t *file, void *buffer, off_t len) |
| Reads a string from an corsaro input file into the provided buffer. | |
| off_t | corsaro_file_rread_packet (struct corsaro_in *corsaro, corsaro_file_in_t *file, libtrace_packet_t *packet, uint16_t len) |
| Read a libtrace packet from an corsaro input file. | |
| off_t | corsaro_file_rpeek (struct corsaro_in *corsaro, 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. | |
| off_t | corsaro_file_rseek (struct corsaro_in *corsaro, corsaro_file_in_t *file, off_t offset, int whence) |
| Changes the read pointer offset to the specified value for an corsaro input file. | |
| off_t | corsaro_file_rtell (struct corsaro_in *corsaro, corsaro_file_in_t *file) |
| Returns the current offset of the read pointer for an corsaro input file. | |
| void | corsaro_file_rclose (struct corsaro_in *corsaro, corsaro_file_in_t *file) |
| Closes an corsaro intput file and frees the reader structure. | |
Header file dealing with the low-level file IO.
Definition in file corsaro_file.h.
| #define CORSARO_FILE_BZ2_SUFFIX ".bz2" |
The suffix used to detect bzip output is desired.
Definition at line 56 of file corsaro_file.h.
Referenced by corsaro_file_detect_compression().
| #define CORSARO_FILE_COMPRESS_LEVEL_DEFAULT 6 |
The default compression level.
Definition at line 50 of file corsaro_file.h.
| #define CORSARO_FILE_MODE | ( | file | ) | (file->mode) |
Accessor macro for getting the mode of a file.
Definition at line 112 of file corsaro_file.h.
Referenced by corsaro_io_write_header(), corsaro_io_write_interval_end(), corsaro_io_write_interval_start(), corsaro_io_write_plugin_end(), corsaro_io_write_plugin_start(), and corsaro_io_write_trailer().
| #define CORSARO_FILE_ZLIB_SUFFIX ".gz" |
The suffix used to detect gzip output is desired.
Definition at line 53 of file corsaro_file.h.
Referenced by corsaro_file_detect_compression().
| #define state_trace mode_state.ms_trace |
Shortcut to the trace state structure.
Definition at line 120 of file corsaro_file.h.
| #define state_wandio mode_state.ms_wandio |
Shortcut to the non-trace (wandio) state structure.
Definition at line 115 of file corsaro_file.h.
| #define trace_io mode_state.ms_trace.trace |
Shortcut to the libtrace object.
Definition at line 122 of file corsaro_file.h.
| #define wand_io mode_state.ms_wandio.io |
Shortcut to a non-trace io object.
Definition at line 117 of file corsaro_file.h.
| typedef struct corsaro_file_in corsaro_file_in_t |
An opaque structure defining an corsaro input file.
| typedef struct corsaro_file corsaro_file_t |
An opaque structure defining an corsaro output file.
| void corsaro_file_close | ( | struct corsaro * | corsaro, |
| corsaro_file_t * | file | ||
| ) |
Closes an corsaro output file and frees the writer structure.
| corsaro | The corsaro object the file is associated with |
| file | The file to close |
Definition at line 259 of file corsaro_file.c.
References CORSARO_FILE_MODE_ASCII, CORSARO_FILE_MODE_BINARY, CORSARO_FILE_MODE_TRACE, and corsaro_file::mode.
| corsaro_file_compress_t corsaro_file_detect_compression | ( | struct corsaro * | corsaro, |
| char * | filename | ||
| ) |
Attempts to detect the type of compression for a file based on the suffix.
| corsaro | The corsaro object the file is associated with |
| filename | The name of the file to check |
Definition at line 52 of file corsaro_file.c.
References CORSARO_FILE_BZ2_SUFFIX, CORSARO_FILE_COMPRESS_BZ2, CORSARO_FILE_COMPRESS_NONE, CORSARO_FILE_COMPRESS_ZLIB, and CORSARO_FILE_ZLIB_SUFFIX.
| void corsaro_file_flush | ( | struct corsaro * | corsaro, |
| corsaro_file_t * | file | ||
| ) |
Force all buffered data for the file to be written out.
| corsaro | The corsaro object the file is associated with |
| file | The file to flush |
Definition at line 253 of file corsaro_file.c.
| 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.
| corsaro | The corsaro object the file is associated with |
| filename | The name of the file to open |
| mode | The corsaro output mode to use when writing |
| compress_type | Compression type |
| compress_level | The compression level to use when writing |
| flags | Flags to apply when opening the file, e.g. O_CREATE |
Definition at line 76 of file corsaro_file.c.
References CORSARO_FILE_MODE_ASCII, CORSARO_FILE_MODE_BINARY, CORSARO_FILE_MODE_TRACE, and corsaro_file::mode.
| off_t corsaro_file_printf | ( | struct corsaro * | corsaro, |
| corsaro_file_t * | file, | ||
| const char * | format, | ||
| ... | |||
| ) |
Print a string to an corsaro file.
| corsaro | The corsaro object the file is associated with |
| file | The file to write to |
| format | The format string to write |
| ... | The arguments to the format string |
The arguments for this function are the same as those for printf(3). See the printf(3) manpage for more details.
Definition at line 243 of file corsaro_file.c.
| void corsaro_file_rclose | ( | struct corsaro_in * | corsaro, |
| corsaro_file_in_t * | file | ||
| ) |
Closes an corsaro intput file and frees the reader structure.
| corsaro | The corsaro object the file is associated with |
| file | The file to close |
Definition at line 503 of file corsaro_file.c.
References CORSARO_FILE_MODE_ASCII, CORSARO_FILE_MODE_BINARY, CORSARO_FILE_MODE_TRACE, and corsaro_file_in::mode.
| off_t corsaro_file_rgets | ( | struct corsaro_in * | corsaro, |
| corsaro_file_in_t * | file, | ||
| void * | buffer, | ||
| off_t | len | ||
| ) |
Reads a string from an corsaro input file into the provided buffer.
| corsaro | The corsaro object the file is associated with |
| file | The file to read from |
| buffer | The buffer to read into |
| len | The size of the buffer |
This function is almost identical to fgets(3), it will read at most one less than len bytes from the file and store them in buffer. Reading stops after an EOF or a newline. If a newline is read, it is stored in the buffer. A null byte will also be stored after the last character in the buffer.
Definition at line 388 of file corsaro_file.c.
References CORSARO_FILE_MODE_ASCII, CORSARO_FILE_MODE_BINARY, and corsaro_file_in::mode.
| corsaro_file_in_t* corsaro_file_ropen | ( | struct corsaro_in * | corsaro, |
| const char * | filename | ||
| ) |
Creates a new corsaro file reader and opens the provided file for reading.
| corsaro | The corsaro object the file is associated with |
| filename | The name of the file to open |
This function will use wandio/libtrace to attempt to detect the compression format used for given file (if any), provided that libtrace was built with the appropriate libraries. It will also attempt to detect the mode that was used to write the file.
Definition at line 295 of file corsaro_file.c.
References CORSARO_FILE_MODE_ASCII, CORSARO_FILE_MODE_BINARY, CORSARO_FILE_MODE_TRACE, and corsaro_file_in::mode.
| off_t corsaro_file_rpeek | ( | struct corsaro_in * | corsaro, |
| 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.
| corsaro | The corsaro object the file is associated with |
| file | The file to read from |
| buffer | The buffer to read into |
| len | The size of the buffer |
Definition at line 471 of file corsaro_file.c.
References CORSARO_FILE_MODE_ASCII, CORSARO_FILE_MODE_BINARY, and corsaro_file_in::mode.
| off_t corsaro_file_rread | ( | struct corsaro_in * | corsaro, |
| corsaro_file_in_t * | file, | ||
| void * | buffer, | ||
| off_t | len | ||
| ) |
Reads from an corsaro input file into the provided buffer.
| corsaro | The corsaro object the file is associated with |
| file | The file to read from |
| buffer | The buffer to read into |
| len | The size of the buffer |
Definition at line 377 of file corsaro_file.c.
References CORSARO_FILE_MODE_ASCII, CORSARO_FILE_MODE_BINARY, and corsaro_file_in::mode.
| off_t corsaro_file_rread_packet | ( | struct corsaro_in * | corsaro, |
| corsaro_file_in_t * | file, | ||
| libtrace_packet_t * | packet, | ||
| uint16_t | len | ||
| ) |
Read a libtrace packet from an corsaro input file.
| corsaro | The corsaro object the file is associated with |
| file | The file to read from |
| packet | The packet to read into |
| len | The size of the packet to be read |
This can be used on Corsaro Binary and Libtrace mode file to retrieve a single packet. If the file is in trace mode, the len parameter is ignored.
Definition at line 432 of file corsaro_file.c.
References CORSARO_FILE_MODE_ASCII, CORSARO_FILE_MODE_BINARY, CORSARO_FILE_MODE_TRACE, and corsaro_file_in::mode.
| off_t corsaro_file_rseek | ( | struct corsaro_in * | corsaro, |
| corsaro_file_in_t * | file, | ||
| off_t | offset, | ||
| int | whence | ||
| ) |
Changes the read pointer offset to the specified value for an corsaro input file.
| corsaro | The corsaro object the file is associated with |
| file | The file to adjust the read pointer for |
| offset | The new offset for the read pointer |
| whence | Indicates where to set the read pointer from. Can be one of SEEK_SET, SEEK_CUR or SEEK_END. |
The arguments for this function are the same as those for lseek(2). See the lseek(2) manpage for more details.
Definition at line 482 of file corsaro_file.c.
References CORSARO_FILE_MODE_ASCII, CORSARO_FILE_MODE_BINARY, and corsaro_file_in::mode.
| off_t corsaro_file_rtell | ( | struct corsaro_in * | corsaro, |
| corsaro_file_in_t * | file | ||
| ) |
Returns the current offset of the read pointer for an corsaro input file.
| corsaro | The corsaro object the file is associated with |
| file | The file to get the read offset for |
Definition at line 493 of file corsaro_file.c.
References CORSARO_FILE_MODE_ASCII, CORSARO_FILE_MODE_BINARY, and corsaro_file_in::mode.
| 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.
| corsaro | The corsaro object the file is associated with |
| file | The file to write to |
| format | The format string to write |
| args | The arguments to the format string |
The arguments for this function are the same as those for vprintf(3). See the vprintf(3) manpage for more details.
Definition at line 231 of file corsaro_file.c.
References CORSARO_FILE_MODE_ASCII, CORSARO_FILE_MODE_BINARY, and corsaro_file::mode.
| 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.
| corsaro | The corsaro object the file is associated with |
| file | The file to write the data to |
| buffer | The buffer to write out |
| len | The amount of writable data in the buffer |
Definition at line 159 of file corsaro_file.c.
References CORSARO_FILE_MODE_ASCII, CORSARO_FILE_MODE_BINARY, and corsaro_file::mode.
| 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.
| corsaro | The corsaro object the file is associated with |
| file | The file to write the packet to |
| packet | The packet to written |
This can be used on Corsaro Binary and Libtrace mode file to write a single packet.
Definition at line 170 of file corsaro_file.c.
References CORSARO_FILE_MODE_ASCII, CORSARO_FILE_MODE_BINARY, CORSARO_FILE_MODE_TRACE, and corsaro_file::mode.