This source file is an example of how to transmit PCAP packets using the packet interface in NTAPI. The example will transmit 2500000 packets with a size of 1024 bytes from port 0. The packet contains an incrementing 32bit pattern.
PCAP can also be used with transmit on timestamp, or segment interfaces. See the respective examples to see how to use those interfaces. Note that for PCAP transmit on timestamp, the "forceTxOnTs" feature must be enabled.
The following NTAPI functions are used:
- The ntservice.ini must have at least one HostBuffersTx defined. Below is an example of a minimum ini-file. It will create a 4MB TX hostbuffer from NUMA node 0.
The following is required to transmit packages:
- #include/nt.h - Applications/Tools only need to include nt.h to obtain prototypes, macros etc. from NTAPI.
- NT_Init(NTAPI_VERSION) - Initialize the NTAPI library. NTAPI_VERSION is a define that describes the version of the API described in the header files included by nt.h. NT_Init() will ask the NTAPI library to convert return data to the NTAPI_VERSION if possible. This will ensure that applications can run on NTAPI libraries of newer versions.
- NT_NetTxOpen_v2() - Open a hostbuffer than can transmit packets to port 0.
- NT_NetTxGet() - Get an empty tx buffer. This will get a 296 byte wire length packet buffer that will be sent onto port 0 when released.
- NT_NET_GET_PKT_DESCR_PTR() is used to retrieve the descriptor
- NT_NET_GET_PKT_L2_PTR() is used to get the L2 pointer to the tx buffer, this is where the payload is placed.
- NT_NetTxRelease() - Release the tx packet buffer. Once a tx buffer is released it will be transmitted
- NT_NetTxClose() - Close the TX stream.
- NT_Done() - Close down the NTAPI library.