P4C
The P4 Compiler
 
Loading...
Searching...
No Matches
pcap_util.h
1/*
2Copyright 2018 VMware, Inc.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17/*
18 * A pcap utility library which provides several functions to read from and
19 * write packets to pcap files.
20 */
21
22#ifndef BACKENDS_EBPF_RUNTIME_EBPF_PCAP_UTIL_H_
23#define BACKENDS_EBPF_RUNTIME_EBPF_PCAP_UTIL_H_
24
25#define PCAP_DONT_INCLUDE_PCAP_BPF_H
26#include <pcap/pcap.h>
27#include <stdint.h> // uint32_t, uint16_t
28
29/* Interfaces are named by integers */
30typedef uint16_t iface_index;
31
32/* A network packet.
33 Contains packet content, timestamp and the interface where
34 the packet has been received/sent.
35 */
36typedef struct {
37 char *data;
38 struct pcap_pkthdr pcap_hdr;
39 iface_index ifindex;
40} pcap_pkt;
41
42struct pcap_list;
43struct pcap_list_array;
44typedef struct pcap_list pcap_list_t;
45typedef struct pcap_list_array pcap_list_array_t;
46
62pcap_list_t *read_pkts_from_pcap(const char *pcap_file_name, iface_index index);
63
73int write_pkts_to_pcap(const char *pcap_file_name, const pcap_list_t *pkt_list);
74
85pcap_list_t *merge_and_delete_lists(pcap_list_array_t *array, pcap_list_t *merged_list);
86
98pcap_list_array_t *split_and_delete_list(pcap_list_t *input_list, pcap_list_array_t *result_arr);
99
112pcap_list_t *append_packet(pcap_list_t *pkt_list, pcap_pkt *pkt);
113
127pcap_list_array_t *insert_list(pcap_list_array_t *pkt_array, pcap_list_t *pkt_list, uint16_t index);
128
134pcap_list_t *allocate_pkt_list();
135
136
142pcap_list_array_t *allocate_pkt_list_array();
143
150uint32_t get_pkt_list_length(pcap_list_t *pkt_list);
151
158uint16_t get_list_array_length(pcap_list_array_t *pkt_list_array);
159
168pcap_pkt *get_packet(pcap_list_t *list, uint32_t index);
169
178pcap_list_t *get_list(pcap_list_array_t *list, uint16_t index);
179
188pcap_pkt *copy_pkt(pcap_pkt *src_pkt);
189
197void delete_list(pcap_list_t *pkt_list);
198
206void delete_array(pcap_list_array_t *pkt_list_array);
207
215void sort_pcap_list(pcap_list_t *pkt_list);
216
225char *generate_pcap_name(const char *pcap_base, int index, const char *suffix);
226
227#endif // BACKENDS_EBPF_RUNTIME_EBPF_PCAP_UTIL_H_
Definition pcap_util.h:36