40 #include <sys/fcntl.h> 102 open (pm->
file_name, O_CREAT | O_TRUNC | O_WRONLY, 0664);
117 fh.magic = 0xa1b2c3d4;
118 fh.major_version = 2;
119 fh.minor_version = 4;
121 fh.max_packet_size_in_bytes = 1 << 16;
124 if (n !=
sizeof (fh))
182 int fd, need_swap, n;
193 if (read (fd, &fh,
sizeof (fh)) !=
sizeof (fh))
201 if (fh.magic == 0xd4c3b2a1)
204 #define _(t,f) fh.f = clib_byte_swap_##t (fh.f); 209 if (fh.magic != 0xa1b2c3d4)
217 while ((n = read (fd, &ph,
sizeof (ph))) != 0)
226 #define _(t,f) ph.f = clib_byte_swap_##t (ph.f); 231 data =
vec_new (
u8, ph.n_bytes_in_packet);
232 if (read (fd, data, ph.n_packet_bytes_stored_in_file) !=
233 ph.n_packet_bytes_stored_in_file)
249 timestamp_sec = ph.time_in_sec;
250 timestamp_usec = ph.time_in_usec;
251 timestamp = ((
u64) timestamp_sec) * 1000000 + (
u64) timestamp_usec;
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.
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
#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.
clib_spinlock_t lock
spinlock to protect e.g.
#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.
static void clib_spinlock_init(clib_spinlock_t *p)
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.
u64 * timestamps
Timestamps.
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