41 #include <sys/fcntl.h> 113 memset (&fh, 0,
sizeof (fh));
114 fh.magic = 0xa1b2c3d4;
115 fh.major_version = 2;
116 fh.minor_version = 4;
118 fh.max_packet_size_in_bytes = 1 << 16;
121 if (n !=
sizeof (fh))
173 int fd, need_swap, n;
184 if (read (fd, &fh,
sizeof (fh)) !=
sizeof (fh))
191 if (fh.magic == 0xd4c3b2a1)
194 #define _(t,f) fh.f = clib_byte_swap_##t (fh.f); 199 if (fh.magic != 0xa1b2c3d4)
207 while ((n = read (fd, &ph,
sizeof (ph))) != 0)
213 #define _(t,f) ph.f = clib_byte_swap_##t (ph.f); 218 data =
vec_new (
u8, ph.n_bytes_in_packet);
219 if (read (fd, data, ph.n_packet_bytes_stored_in_file) != ph.n_packet_bytes_stored_in_file)
char * file_name
File name of pcap output.
int file_descriptor
File descriptor for reading/writing.
u32 n_packets_to_capture
Number of packets to capture.
PCAP utility definitions.
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
PCAP main state data structure.
#define vec_new(T, N)
Create new vector of given type and length (unspecified alignment, no header).
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
#define clib_error_return(e, args...)
#define foreach_pcap_packet_header
u32 n_pcap_data_written
Bytes written.
u8 * pcap_data
Vector of pcap data.
#define clib_error_return_unix(e, args...)
clib_error_t * pcap_read(pcap_main_t *pm)
Read PCAP file.
clib_error_t * pcap_close(pcap_main_t *pm)
Close PCAP file.
clib_error_t * pcap_write(pcap_main_t *pm)
Write PCAP file.
#define PCAP_MAIN_INIT_DONE
static word unix_error_is_fatal(word error)
u32 min_packet_bytes
Min/Max Packet bytes.
pcap_packet_type_t packet_type
Packet type.
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
u8 ** packets_read
Packets read from file.
u32 n_packets_captured
Number of packets currently captured.
#define foreach_pcap_file_header