EDGESEC  0.1.0-alpha.0+sha.ca29a8277b72f80785649ea9ef9cd7edf642d939
Secure router - reference implementation
Data Structures | Typedefs | Functions
pcap_service.h File Reference

File containing the definition of the pcap service utilities. More...

#include <stdbool.h>
#include <stdint.h>
#include <net/if.h>
#include <pcap.h>
#include <sys/types.h>
#include <utarray.h>
Include dependency graph for pcap_service.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  pcap_context
 Pcap context structure definition. More...
 

Typedefs

typedef void(* capture_callback_fn) (const void *ctx, const void *pcap_ctx, char *ltype, struct pcap_pkthdr *header, uint8_t *packet)
 

Functions

int capture_pcap_start (struct pcap_context *ctx)
 Starts the blocking pcap loop. More...
 
void capture_pcap_stop (struct pcap_context *ctx)
 Stops the blocking pcap loop. More...
 
int get_pcap_datalink (struct pcap_context *ctx)
 Get the pcap config datalink value. More...
 
int run_pcap (char *interface, bool immediate, bool promiscuous, int timeout, char *filter, bool nonblock, capture_callback_fn pcap_fn, void *fn_ctx, struct pcap_context **pctx)
 Executes the libpcap service. More...
 
int capture_pcap_packet (struct pcap_context *ctx)
 Captures a pcap packet. More...
 
int dump_file_pcap (struct pcap_context *ctx, char *file_path, struct pcap_pkthdr *header, uint8_t *packet)
 Saves a packet packet into file. More...
 
int inject_pcap (struct pcap_context *ctx, uint8_t *packet, size_t size)
 Injects a packets. More...
 
int get_pcap_stats (const struct pcap_context *ctx, struct pcap_stat *ps)
 Return pcap capture statistics. More...
 
void close_pcap (struct pcap_context *ctx)
 Closes the pcap service. More...
 
void free_pcap_list (UT_array *ctx_list)
 Frees a pcap list. More...
 
UT_array * create_pcap_list (void)
 Creates a pcap list. More...
 

Detailed Description

File containing the definition of the pcap service utilities.

Author
Alexandru Mereacre
Date
2021

Typedef Documentation

◆ capture_callback_fn

typedef void(* capture_callback_fn) (const void *ctx, const void *pcap_ctx, char *ltype, struct pcap_pkthdr *header, uint8_t *packet)

Function Documentation

◆ capture_pcap_packet()

int capture_pcap_packet ( struct pcap_context ctx)

Captures a pcap packet.

Parameters
ctxThe pcap context structure
Returns
int 0 on success, -1 otherwise

◆ capture_pcap_start()

int capture_pcap_start ( struct pcap_context ctx)

Starts the blocking pcap loop.

Parameters
ctxThe pcap context
Returns
int 0 on success, -1 on error, -2 if the loop terminated

◆ capture_pcap_stop()

void capture_pcap_stop ( struct pcap_context ctx)

Stops the blocking pcap loop.

Parameters
ctxThe pcap context

◆ close_pcap()

void close_pcap ( struct pcap_context ctx)

Closes the pcap service.

Parameters
ctxThe pcap context

◆ create_pcap_list()

UT_array* create_pcap_list ( void  )

Creates a pcap list.

Returns
UT_array* The pcap list, NULL on failure

◆ dump_file_pcap()

int dump_file_pcap ( struct pcap_context ctx,
char *  file_path,
struct pcap_pkthdr *  header,
uint8_t *  packet 
)

Saves a packet packet into file.

Parameters
ctxThe pcap context
file_pathThe file path to save the packet
headerThe packet header
packetThe packet data
Returns
int 0 on success, -1 on failure

◆ free_pcap_list()

void free_pcap_list ( UT_array *  ctx_list)

Frees a pcap list.

Parameters
ctx_listThe pcap list

◆ get_pcap_datalink()

int get_pcap_datalink ( struct pcap_context ctx)

Get the pcap config datalink value.

Parameters
ctxThe pcap context
Returns
int the config value

◆ get_pcap_stats()

int get_pcap_stats ( const struct pcap_context ctx,
struct pcap_stat *  ps 
)

Return pcap capture statistics.

Parameters
ctx[in]The pcap context
ps[out]The pcap_stat structure
Returns
0 on success, -1 on failure

◆ inject_pcap()

int inject_pcap ( struct pcap_context ctx,
uint8_t *  packet,
size_t  size 
)

Injects a packets.

Parameters
ctxThe pcap context
packetThe packet data
sizeThe packet size
Returns
int number of bytes injected on success, -1 on failure

◆ run_pcap()

int run_pcap ( char *  interface,
bool  immediate,
bool  promiscuous,
int  timeout,
char *  filter,
bool  nonblock,
capture_callback_fn  pcap_fn,
void *  fn_ctx,
struct pcap_context **  pctx 
)

Executes the libpcap service.

Parameters
interfaceThe capture interface
immediateThe immediate mode flag
promiscuousThe promiscuous mode flag
timeoutThe timeout (in milliseconds)
filterThe capture filter string
nonblockSets the capture to nonblocking mode
pcap_fnThe pcap capture callback
fn_ctxThe context for callback function
pctxThe returned pcap context
Returns
0 on success, -1 on failure