This source file is an example of how to do inline with the segment interface.
The following NTAPI functions are used:
A Napatech capture accelerator is need to run this example. The ntservice.ini must have at least one HostBuffersRx defined. Below is an example of a minimum ini-file. It will create a 32MB RX hostbuffer from NUMA node 0.
The following is required to perform capture of segments to disk:
- #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_NetRxOpen() - Open the stream using a stream ID. The stream ID must match the one used when creating the filter.
- NT_NTPL() - Setup traffic forwarding from stream, and use the wirelength to indicate whether the packet should be dropped or not. Assign traffic to the stream with Dyn3 descriptor. A stream does not return data until traffic is assigned to it by a filter. Stream IDs can be shared between other streams.
- Wait until we start seeing segments that are hit by the NTPL assign command. This is done to avoid getting segments that are not fully classified by the stream. NT_NetRxGet() is called with a timeout of 1000ms and will return NT_STATUS_TIMEOUT in case nothing is received within 1000ms and will return NT_SUCCESS when a segment is returned. Segments with NT_NET_GET_SEGMENTLENGTH()==0 can be returned so it is needed to check for the segment length before using data within the segment. The NT_NET_GET_SEGMENT_TIMESTAMP() macro can still be used on the empty segments. Return values different from that is an indication of an error. Segments that are prior to the expected time are released via NT_NetRxRelease().
- NT_NetRxGet(), and NT_NetRxRelease() - Receive segments, drop every other packet and release segments. The Segment macros are used to find the segment and length and timestamp of the segment:
- NT_NET_GET_SEGMENT_PTR() - Get a pointer to the segment.
- NT_NET_GET_SEGMENT_LENGTH() - Get length of the segment to store.
- NT_NET_GET_SEGMENT_TIMESTAMP() - The time the segment was delivered.
- _nt_net_build_pkt_netbuf() and _nt_net_get_next_packet() are used to traverse packets inside a segment. This is usefull if inspection is needed before saving the segment.
- NT_NetRxClose() - Close the stream when terminating. This will close the stream and release the NTPL assignment made on the hostbuffer.
- Close captured file
- NT_Done() - Close down the NTAPI library.