16 #include <sys/fcntl.h> 72 if (truncate (pm->
file_name, actual_size) < 0)
100 fd = open (pm->
file_name, O_CREAT | O_TRUNC | O_RDWR, 0664);
115 if (lseek (fd, pm->
max_file_size - 1, SEEK_SET) == (off_t) - 1)
122 if (write (fd, &zero, 1) != 1)
130 PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
148 fh->magic = 0xa1b2c3d4;
149 fh->major_version = 2;
150 fh->minor_version = 4;
152 fh->max_packet_size_in_bytes = 1 << 16;
171 u64 packets_read = 0;
172 u32 min_packet_bytes = ~0;
173 u32 max_packet_bytes = 0;
182 if (fstat (fd, &statb) < 0)
188 if ((statb.st_mode & S_IFREG) == 0)
195 if (statb.st_size < sizeof (*fh) +
sizeof (*ph))
202 pm->
file_baseva = mmap (0, statb.st_size, PROT_READ, MAP_SHARED, fd, 0);
213 if (fh->magic != 0xa1b2c3d4)
224 if (ph->n_packet_bytes_stored_in_file == 0)
229 ph->n_packet_bytes_stored_in_file <
230 min_packet_bytes ? ph->n_packet_bytes_stored_in_file :
233 ph->n_packet_bytes_stored_in_file >
234 max_packet_bytes ? ph->n_packet_bytes_stored_in_file :
238 (((
u8 *) (ph)) +
sizeof (*ph) + ph->n_packet_bytes_stored_in_file);
u32 min_packet_bytes
Min/Max Packet bytes.
#define MPCAP_FLAG_INIT_DONE
u8 * file_baseva
Base address.
u32 n_mpcap_data_written
Bytes written.
#define MPCAP_FLAG_WRITE_ENABLE
#define clib_error_return(e, args...)
static void clib_spinlock_init(clib_spinlock_t *p)
static const __m128i zero
uword clib_mem_get_page_size(void)
#define clib_error_return_unix(e, args...)
char * file_name
File name of mpcap output.
MPCAP main state data structure.
clib_error_t * mpcap_map(mpcap_main_t *pm)
mmap a mapped pcap file, e.g.
#define MPCAP_FLAG_THREAD_SAFE
MPCAP utility definitions.
u32 n_packets_captured
Number of packets currently captured.
clib_spinlock_t lock
spinlock, initialized if flagged MPCAP_FLAG_THREAD_SAFE
mpcap_file_header_t * file_header
Pointer to file header in svm, for ease of updating.
mpcap_packet_type_t packet_type
Packet type.
u64 packets_read
Packets in mapped mpcap file.
#define MPCAP_DEFAULT_FILE_SIZE
#define clib_unix_warning(format, args...)
u64 max_file_size
Maximum file size.
clib_error_t * mpcap_init(mpcap_main_t *pm)
Initialize a mapped pcap file.
u8 * current_va
current memory address
clib_error_t * mpcap_close(mpcap_main_t *pm)
Close a mapped pcap file.