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))
179 int fd, need_swap, n;
190 if (read (fd, &fh,
sizeof (fh)) !=
sizeof (fh))
198 if (fh.magic == 0xd4c3b2a1)
201 #define _(t,f) fh.f = clib_byte_swap_##t (fh.f); 206 if (fh.magic != 0xa1b2c3d4)
214 while ((n = read (fd, &ph,
sizeof (ph))) != 0)
223 #define _(t,f) ph.f = clib_byte_swap_##t (ph.f); 228 data =
vec_new (
u8, ph.n_bytes_in_packet);
229 if (read (fd, data, ph.n_packet_bytes_stored_in_file) !=
230 ph.n_packet_bytes_stored_in_file)
246 timestamp_sec = ph.time_in_sec;
247 timestamp_usec = ph.time_in_usec;
248 timestamp = ((
u64) timestamp_sec) * 1000000 + (
u64) timestamp_usec;
char * file_name
File name of pcap output.
__clib_export clib_error_t * pcap_write(pcap_main_t *pm)
Write PCAP file.
int file_descriptor
File descriptor for reading/writing.
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.
__clib_export clib_error_t * pcap_read(pcap_main_t *pm)
Read PCAP file.
pool_header_t * ph(void *p)
GDB callable function: ph - call pool_header - get pool header.
static void clib_spinlock_init(clib_spinlock_t *p)
__clib_export clib_error_t * pcap_close(pcap_main_t *pm)
Close PCAP file.
u8 * pcap_data
Vector of pcap data.
#define clib_error_return_unix(e, args...)
#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