EDGESEC  0.1.0-alpha.0+sha.ca29a8277b72f80785649ea9ef9cd7edf642d939
Secure router - reference implementation
pcap_service.h
Go to the documentation of this file.
1 
11 #ifndef PCAP_SERVICE_H
12 #define PCAP_SERVICE_H
13 
14 #include <stdbool.h>
15 #include <stdint.h>
16 #include <net/if.h>
17 #include <pcap.h>
18 #include <sys/types.h>
19 #include <utarray.h>
20 
21 typedef void (*capture_callback_fn)(const void *ctx, const void *pcap_ctx,
22  char *ltype, struct pcap_pkthdr *header,
23  uint8_t *packet);
24 
29 struct pcap_context {
30  int pcap_fd;
31  pcap_t *pd;
32  char ifname[IF_NAMESIZE];
34  void *fn_ctx;
35 };
36 
43 int capture_pcap_start(struct pcap_context *ctx);
44 
50 void capture_pcap_stop(struct pcap_context *ctx);
51 
58 int get_pcap_datalink(struct pcap_context *ctx);
59 
74 int run_pcap(char *interface, bool immediate, bool promiscuous, int timeout,
75  char *filter, bool nonblock, capture_callback_fn pcap_fn,
76  void *fn_ctx, struct pcap_context **pctx);
77 
84 int capture_pcap_packet(struct pcap_context *ctx);
85 
95 int dump_file_pcap(struct pcap_context *ctx, char *file_path,
96  struct pcap_pkthdr *header, uint8_t *packet);
97 
106 int inject_pcap(struct pcap_context *ctx, uint8_t *packet, size_t size);
107 
115 int get_pcap_stats(const struct pcap_context *ctx, struct pcap_stat *ps);
116 
122 void close_pcap(struct pcap_context *ctx);
123 
129 void free_pcap_list(UT_array *ctx_list);
130 
136 UT_array *create_pcap_list(void);
137 #endif
int get_pcap_stats(const struct pcap_context *ctx, struct pcap_stat *ps)
Return pcap capture statistics.
Definition: pcap_service.c:229
int dump_file_pcap(struct pcap_context *ctx, char *file_path, struct pcap_pkthdr *header, uint8_t *packet)
Saves a packet packet into file.
Definition: pcap_service.c:217
int inject_pcap(struct pcap_context *ctx, uint8_t *packet, size_t size)
Injects a packets.
Definition: pcap_service.c:238
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.
Definition: pcap_service.c:105
int get_pcap_datalink(struct pcap_context *ctx)
Get the pcap config datalink value.
Definition: pcap_service.c:96
void free_pcap_list(UT_array *ctx_list)
Frees a pcap list.
Definition: pcap_service.c:249
void close_pcap(struct pcap_context *ctx)
Closes the pcap service.
Definition: pcap_service.c:72
void capture_pcap_stop(struct pcap_context *ctx)
Stops the blocking pcap loop.
Definition: pcap_service.c:90
UT_array * create_pcap_list(void)
Creates a pcap list.
Definition: pcap_service.c:263
int capture_pcap_packet(struct pcap_context *ctx)
Captures a pcap packet.
Definition: pcap_service.c:68
int capture_pcap_start(struct pcap_context *ctx)
Starts the blocking pcap loop.
Definition: pcap_service.c:81
void(* capture_callback_fn)(const void *ctx, const void *pcap_ctx, char *ltype, struct pcap_pkthdr *header, uint8_t *packet)
Definition: pcap_service.h:21
Pcap context structure definition.
Definition: pcap_service.h:29
int pcap_fd
Definition: pcap_service.h:30
pcap_t * pd
Definition: pcap_service.h:31
char ifname[IF_NAMESIZE]
Definition: pcap_service.h:32
void * fn_ctx
Definition: pcap_service.h:34
capture_callback_fn pcap_fn
Definition: pcap_service.h:33