Broccoli: The Bro Client Communications Library | ||
---|---|---|
Prev |
extern int bro_debug_calltrace; extern int bro_debug_messages; void (*BroEventFunc) (BroConn *bc, void *user_data, ...); void (*BroCompactEventFunc) (BroConn *bc, void *user_data, BroEvMeta *meta); BroConn* bro_conn_new (struct in_addr *ip_addr, uint16 port, int flags); BroConn* bro_conn_new_str (const char *hostname, int flags); BroConn* bro_conn_new_socket (int socket, int flags); void bro_conn_set_class (BroConn *bc, const char *classname); const char* bro_conn_get_peer_class (const BroConn *bc); int bro_conn_connect (BroConn *bc); int bro_conn_alive (const BroConn *bc); int bro_conn_delete (BroConn *bc); void bro_conn_adopt_events (BroConn *src, BroConn *dst); int bro_conn_get_fd (BroConn *bc); int bro_conn_process_input (BroConn *bc); void bro_conn_data_set (BroConn *bc, const char *key, void *val); void* bro_conn_data_get (BroConn *bc, const char *key); void* bro_conn_data_del (BroConn *bc, const char *key); BroEvent* bro_event_new (const char *event_name); void bro_event_free (BroEvent *be); int bro_event_add_val (BroEvent *be, int type, const char *type_name, const void *val); int bro_event_set_val (BroEvent *be, int val_num, int type, const char *type_name, const void *val); int bro_event_send (BroConn *bc, BroEvent *be); int bro_event_queue_length (BroConn *bc); int bro_event_queue_flush (BroConn *bc); void bro_event_registry_add (BroConn *bc, const char *event_name, BroEventFunc func, void *user_data); void bro_event_registry_add_compact (BroConn *bc, const char *event_name, BroCompactEventFunc func, void *user_data); void bro_event_registry_remove (BroConn *bc, const char *event_name); void bro_event_registry_request (BroConn *bc); BroBuf* bro_buf_new (void); void bro_buf_free (BroBuf *buf); int bro_buf_append (BroBuf *buf, void *data, int data_len); void bro_buf_consume (BroBuf *buf); void bro_buf_reset (BroBuf *buf); uchar* bro_buf_get (BroBuf *buf); uchar* bro_buf_get_end (BroBuf *buf); uint bro_buf_get_size (BroBuf *buf); uint bro_buf_get_used_size (BroBuf *buf); uchar* bro_buf_ptr_get (BroBuf *buf); uint32 bro_buf_ptr_tell (BroBuf *buf); int bro_buf_ptr_seek (BroBuf *buf, int offset, int whence); int bro_buf_ptr_check (BroBuf *buf, int size); int bro_buf_ptr_read (BroBuf *buf, void *data, int size); int bro_buf_ptr_write (BroBuf *buf, void *data, int size); int bro_conf_get_int (const char *val_name, int *val); int bro_conf_get_dbl (const char *val_name, double *val); const char* bro_conf_get_str (const char *val_name); void bro_conf_set_domain (const char *domain); void bro_string_init (BroString *bs); int bro_string_set (BroString *bs, const char *s); int bro_string_set_data (BroString *bs, const uchar *data, int data_len); const uchar* bro_string_get_data (const BroString *bs); uint32 bro_string_get_length (const BroString *bs); BroString* bro_string_copy (BroString *bs); void bro_string_cleanup (BroString *bs); void bro_string_free (BroString *bs); BroRecord* bro_record_new (void); void bro_record_free (BroRecord *rec); int bro_record_add_val (BroRecord *rec, const char *name, int type, const char *type_name, const void *val); void* bro_record_get_nth_val (BroRecord *rec, int num, int *type); void* bro_record_get_named_val (BroRecord *rec, const char *name, int *type); int bro_record_set_nth_val (BroRecord *rec, int num, int type, const char *type_name, const void *val); int bro_record_set_named_val (BroRecord *rec, const char *name, int type, const char *type_name, const void *val); int (*BroTableCallback) (void *key, void *val, void *user_data); BroTable* bro_table_new (void); void bro_table_free (BroTable *tbl); int bro_table_insert (BroTable *tbl, int key_type, const void *key, int val_type, const void *val); void* bro_table_find (BroTable *tbl, const void *key); int bro_table_get_size (BroTable *tbl); void bro_table_get_types (BroTable *tbl, int *key_type, int *val_type); void bro_table_foreach (BroTable *tbl, BroTableCallback cb, void *user_data); int (*BroSetCallback) (void *val, void *user_data); BroSet* bro_set_new (void); void bro_set_free (BroSet *set); int bro_set_insert (BroSet *set, int type, const void *val); int bro_set_find (BroSet *set, const void *key); int bro_set_get_size (BroSet *set); void bro_set_get_type (BroSet *set, int *type); void bro_set_foreach (BroSet *set, BroSetCallback cb, void *user_data); void bro_conn_set_packet_ctxt (BroConn *bc, int link_type); void bro_conn_get_packet_ctxt (BroConn *bc, int *link_type); BroPacket* bro_packet_new (const struct pcap_pkthdr *hdr, const u_char *data, const char *tag); BroPacket* bro_packet_clone (const BroPacket *packet); void bro_packet_free (BroPacket *packet); int bro_packet_send (BroConn *bc, BroPacket *packet); double bro_util_current_time (void); double bro_util_timeval_to_double (const struct timeval *tv); |
extern int bro_debug_calltrace; |
If you have debugging support built in (i.e., your package was configured with --enable-debugging), you can enable/disable debugging output for call tracing by setting this to 0 (off) or 1 (on). Default is off.
extern int bro_debug_messages; |
If you have debugging support built in (i.e., your package was configured with --enable-debugging), you can enable/disable debugging messages by setting this to 0 (off) or 1 (on). Default is off.
void (*BroEventFunc) (BroConn *bc, void *user_data, ...); |
This is the signature of callbacks for handling received
Bro events, called in the argument-expanded style. For details
see bro_event_registry_add()
Bro connection handle.
user data provided to bro_event_registry_add()
varargs.
void (*BroCompactEventFunc) (BroConn *bc, void *user_data, BroEvMeta *meta); |
This is the signature of callbacks for handling received
Bro events, called in the compact-argument style. For details
see bro_event_registry_add_compact()
Bro connection handle.
user data provided to bro_event_registry_add_compact()
metadata for the event
BroConn* bro_conn_new (struct in_addr *ip_addr, uint16 port, int flags); |
The function creates a new Bro connection handle for communication with Bro through a network. Depending on the flags passed in, the connection and its setup process can be adjusted. If you don't want to pass any flags, use BRO_CFLAG_NONE.
4-byte IP address of Bro to contact, in network byte order.
port of machine at ip_addr to contact, in network byte order.
an or-combination of the BRO_CONN_xxx flags.
pointer to a newly allocated and initialized Bro connection structure. You need this structure for all other calls in order to identify the connection to Bro.
BroConn* bro_conn_new_str (const char *hostname, int flags); |
The function is identical to bro_conn_new()
string describing the host and port to connect to.
an or-combination of the BRO_CONN_xxx flags.
pointer to a newly allocated and initialized Bro connection structure. You need this structure for all other calls in order to identify the connection to Bro.
BroConn* bro_conn_new_socket (int socket, int flags); |
The function is identical to bro_conn_new()
open socket.
an or-combination of the BRO_CONN_xxx flags.
pointer to a newly allocated and initialized Bro connection structure. You need this structure for all other calls in order to identify the connection to Bro.
void bro_conn_set_class (BroConn *bc, const char *classname); |
Broccoli connections can indicate that they belong to a certain class
of connections, which is needed primarily if multiple Bro/Broccoli
instances are running on the same node and connect to a single remote
peer. You can set this class with this function, and you have to do so
before calling bro_connect()
connection handle.
class identifier.
const char* bro_conn_get_peer_class (const BroConn *bc); |
connection handle.
a string containing the connection class indicated by the peer, if any, otherwise NULL.
int bro_conn_connect (BroConn *bc); |
The function attempts to set up and configure a connection to the peer configured when the connection handle was obtained.
connection handle.
TRUE on success, FALSE on failure.
int bro_conn_alive (const BroConn *bc); |
This predicate reports whether the connection handle is currently
usable for sending/receiving data or not, e.g. because the peer
died. The function does not actively check and update the
connection's state, it only reports the value of flags indicating
its status. In particular, this means that when calling
bro_conn_alive()
select()
bro_conn_alive()
bro_conn_process_input()
bro_conn_connect()
Bro connection handle.
TRUE if the connection is alive, FALSE otherwise.
int bro_conn_delete (BroConn *bc); |
This function will terminate the given connection if necessary and release all resources associated with the connection handle.
Bro connection handle
FALSE on error, TRUE otherwise.
void bro_conn_adopt_events (BroConn *src, BroConn *dst); |
The function makes the connection identified by dst use the same event mask as the one identified by src.
Bro connection handle for connection whose event list to adopt.
Bro connection handle for connection whose event list to change.
int bro_conn_get_fd (BroConn *bc); |
If you need to know the file descriptor of the connection
(such as when select()
Bro connection handle.
file descriptor for connection bc, or negative value on error.
int bro_conn_process_input (BroConn *bc); |
The function reads all input sent to the local sensor by the
Bro peering at the connection identified by bc. It is up
to you to find a spot in the application you're instrumenting
to make sure this is called. This function cannot block.
bro_conn_alive()
bro_conn_process_input()
Bro connection handle
TRUE if any input was processed, FALSE otherwise.
void bro_conn_data_set (BroConn *bc, const char *key, void *val); |
The function stores val under name key in the connection handle bc. key is copied internally so you do not need to duplicate it before passing.
Bro connection handle.
name of the data item.
data item.
void* bro_conn_data_get (BroConn *bc, const char *key); |
The function tries to look up the data item with name key and if found, returns it.
Bro connection handle.
name of the data item.
data item if lookup was successful, NULL otherwise.
void* bro_conn_data_del (BroConn *bc, const char *key); |
The function tries to remove the data item with name key.
Bro connection handle.
name of the data item.
the removed data item if it exists, NULL otherwise.
BroEvent* bro_event_new (const char *event_name); |
The function creates a new empty event with the given name and returns it.
name of the Bro event.
new event, or NULL if allocation failed.
void bro_event_free (BroEvent *be); |
The function releases all memory associated with be. Note that you do NOT have to call this after sending an event.
event to release.
int bro_event_add_val (BroEvent *be, int type, const char *type_name, const void *val); |
The function adds the given val to the argument list of event be. The type of val is derived from type, and may be specialized to the type named type_name. If type_name is not desired, use NULL.
val remains the caller's responsibility and is copied internally.
event to add to.
numerical type identifier (a BRO_TYPE_xxx constant).
optional name of specialized type.
value to add to event.
TRUE if the operation was successful, FALSE otherwise.
int bro_event_set_val (BroEvent *be, int val_num, int type, const char *type_name, const void *val); |
The function replaces whatever value is currently stored in the event pointed to by be with the val specified through the type and val arguments. If the event does not currently hold enough values to replace one in position val_num, the function does nothing. If you want to indicate a type specialized from type, use type_name to give its name, otherwise pass NULL for type_name.
event handle.
number of the value to replace, starting at 0.
numerical type identifier (a BRO_TYPE_xxx constant).
optional name of specialized type.
value to put in.
TRUE if successful, FALSE on error.
int bro_event_send (BroConn *bc, BroEvent *be); |
The function tries to send be to the Bro agent connected
through bc. Regardless of the outcome, you do NOT have
to release the event afterwards using bro_event_free()
Bro connection handle
event to send.
TRUE if the event got sent or queued for later transmission,
FALSE on error. There are no automatic repeated send attempts
(to minimize the effect on the code that Broccoli is linked to).
If you have to make sure that everything got sent, you have
to try to empty the queue using bro_event_queue_flush()
bro_event_queue_empty()
int bro_event_queue_length (BroConn *bc); |
Use this function to find out how many events are currently queued on the client side.
Bro connection handle
number of items currently queued.
int bro_event_queue_flush (BroConn *bc); |
The function tries to send as many queued events to the Bro agent as possible.
Bro connection handle
remaining queue length after flush.
void bro_event_registry_add (BroConn *bc, const char *event_name, BroEventFunc func, void *user_data); |
This function registers the callback func to be invoked when events of name event_name arrive on connection bc. user_data is passed along to the callback, which will receive it as the second parameter. You need to ensure that the memory user_data points to is valid during the time the callback might be invoked.
Note that this function only registers the callback in the state
associated with bc. If you use bro_event_registry_add()
bro_conn_connect()
bro_conn_connect()
bro_event_registry_request()
Bro connection handle
Name of events that trigger callback
callback to invoke.
user data passed through to the callback.
void bro_event_registry_add_compact (BroConn *bc, const char *event_name, BroCompactEventFunc func, void *user_data); |
This function registers the callback func to be invoked when events
of name event_name arrive on connection bc. user_data is passed along
to the callback, which will receive it as the second parameter. You
need to ensure that the memory user_data points to is valid during the
time the callback might be invoked. See bro_event_registry_add()
Bro connection handle
Name of events that trigger callback
callback to invoke.
user data passed through to the callback.
void bro_event_registry_remove (BroConn *bc, const char *event_name); |
The function removes all callbacks for event event_name from the event registry for connection bc.
Bro connection handle
event to ignore from now on.
void bro_event_registry_request (BroConn *bc); |
The function requests the events you have previously requested using
bro_event_registry_add()
Bro connection handle
BroBuf* bro_buf_new (void); |
a new buffer object, or NULL on error. Use paired with
bro_buf_free()
void bro_buf_free (BroBuf *buf); |
The function releases all memory held by the buffer pointed
to by buf. Use paired with bro_buf_new()
buffer pointer.
int bro_buf_append (BroBuf *buf, void *data, int data_len); |
The function appends data to the end of the buffer,
enlarging it if necessary to hold the len new bytes.
NOTE: it does not modify the buffer pointer. It only
appends new data where buf_off is currently pointing
and updates it accordingly. If you DO want the buffer
pointer to be updated, have a look at bro_buf_ptr_write()
buffer pointer.
new data to append to buffer.
size of data.
TRUE if successful, FALSE otherwise.
void bro_buf_consume (BroBuf *buf); |
The function removes the buffer contents between the start
of the buffer and the point where the buffer pointer
currently points to. The idea is that you call bro_buf_ptr_read()
bro_buf_consume()
buffer pointer.
void bro_buf_reset (BroBuf *buf); |
The function resets the buffer pointers to the beginning of the currently allocated buffer, i.e., it marks the buffer as empty.
buffer pointer.
uchar* bro_buf_get_end (BroBuf *buf); |
buffer pointer.
a pointer to the first byte in the buffer that is not currently used.
uint bro_buf_get_size (BroBuf *buf); |
buffer pointer.
the number of actual bytes allocated for the buffer.
uint bro_buf_get_used_size (BroBuf *buf); |
buffer pointer.
number of bytes currently used.
uint32 bro_buf_ptr_tell (BroBuf *buf); |
buffer pointer.
current offset of buffer content pointer.
int bro_buf_ptr_seek (BroBuf *buf, int offset, int whence); |
The function adjusts the position of buf's content
pointer. Call semantics are identical to fseek()
buffer pointer.
number of bytes by which to adjust pointer, positive or negative.
location relative to which to adjust.
TRUE if adjustment could be made, FALSE if not (e.g. because the offset requested is not within legal bounds).