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>
Go to the source code of this file.
|
typedef void(* | capture_callback_fn) (const void *ctx, const void *pcap_ctx, char *ltype, struct pcap_pkthdr *header, uint8_t *packet) |
|
|
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...
|
|
File containing the definition of the pcap service utilities.
- Author
- Alexandru Mereacre
- Date
- 2021
- Copyright
- SPDX-FileCopyrightText: © 2021 NQMCyber Ltd and edgesec contributors SPDX-License-Identifier: LGPL-3.0-or-later
◆ capture_callback_fn
typedef void(* capture_callback_fn) (const void *ctx, const void *pcap_ctx, char *ltype, struct pcap_pkthdr *header, uint8_t *packet) |
◆ capture_pcap_packet()
Captures a pcap packet.
- Parameters
-
ctx | The pcap context structure |
- Returns
- int 0 on success, -1 otherwise
◆ capture_pcap_start()
Starts the blocking pcap loop.
- Parameters
-
- Returns
- int 0 on success, -1 on error, -2 if the loop terminated
◆ capture_pcap_stop()
Stops the blocking pcap loop.
- Parameters
-
◆ close_pcap()
Closes the pcap service.
- Parameters
-
◆ 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
-
ctx | The pcap context |
file_path | The file path to save the packet |
header | The packet header |
packet | The 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
-
◆ get_pcap_datalink()
Get the pcap config datalink value.
- Parameters
-
- 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
-
ctx | The pcap context |
packet | The packet data |
size | The 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
-
interface | The capture interface |
immediate | The immediate mode flag |
promiscuous | The promiscuous mode flag |
timeout | The timeout (in milliseconds) |
filter | The capture filter string |
nonblock | Sets the capture to nonblocking mode |
pcap_fn | The pcap capture callback |
fn_ctx | The context for callback function |
pctx | The returned pcap context |
- Returns
- 0 on success, -1 on failure