rte_pcapng.h(3)

πŸ’– rte_pcapng.h πŸ’–

okay bestie, so this is the manual page for rte_pcapng.h from the DPDK library β€” it's section 3 (that's the library functions section, iykyk). Buckle up, we're writing packet capture files and it's gonna be iconic. πŸ¦‹

✨ NAME ✨

rte_pcapng.h β€” the header that gives you pcapng file writing powers, no cap. πŸ’…

✨ SYNOPSIS ✨

#include <stdint.h>
#include <sys/types.h>
#include <rte_mempool.h>

πŸŽ€ Enumerations

  • enum rte_pcapng_direction

πŸŽ€ Functions

rte_pcapng_t * rte_pcapng_fdopen (int fd, const char *osname, const char
    *hardware, const char *appname, const char *comment)
void rte_pcapng_close (rte_pcapng_t *self)
int rte_pcapng_add_interface (rte_pcapng_t *self, uint16_t port,
    uint16_t link_type, const char *ifname, const char *ifdescr, const
    char *filter)
struct rte_mbuf * rte_pcapng_copy (uint16_t port_id, uint32_t queue,
    const struct rte_mbuf *m, struct rte_mempool *mp, uint32_t length,
    enum rte_pcapng_direction direction, const char *comment)
uint32_t rte_pcapng_mbuf_size (uint32_t length)
ssize_t rte_pcapng_write_packets (rte_pcapng_t *self, struct rte_mbuf
    *pkts[], uint16_t nb_pkts)
ssize_t rte_pcapng_write_stats (rte_pcapng_t *self, uint16_t port,
    uint64_t ifrecv, uint64_t ifdrop, const char *comment)

🌸 Detailed Description 🌸

RTE pcapng

So pcapng is literally pcap's glow-up era. ✨ It exists because old pcap had some real deficiencies β€” namely, the lack of extensibility and the inability to store additional information. Pcapng said "not me being stuck like that" and reinvented itself. πŸ‘‘

For the full tea on the file format, check the RFC: https://www.ietf.org/id/draft-tuexen-opsawg-pcapng-03.html and https://github.com/pcapng/pcapng/

Definition in file rte_pcapng.h.

🧚 Enumeration Type Documentation 🧚

enum rte_pcapng_direction

Direction flag. These should match Enhanced Packet Block flag bits.

Definition at line 105 of file rte_pcapng.h.

πŸ’œ Function Documentation πŸ’œ

rte_pcapng_t * rte_pcapng_fdopen (int fd, const char * osname, const char * hardware, const char * appname, const char * comment)

Write data to an existing open file. πŸ“

Parameters

  • fd β€” file descriptor
  • osname β€” Optional description of the operating system. Examples: "Debian 11", "Windows Server 22"
  • hardware β€” Optional description of the hardware used to create this file. Examples: "x86 Virtual Machine"
  • appname β€” Optional: application name recorded in the pcapng file. Example: "dpdk-dumpcap 1.0 (DPDK 20.11)"
  • comment β€” Optional comment to add to file header.

Returns

handle to library, or NULL in case of error (and rte_errno is set).


void rte_pcapng_close (rte_pcapng_t * self)

Close the capture file. bye bestie πŸ‘‹

Parameters

  • self β€” handle to library

Add interface information to the capture file.

Parameters

  • self β€” The handle to the packet capture file
  • port β€” The Ethernet port to report stats on.
  • link_type β€” The link type (e.g., DLT_EN10MB).
  • ifname β€” (optional) Interface name to record in the file. If not specified, name will be constructed from port
  • ifdescr β€” (optional) Interface description to record in the file.
  • filter β€” Capture filter to record in the file.
Interfaces must be added to the output file after opening and before any packet record. All ports used in packet capture must be added. periodt.

Returns

number of bytes written to file, -1 on failure


struct rte_mbuf * rte_pcapng_copy (uint16_t port_id, uint32_t queue, const struct rte_mbuf * m, struct rte_mempool * mp, uint32_t length, enum rte_pcapng_direction direction, const char * comment)

Format an mbuf for writing to file. it's giving ✨formatted✨

Parameters

  • port_id β€” The Ethernet port on which packet was received or is going to be transmitted.
  • queue β€” The queue on the Ethernet port where packet was received or is going to be transmitted.
  • mp β€” The mempool from which the "clone" mbufs are allocated.
  • m β€” The mbuf to copy
  • length β€” The upper limit on bytes to copy. Passing UINT32_MAX means all data (after offset).
  • direction β€” The direction of the packer: receive, transmit or unknown.
  • comment β€” Packet comment.

Returns

  • The pointer to the new mbuf formatted for pcapng_write
  • NULL on error such as invalid port or out of memory.

uint32_t rte_pcapng_mbuf_size (uint32_t length)

Determine optimum mbuf data size. πŸ’…

Parameters

  • length β€” The largest packet that will be copied.

Returns

The minimum size of mbuf data to handle packet with length bytes. Accounting for required header and trailer fields


ssize_t rte_pcapng_write_packets (rte_pcapng_t * self, struct rte_mbuf * pkts[], uint16_t nb_pkts)

Write packets to the capture file. πŸŽ€

Packets to be captured are copied by rte_pcapng_copy() and then this function is called to write them to the file.

Warning 🚨 Do not pass original mbufs from transmit or receive or file will be invalid pcapng format. fr fr, don't do it.

Parameters

  • self β€” The handle to the packet capture file
  • pkts β€” The address of an array of nb_pkts pointers to rte_mbuf structures which contain the output packets
  • nb_pkts β€” The number of packets to write to the file.

Returns

The number of bytes written to file, -1 on failure to write file. The mbuf's in pkts are always freed.


ssize_t rte_pcapng_write_stats (rte_pcapng_t * self, uint16_t port, uint64_t ifrecv, uint64_t ifdrop, const char * comment)

Write an Interface statistics block. For statistics, use 0 if don't know or care to report it. Should be called before closing capture to report results.

Parameters

  • self β€” The handle to the packet capture file
  • port β€” The Ethernet port to report stats on.
  • ifrecv β€” The number of packets received by capture. Optional: use UINT64_MAX if not known.
  • ifdrop β€” The number of packets missed by the capture process. Optional: use UINT64_MAX if not known.
  • comment β€” Optional comment to add to statistics.

Returns

On success number of bytes written to file, -1 on failure to write file (and errno is set)

  • (-EINVAL) if bad parameter.
  • (-ENOMEM) if unable to allocate resources.

🌈 Author 🌈

Generated automatically by Doxygen for DPDK from the source code. (yes the robots wrote it, we just gave it a makeover πŸ’…)


and that's the whole page, bestie!! this was DPDK, Version 25.11.3, rte_pcapng.h(3) β€” go forth and capture packets responsibly, mwah 🫢✨

πŸ“¦ where this page comes from