Skip to Content
[CAIDA - Cooperative Association for Internet Data Analysis logo]
The Cooperative Association for Internet Data Analysis
corsaro_io.h File Reference

Header file dealing with the corsaro file IO. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define CORSARO_IO_HEADER_FIXED_BYTE_LEN   (4+4+1+1+4+2)
 Length of the fixed part of the global corsaro header.
#define CORSARO_IO_INTERVAL_HEADER_BYTE_LEN   (4+4+2+4)
 Length of the interval header.
#define CORSARO_IO_INTERVAL_DATA_HEADER_BYTE_LEN   (4+4+2)
 Length of the data block header.
#define CORSARO_IO_TRAILER_BYTE_LEN   (4+4+8+4+4+4+4)
 Length of the corsaro trailer.
#define CORSARO_IO_PLUGIN_PATTERN   "%P"
 The pattern to replace in the output file name with the name of the plugin.
#define CORSARO_IO_GLOBAL_NAME   "global"
 The name to use for the global 'plugin' file.
#define CORSARO_IO_LOG_NAME   "log"
 The name to use for the log 'plugin' file.

Functions

corsaro_file_tcorsaro_io_prepare_file_full (corsaro_t *corsaro, const char *plugin_name, corsaro_file_mode_t mode, corsaro_file_compress_t compress, int compress_level, int flags)
 Uses the given settings to open an corsaro file for the given plugin.
corsaro_file_tcorsaro_io_prepare_file (corsaro_t *corsaro, const char *plugin_name)
 Uses the current settings to open an corsaro file for the given plugin.
int corsaro_io_validate_template (corsaro_t *corsaro, char *template)
 Validates a output file template for needed features.
off_t corsaro_io_write_header (corsaro_t *corsaro, corsaro_file_t *file, corsaro_header_t *header)
 Write the corsaro headers to the file.
void corsaro_io_print_header (corsaro_plugin_manager_t *plugin_manager, corsaro_header_t *header)
 Write the corsaro headers to stdout.
off_t corsaro_io_write_trailer (corsaro_t *corsaro, corsaro_file_t *file, corsaro_trailer_t *trailer)
 Write the corsaro trailers to the file.
void corsaro_io_print_trailer (corsaro_trailer_t *trailer)
 Write the corsaro trailers to stdout.
off_t corsaro_io_write_interval_start (corsaro_t *corsaro, corsaro_file_t *file, corsaro_interval_t *int_start)
 Write the appropriate interval headers to the file.
void corsaro_io_print_interval_start (corsaro_interval_t *int_start)
 Write the interval headers to stdout.
off_t corsaro_io_write_interval_end (corsaro_t *corsaro, corsaro_file_t *file, corsaro_interval_t *int_end)
 Write the appropriate interval trailers to the file.
void corsaro_io_print_interval_end (corsaro_interval_t *int_end)
 Write the interval trailers to stdout.
off_t corsaro_io_write_plugin_start (corsaro_t *corsaro, corsaro_file_t *file, corsaro_plugin_t *plugin)
 Write the appropriate plugin header to the file.
off_t corsaro_io_write_plugin_end (corsaro_t *corsaro, corsaro_file_t *file, corsaro_plugin_t *plugin)
 Write the appropriate plugin trailer to the file.
off_t corsaro_io_write_record (corsaro_t *corsaro, corsaro_file_t *file, corsaro_in_record_type_t record_type, corsaro_in_record_t *record)
 Write a generic corsaro record to the file.
int corsaro_io_print_record (corsaro_plugin_manager_t *plugin_manager, corsaro_in_record_type_t record_type, corsaro_in_record_t *record)
 Print a generic corsaro record to stdout.
off_t corsaro_io_read_header (corsaro_in_t *corsaro, corsaro_file_in_t *file, corsaro_in_record_type_t *record_type, corsaro_in_record_t *record)
 Read an corsaro header from the file.
off_t corsaro_io_read_trailer (corsaro_in_t *corsaro, corsaro_file_in_t *file, corsaro_in_record_type_t *record_type, corsaro_in_record_t *record)
 Read the corsaro trailers from the file.
off_t corsaro_io_read_interval_start (corsaro_in_t *corsaro, corsaro_file_in_t *file, corsaro_in_record_type_t *record_type, corsaro_in_record_t *record)
 Read the appropriate interval headers from the file.
off_t corsaro_io_read_interval_end (corsaro_in_t *corsaro, corsaro_file_in_t *file, corsaro_in_record_type_t *record_type, corsaro_in_record_t *record)
 Read the appropriate interval trailers from the file.
off_t corsaro_io_read_plugin_start (corsaro_in_t *corsaro, corsaro_file_in_t *file, corsaro_in_record_type_t *record_type, corsaro_in_record_t *record)
 Read the appropriate plugin header from the file.
off_t corsaro_io_read_plugin_end (corsaro_in_t *corsaro, corsaro_file_in_t *file, corsaro_in_record_type_t *record_type, corsaro_in_record_t *record)
 Read the appropriate plugin trailer from the file.
off_t corsaro_io_read_bytes (corsaro_in_t *corsaro, corsaro_in_record_t *record, off_t len)
 Read the given number of bytes into the record.
off_t corsaro_io_read_bytes_offset (corsaro_in_t *corsaro, corsaro_in_record_t *record, off_t offset, off_t len)
 Read the given number of bytes into the record buffer at the given offset.

Detailed Description

Header file dealing with the corsaro file IO.

Author:
Alistair King

Definition in file corsaro_io.h.


Macro Definition Documentation

#define CORSARO_IO_GLOBAL_NAME   "global"

The name to use for the global 'plugin' file.

Definition at line 59 of file corsaro_io.h.

#define CORSARO_IO_HEADER_FIXED_BYTE_LEN   (4+4+1+1+4+2)

Length of the fixed part of the global corsaro header.

Definition at line 45 of file corsaro_io.h.

Referenced by corsaro_io_read_header().

#define CORSARO_IO_INTERVAL_DATA_HEADER_BYTE_LEN   (4+4+2)

Length of the data block header.

Definition at line 51 of file corsaro_io.h.

#define CORSARO_IO_INTERVAL_HEADER_BYTE_LEN   (4+4+2+4)

Length of the interval header.

Definition at line 48 of file corsaro_io.h.

Referenced by corsaro_io_read_interval_end(), and corsaro_io_read_interval_start().

#define CORSARO_IO_LOG_NAME   "log"

The name to use for the log 'plugin' file.

Definition at line 61 of file corsaro_io.h.

Referenced by corsaro_log_init().

#define CORSARO_IO_PLUGIN_PATTERN   "%P"

The pattern to replace in the output file name with the name of the plugin.

Definition at line 57 of file corsaro_io.h.

Referenced by corsaro_io_validate_template().

#define CORSARO_IO_TRAILER_BYTE_LEN   (4+4+8+4+4+4+4)

Length of the corsaro trailer.

Definition at line 54 of file corsaro_io.h.


Function Documentation

corsaro_file_t* corsaro_io_prepare_file ( corsaro_t corsaro,
const char *  plugin_name 
)

Uses the current settings to open an corsaro file for the given plugin.

Parameters:
corsaroThe corsaro object associated with the file
plugin_nameThe name of the plugin (inserted into the template)
Returns:
A pointer to a new corsaro output file, or NULL if an error occurs

Definition at line 635 of file corsaro_io.c.

References corsaro::compress, corsaro::compress_level, and corsaro::output_mode.

corsaro_file_t* corsaro_io_prepare_file_full ( corsaro_t corsaro,
const char *  plugin_name,
corsaro_file_mode_t  mode,
corsaro_file_compress_t  compress,
int  compress_level,
int  flags 
)

Uses the given settings to open an corsaro file for the given plugin.

Parameters:
corsaroThe corsaro object associated with the file
plugin_nameThe name of the plugin (inserted into the template)
modeThe corsaro file mode to use
compressThe corsaro file compression type to use
compress_levelThe corsaro file compression level to use
flagsThe flags to use when opening the file (e.g. O_CREAT)
Returns:
A pointer to a new corsaro output file, or NULL if an error occurs

Definition at line 642 of file corsaro_io.c.

void corsaro_io_print_header ( corsaro_plugin_manager_t plugin_manager,
corsaro_header_t header 
)
void corsaro_io_print_interval_end ( corsaro_interval_t int_end)

Write the interval trailers to stdout.

Parameters:
int_endThe end interval to write out

Definition at line 784 of file corsaro_io.c.

References corsaro_interval::number, and corsaro_interval::time.

void corsaro_io_print_interval_start ( corsaro_interval_t int_start)

Write the interval headers to stdout.

Parameters:
int_startThe start interval to write out

Definition at line 768 of file corsaro_io.c.

References corsaro_interval::number, and corsaro_interval::time.

void corsaro_io_print_trailer ( corsaro_trailer_t trailer)

Write the corsaro trailers to stdout.

Parameters:
trailerThe trailer to write out

Definition at line 744 of file corsaro_io.c.

References corsaro_trailer::first_packet_time, corsaro_trailer::last_packet_time, corsaro_trailer::local_final_time, corsaro_trailer::packet_cnt, and corsaro_trailer::runtime.

off_t corsaro_io_read_bytes ( corsaro_in_t corsaro,
corsaro_in_record_t record,
off_t  len 
)

Read the given number of bytes into the record.

Parameters:
corsaroThe corsaro object to read from
recordThe record to read into
lenThe number of bytes to read
Returns:
The number of bytes to read, 0 if EOF, -1 on error

Definition at line 1244 of file corsaro_io.c.

References corsaro_in_record::buffer, corsaro_in_record::buffer_len, and corsaro_in::file.

off_t corsaro_io_read_bytes_offset ( corsaro_in_t corsaro,
corsaro_in_record_t record,
off_t  offset,
off_t  len 
)

Read the given number of bytes into the record buffer at the given offset.

Parameters:
corsaroThe corsaro object to read from
recordThe record to read into
offsetThe offset into the record buffer to read data to
lenThe number of bytes to read
Returns:
The number of bytes to read, 0 if EOF, -1 on error

This function can be useful to store data that a record points to without actually having to malloc memory. Beware that the record buffer is a fixed size so don't use this for massive objects. Also remember to update the pointer in the record object to this data.

Definition at line 1253 of file corsaro_io.c.

References corsaro_in_record::buffer, corsaro_in_record::buffer_len, and corsaro_in::file.

off_t corsaro_io_read_header ( corsaro_in_t corsaro,
corsaro_file_in_t file,
corsaro_in_record_type_t record_type,
corsaro_in_record_t record 
)

Read an corsaro header from the file.

Parameters:
corsaroThe corsaro object associated with the file
fileThe corsaro input file to read from
Returns:
The amount of data read, or -1 if an error occurs

Definition at line 1033 of file corsaro_io.c.

References corsaro_in_record::buffer, CORSARO_IN_RECORD_TYPE_IO_HEADER, CORSARO_IN_RECORD_TYPE_NULL, and CORSARO_IO_HEADER_FIXED_BYTE_LEN.

off_t corsaro_io_read_interval_end ( corsaro_in_t corsaro,
corsaro_file_in_t file,
corsaro_in_record_type_t record_type,
corsaro_in_record_t record 
)

Read the appropriate interval trailers from the file.

Parameters:
corsaroThe corsaro object associated with the file
fileThe corsaro input file to read from
Returns:
The amount of data read, or -1 if an error occurs

Definition at line 1187 of file corsaro_io.c.

References corsaro_in_record::buffer, CORSARO_IN_RECORD_TYPE_IO_INTERVAL_END, CORSARO_IN_RECORD_TYPE_NULL, and CORSARO_IO_INTERVAL_HEADER_BYTE_LEN.

off_t corsaro_io_read_interval_start ( corsaro_in_t corsaro,
corsaro_file_in_t file,
corsaro_in_record_type_t record_type,
corsaro_in_record_t record 
)

Read the appropriate interval headers from the file.

Parameters:
corsaroThe corsaro object associated with the file
fileThe corsaro input file to read from
Returns:
The amount of data read, or -1 if an error occurs

Definition at line 1159 of file corsaro_io.c.

References corsaro_in_record::buffer, CORSARO_IN_RECORD_TYPE_IO_INTERVAL_START, CORSARO_IN_RECORD_TYPE_NULL, and CORSARO_IO_INTERVAL_HEADER_BYTE_LEN.

off_t corsaro_io_read_plugin_end ( corsaro_in_t corsaro,
corsaro_file_in_t file,
corsaro_in_record_type_t record_type,
corsaro_in_record_t record 
)

Read the appropriate plugin trailer from the file.

Parameters:
corsaroThe corsaro object associated with the file
fileThe corsaro input file to read from
Returns:
The amount of data read, or -1 if an error occurs

Definition at line 1230 of file corsaro_io.c.

References CORSARO_IN_RECORD_TYPE_IO_PLUGIN_END.

off_t corsaro_io_read_plugin_start ( corsaro_in_t corsaro,
corsaro_file_in_t file,
corsaro_in_record_type_t record_type,
corsaro_in_record_t record 
)

Read the appropriate plugin header from the file.

Parameters:
corsaroThe corsaro object associated with the file
fileThe corsaro input file to read from
Returns:
The amount of data read, or -1 if an error occurs

Definition at line 1215 of file corsaro_io.c.

References CORSARO_IN_RECORD_TYPE_IO_PLUGIN_START.

off_t corsaro_io_read_trailer ( corsaro_in_t corsaro,
corsaro_file_in_t file,
corsaro_in_record_type_t record_type,
corsaro_in_record_t record 
)

Read the corsaro trailers from the file.

Parameters:
corsaroThe corsaro object associated with the file
fileThe corsaro input file to read from
Returns:
The amount of data read, or -1 if an error occurs

Definition at line 1133 of file corsaro_io.c.

References corsaro_in_record::buffer, CORSARO_IN_RECORD_TYPE_IO_TRAILER, and CORSARO_IN_RECORD_TYPE_NULL.

int corsaro_io_validate_template ( corsaro_t corsaro,
char *  template 
)

Validates a output file template for needed features.

Parameters:
templateThe file template to be validated
Returns:
1 if the template is valid, 0 if it is invalid

Definition at line 674 of file corsaro_io.c.

References CORSARO_IO_PLUGIN_PATTERN.

off_t corsaro_io_write_header ( corsaro_t corsaro,
corsaro_file_t file,
corsaro_header_t header 
)

Write the corsaro headers to the file.

Parameters:
corsaroThe corsaro object associated with the file
fileThe corsaro output file to write to
headerThe header to write out (NULL to generate one)
Returns:
The amount of data written, or -1 if an error occurs

Definition at line 704 of file corsaro_io.c.

References CORSARO_FILE_MODE, CORSARO_FILE_MODE_ASCII, and CORSARO_FILE_MODE_BINARY.

off_t corsaro_io_write_interval_end ( corsaro_t corsaro,
corsaro_file_t file,
corsaro_interval_t int_end 
)

Write the appropriate interval trailers to the file.

Parameters:
corsaroThe corsaro object associated with the file
fileThe corsaro output file to write to
int_endThe end interval to write out
Returns:
The amount of data written, or -1 if an error occurs

Definition at line 775 of file corsaro_io.c.

References CORSARO_FILE_MODE, CORSARO_FILE_MODE_ASCII, and CORSARO_FILE_MODE_BINARY.

off_t corsaro_io_write_interval_start ( corsaro_t corsaro,
corsaro_file_t file,
corsaro_interval_t int_start 
)

Write the appropriate interval headers to the file.

Parameters:
corsaroThe corsaro object associated with the file
fileThe corsaro output file to write to
int_startThe start interval to write out
Returns:
The amount of data written, or -1 if an error occurs

Definition at line 759 of file corsaro_io.c.

References CORSARO_FILE_MODE, CORSARO_FILE_MODE_ASCII, and CORSARO_FILE_MODE_BINARY.

off_t corsaro_io_write_plugin_end ( corsaro_t corsaro,
corsaro_file_t file,
corsaro_plugin_t plugin 
)

Write the appropriate plugin trailer to the file.

Parameters:
corsaroThe corsaro object associated with the file
fileThe corsaro output file to write to
Returns:
The amount of data written, or -1 if an error occurs

Definition at line 808 of file corsaro_io.c.

References CORSARO_FILE_MODE, CORSARO_FILE_MODE_ASCII, and CORSARO_FILE_MODE_BINARY.

off_t corsaro_io_write_plugin_start ( corsaro_t corsaro,
corsaro_file_t file,
corsaro_plugin_t plugin 
)

Write the appropriate plugin header to the file.

Parameters:
corsaroThe corsaro object associated with the file
fileThe corsaro output file to write to
Returns:
The amount of data written, or -1 if an error occurs

Definition at line 792 of file corsaro_io.c.

References CORSARO_FILE_MODE, CORSARO_FILE_MODE_ASCII, and CORSARO_FILE_MODE_BINARY.

off_t corsaro_io_write_record ( corsaro_t corsaro,
corsaro_file_t file,
corsaro_in_record_type_t  record_type,
corsaro_in_record_t record 
)
off_t corsaro_io_write_trailer ( corsaro_t corsaro,
corsaro_file_t file,
corsaro_trailer_t trailer 
)

Write the corsaro trailers to the file.

Parameters:
corsaroThe corsaro object associated with the file
fileThe corsaro output file to write to
trailerThe trailer to write out (NULL to generate one)
Returns:
The amount of data written, or -1 if an error occurs

Definition at line 735 of file corsaro_io.c.

References CORSARO_FILE_MODE, CORSARO_FILE_MODE_ASCII, and CORSARO_FILE_MODE_BINARY.