44 #include "corsaro_pcap.h"
55 #define CORSARO_PCAP_MAGIC 0x50434150
58 #define PLUGIN_NAME "pcap"
63 #define OUTFILE_POINTERS 2
75 struct corsaro_pcap_state_t {
85 #define STATE(corsaro) \
86 (CORSARO_PLUGIN_STATE(corsaro, pcap, CORSARO_PLUGIN_ID_PCAP))
88 #define PLUGIN(corsaro) \
89 (CORSARO_PLUGIN_PLUGIN(corsaro, CORSARO_PLUGIN_ID_PCAP))
116 struct corsaro_pcap_state_t *state;
118 assert(plugin != NULL);
120 if((state =
malloc_zero(
sizeof(
struct corsaro_pcap_state_t))) == NULL)
123 "could not malloc corsaro_pcap_state_t");
153 struct corsaro_pcap_state_t *state =
STATE(corsaro);
160 if(state->outfile_p[i] != NULL)
163 state->outfile_p[i] = NULL;
166 state->outfile = NULL;
180 corsaro_log_in(__func__, corsaro,
"pcap files are simply trace files."
181 " use libtrace instead of corsaro");
197 if(
STATE(corsaro)->outfile == NULL)
201 STATE(corsaro)->outfile_p[
STATE(corsaro)->outfile_n] =
210 corsaro_log(__func__, corsaro,
"could not open %s output file",
215 outfile_p[
STATE(corsaro)->outfile_n];
223 struct corsaro_pcap_state_t *state =
STATE(corsaro);
229 assert(state->outfile != NULL);
232 state->outfile_n = (state->outfile_n+1) %
235 if(state->outfile_p[state->outfile_n] != NULL)
239 state->outfile_p[state->outfile_n]);
240 state->outfile_p[state->outfile_n] = NULL;
243 state->outfile = NULL;
255 corsaro_log(__func__, corsaro,
"could not write packet");
Structure representing the start or end of an interval.
An opaque structure defining an corsaro input file.
#define PLUGIN_NAME
The name of this plugin.
Header file dealing with the corsaro plugin manager.
int compress_level
The compression level (ignored if not compressing)
Header file dealing with the corsaro logging sub-system.
int corsaro_pcap_close_input(corsaro_in_t *corsaro)
Implements the close_input function of the plugin API.
An opaque structure defining an corsaro output file.
int corsaro_pcap_process_packet(corsaro_t *corsaro, corsaro_packet_t *packet)
Implements the process_packet function of the plugin API.
A reusable opaque structure for corsaro to read an input record into.
#define LT_PKT(corsaro_packet)
Convenience macro to get to the libtrace packet inside an corsaro packet.
corsaro_file_t * corsaro_io_prepare_file_full(corsaro_t *corsaro, const char *plugin_name, corsaro_interval_t *interval, 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.
off_t corsaro_pcap_read_record(struct corsaro_in *corsaro, corsaro_in_record_type_t *record_type, corsaro_in_record_t *record)
Implements the read_record function of the plugin API.
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.
void corsaro_file_close(struct corsaro *corsaro, corsaro_file_t *file)
Closes an corsaro output file and frees the writer structure.
int corsaro_pcap_end_interval(corsaro_t *corsaro, corsaro_interval_t *int_end)
Implements the end_interval function of the plugin API.
int corsaro_pcap_probe_magic(corsaro_in_t *corsaro, corsaro_file_in_t *file)
Implements the probe_magic function of the plugin API.
int corsaro_pcap_start_interval(corsaro_t *corsaro, corsaro_interval_t *int_start)
Implements the start_interval function of the plugin API.
static libtrace_packet_t * packet
A pointer to a libtrace packet.
void corsaro_plugin_free_state(corsaro_plugin_manager_t *manager, corsaro_plugin_t *plugin)
Free the state for a plugin.
#define CORSARO_PCAP_MAGIC
The magic number for this plugin - "PCAP".
Header file for common utility functions.
A lightweight wrapper around a libtrace packet.
corsaro_plugin_manager_t * plugin_manager
A pointer to the corsaro plugin manager state.
#define CORSARO_PLUGIN_GENERATE_PTRS(plugin)
Convenience macro that defines all the function pointers for the corsaro plugin API.
corsaro_in_record_type
Corsaro input record types.
void corsaro_plugin_register_state(corsaro_plugin_manager_t *manager, corsaro_plugin_t *plugin, void *state)
Register the state for a plugin.
int corsaro_pcap_close_output(corsaro_t *corsaro)
Implements the close_output function of the plugin API.
#define CORSARO_PLUGIN_GENERATE_TAIL
Convenience macro that defines all the 'remaining' blank fields in a corsaro plugin object...
void * malloc_zero(const size_t size)
Allocate memory and set it to zero.
Header file dealing with the low-level file IO.
static corsaro_in_record_t * record
A pointer to a corsaro record.
#define STATE(corsaro)
Extends the generic plugin state convenience macro in corsaro_plugin.h.
void corsaro_log_in(const char *func, corsaro_in_t *corsaro, const char *format,...)
Write a formatted string to the logfile associated with an corsaro input object.
int corsaro_is_rotate_interval(corsaro_t *corsaro)
Convenience function to determine if the output files should be rotated.
Pseudo IO mode which allows trace files to be written.
int corsaro_pcap_init_output(corsaro_t *corsaro)
Implements the init_output function of the plugin API.
#define OUTFILE_POINTERS
The number of output file pointers to support non-blocking close at the end of an interval...
int corsaro_pcap_probe_filename(const char *fname)
Implements the probe_filename function of the plugin API.
off_t corsaro_pcap_read_global_data_record(struct corsaro_in *corsaro, enum corsaro_in_record_type *record_type, struct corsaro_in_record *record)
Implements the read_global_data_record function of the plugin API.
corsaro_file_compress_t compress
The compression type (based on the file name)
Header file dealing with the corsaro file IO.
int corsaro_pcap_init_input(corsaro_in_t *corsaro)
Implements the init_output function of the plugin API.
corsaro_plugin_t * corsaro_pcap_alloc(corsaro_t *corsaro)
Implements the alloc function of the plugin API.
void corsaro_log(const char *func, corsaro_t *corsaro, const char *format,...)
Write a formatted string to the logfile associated with an corsaro object.
static corsaro_plugin_t corsaro_pcap_plugin
Common plugin information across all instances.
enum corsaro_in_record_type corsaro_in_record_type_t
Corsaro input record types.
Pass-through PCAP plugin.
An corsaro packet processing plugin.
#define PLUGIN(corsaro)
Extends the generic plugin plugin convenience macro in corsaro_plugin.h.
Header file dealing with the internal corsaro functions.