src/dpdk/drivers/net/pcap/rte_eth_pcap.c
static uint16_t
eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
{
	unsigned int i;
	struct rte_mbuf *mbuf;
	struct pmd_process_private *pp;
	struct pcap_tx_queue *dumper_q = queue;
	uint16_t num_tx = 0;
	uint32_t tx_bytes = 0;
	struct pcap_pkthdr header;
	pcap_dumper_t *dumper;
	unsigned char temp_data[RTE_ETH_PCAP_SNAPLEN];
	size_t len, caplen;

	pp = rte_eth_devices[dumper_q->port_id].process_private;
	dumper = pp->tx_dumper[dumper_q->queue_id];

	if (dumper == NULL || nb_pkts == 0)
		return 0;

	/* writes the nb_pkts packets to the previously opened pcap file
	 * dumper */
	for (i = 0; i < nb_pkts; i++) {
		mbuf = bufs[i];
		len = caplen = rte_pktmbuf_pkt_len(mbuf);
		if (unlikely(!rte_pktmbuf_is_contiguous(mbuf) &&
				len > sizeof(temp_data))) {
			caplen = sizeof(temp_data);
		}

		calculate_timestamp(&header.ts);
		header.len = len;
		header.caplen = caplen;
		/* rte_pktmbuf_read() returns a pointer to the data directly
		 * in the mbuf (when the mbuf is contiguous) or, otherwise,
		 * a pointer to temp_data after copying into it.
		 */
		pcap_dump((u_char *)dumper, &header,
			rte_pktmbuf_read(mbuf, 0, caplen, temp_data));

		num_tx++;
		tx_bytes += caplen;
		rte_pktmbuf_free(mbuf);
	}

	/*
	 * Since there's no place to hook a callback when the forwarding
	 * process stops and to make sure the pcap file is actually written,
	 * we flush the pcap dumper within each burst.
	 */
	pcap_dump_flush(dumper);
	dumper_q->tx_stat.pkts += num_tx;
	dumper_q->tx_stat.bytes += tx_bytes;
	dumper_q->tx_stat.err_pkts += nb_pkts - num_tx;

	return nb_pkts;
}
/*
 * Callback to handle writing packets to a pcap file.
 */
Callback to handle writing packets to a pcap file.
Callback to handle writing packets to a pcap file .
static uint16_t
eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
{
	unsigned int i;
	struct rte_mbuf *mbuf;
	struct pmd_process_private *pp;
	struct pcap_tx_queue *dumper_q = queue;
	uint16_t num_tx = 0;
	uint32_t tx_bytes = 0;
	struct pcap_pkthdr header;
	pcap_dumper_t *dumper;
	unsigned char temp_data[RTE_ETH_PCAP_SNAPLEN];
	size_t len, caplen;
	pp = rte_eth_devices[dumper_q->port_id].process_private;
	dumper = pp->tx_dumper[dumper_q->queue_id];
	if (dumper == NULL || nb_pkts == 0)
		return 0;
	for (i = 0; i < nb_pkts; i++) {
		mbuf = bufs[i];
		len = caplen = rte_pktmbuf_pkt_len(mbuf);
		if (unlikely(!rte_pktmbuf_is_contiguous(mbuf) &&
				len > sizeof(temp_data))) {
			caplen = sizeof(temp_data);
		}
		calculate_timestamp(&header.ts);
		header.len = len;
		header.caplen = caplen;
		pcap_dump((u_char *)dumper, &header,
			rte_pktmbuf_read(mbuf, 0, caplen, temp_data));
		num_tx++;
		tx_bytes += caplen;
		rte_pktmbuf_free(mbuf);
	}
	pcap_dump_flush(dumper);
	dumper_q->tx_stat.pkts += num_tx;
	dumper_q->tx_stat.bytes += tx_bytes;
	dumper_q->tx_stat.err_pkts += nb_pkts - num_tx;
	return nb_pkts;
}
static uint16_t eth_pcap_tx_dumper ( void * queue , struct rte_mbuf * * bufs , uint16_t nb_pkts ) { unsigned int i ; struct rte_mbuf * mbuf ; struct pmd_process_private * pp ; struct pcap_tx_queue * dumper_q = queue ; uint16_t num_tx = 0 ; uint32_t tx_bytes = 0 ; struct pcap_pkthdr header ; pcap_dumper_t * dumper ; unsigned char temp_data [ RTE_ETH_PCAP_SNAPLEN ] ; size_t len , caplen ; pp = rte_eth_devices [ dumper_q -> port_id ] . process_private ; dumper = pp -> tx_dumper [ dumper_q -> queue_id ] ; if ( dumper == NULL || nb_pkts == 0 ) return 0 ; for ( i = 0 ; i < nb_pkts ; i ++ ) { mbuf = bufs [ i ] ; len = caplen = rte_pktmbuf_pkt_len ( mbuf ) ; if ( unlikely ( ! rte_pktmbuf_is_contiguous ( mbuf ) && len > sizeof ( temp_data ) ) ) { caplen = sizeof ( temp_data ) ; } calculate_timestamp ( & header . ts ) ; header . len = len ; header . caplen = caplen ; pcap_dump ( ( u_char * ) dumper , & header , rte_pktmbuf_read ( mbuf , 0 , caplen , temp_data ) ) ; num_tx ++ ; tx_bytes += caplen ; rte_pktmbuf_free ( mbuf ) ; } pcap_dump_flush ( dumper ) ; dumper_q -> tx_stat . pkts += num_tx ; dumper_q -> tx_stat . bytes += tx_bytes ; dumper_q -> tx_stat . err_pkts += nb_pkts - num_tx ; return nb_pkts ; }
Callback to handle writing packets to a pcap file.
Callback to handle writing packets to a pcap file .
/* writes the nb_pkts packets to the previously opened pcap file
	 * dumper */ /* rte_pktmbuf_read() returns a pointer to the data directly
		 * in the mbuf (when the mbuf is contiguous) or, otherwise,
		 * a pointer to temp_data after copying into it.
		 */ /*
	 * Since there's no place to hook a callback when the forwarding
	 * process stops and to make sure the pcap file is actually written,
	 * we flush the pcap dumper within each burst.
	 */