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
20#ifndef BACKENDS_EBPF_RUNTIME_EBPF_PCAP_UTIL_H_
21#define BACKENDS_EBPF_RUNTIME_EBPF_PCAP_UTIL_H_
22
23#define PCAP_DONT_INCLUDE_PCAP_BPF_H
24#include <pcap/pcap.h>
25#include <stdint.h> // uint32_t, uint16_t
26
28typedef uint16_t iface_index;
29
33typedef struct {
34 char *data;
35 struct pcap_pkthdr pcap_hdr;
36 iface_index ifindex;
37} pcap_pkt;
38
39struct pcap_list;
40struct pcap_list_array;
41typedef struct pcap_list pcap_list_t;
42typedef struct pcap_list_array pcap_list_array_t;
43
57pcap_list_t *read_pkts_from_pcap(const char *pcap_file_name, iface_index index);
58
66int write_pkts_to_pcap(const char *pcap_file_name, const pcap_list_t *pkt_list);
67
76pcap_list_t *merge_and_delete_lists(pcap_list_array_t *array, pcap_list_t *merged_list);
77
87pcap_list_array_t *split_and_delete_list(pcap_list_t *input_list, pcap_list_array_t *result_arr);
88
99pcap_list_t *append_packet(pcap_list_t *pkt_list, pcap_pkt *pkt);
100
112pcap_list_array_t *insert_list(pcap_list_array_t *pkt_array, pcap_list_t *pkt_list, uint16_t index);
113
117pcap_list_t *allocate_pkt_list();
118
122pcap_list_array_t *allocate_pkt_list_array();
123
128uint32_t get_pkt_list_length(pcap_list_t *pkt_list);
129
134uint16_t get_list_array_length(pcap_list_array_t *pkt_list_array);
135
142pcap_pkt *get_packet(pcap_list_t *list, uint32_t index);
143
150pcap_list_t *get_list(pcap_list_array_t *list, uint16_t index);
151
159pcap_pkt *copy_pkt(pcap_pkt *src_pkt);
160
166void delete_list(pcap_list_t *pkt_list);
167
173void delete_array(pcap_list_array_t *pkt_list_array);
174
180void sort_pcap_list(pcap_list_t *pkt_list);
181
188char *generate_pcap_name(const char *pcap_base, int index, const char *suffix);
189
190#endif // BACKENDS_EBPF_RUNTIME_EBPF_PCAP_UTIL_H_
191
Definition pcap_util.h:33