Detailed Description
The File network stream is used for packet-by-packet offline analysis of the packets captured with the segment RX interface. See Segment interface for a description of how to accomplish this.
To open a file network stream, call the NT_NetFileOpen with the name of the captured file as argument. To get the next packet from the file network stream, call the NT_NetFileGet. Use the packet macros to access the packet data. When finished with the packet, call NT_NetFileRelease to release it again. When finished with the stream, call NT_NetFileClose to close it.
Supported files are native NT captured files, pcap and pcap-ng files. When using pcap or pcap-ng files, the received port information is always set to 0.
For an example on how to use the file network stream interface, see net/replay/replay_example.c.
Functions | |
int | NT_NetFileOpen (NtNetStreamFile_t *hStream, const char *name, enum NtNetInterface_e netIntf, const char *file) |
Opens a capture file. More... | |
int | NT_NetFileOpen_v2 (NtNetStreamFile_t *hStream, const char *name, enum NtNetInterface_e netIntf, const char *file, bool noConvert) |
Opens a capture file (extended version) More... | |
int | NT_NetFileGet (NtNetStreamFile_t hStream, NtNetBuf_t *netBuf) |
Gets packets/segments from a file stream. More... | |
int | NT_NetFileRelease (NtNetStreamFile_t hStream, NtNetBuf_t netBuf) |
Releases the network buffer. More... | |
int | NT_NetFileClose (NtNetStreamFile_t hStream) |
Closes a file stream. More... | |
int | NT_NetFileRead (NtNetStreamFile_t hStream, NtNetFileRead_t *data) |
Read information about a file stream. More... | |
int | NT_NetFileOpen_Attr (NtNetStreamFile_t *hStream, const char *file, const NtNetFileAttr_t *attr) |
Opens a capture file. More... | |
void | NT_NetFileOpenAttrInit (NtNetFileAttr_t *attr) |
Initialize NetFile stream attributes. More... | |
void | NT_NetFileOpenAttrSetName (NtNetFileAttr_t *attr, const char *name) |
Sets the stream name attribute. More... | |
const char * | NT_NetFileOpenAttrGetName (const NtNetFileAttr_t *attr) |
Returns the name attribute. More... | |
void | NT_NetFileOpenAttrSetInterface (NtNetFileAttr_t *attr, enum NtNetInterface_e netIntf) |
Sets the interface type attribute. More... | |
enum NtNetInterface_e | NT_NetTxOpenAttrGetInterface (NtNetTxAttr_t *attr) |
Returns the interface type attribute. More... | |
void | NT_NetFileOpenAttrSetEnablePcapToNtConversion (NtNetFileAttr_t *attr, bool enableFlag) |
Enable or disable automatic conversion from PCAP to NT format. More... | |
bool | NT_NetFileOpenAttrGetEnablePcapToNtConversion (const NtNetTxAttr_t *attr) |
Returns whether automatic conversion from PCAP to NT format is enabled. More... | |
int | NT_NetFileOpenAttrSetConvertedTsType (NtNetFileAttr_t *attr, enum NtTimestampType_e convertedTsType) |
Sets the converted timstamp type attribute. More... | |
enum NtTimestampType_e | NT_NetFileOpenAttrGetConvertedTsType (NtNetTxAttr_t *attr) |
Gets the converted timstamp type attribute. More... | |
Typedefs | |
typedef struct NtNetStreamFile_s * | NtNetStreamFile_t |
Function Documentation
int NT_NetFileOpen | ( | NtNetStreamFile_t * | hStream, |
const char * | name, | ||
enum NtNetInterface_e | netIntf, | ||
const char * | file | ||
) |
Opens a capture file.
This function is called to open a capture file, captured with a segment-based stream. The capture file must have an NT, PCAP or PCAP-NG file header otherwise it will fail when opening the capture file.
- Parameters
-
[out] hStream Reference to a NetFile_t stream pointer [in] name A stream friendly name - used in, for example, logging statements [in] netIntf Deliver packets or segments [in] file The capture file to open
- Return values
-
NT_SUCCESS Success !=NT_SUCCESS Error - use NT_ExplainError for an error description
- Examples:
- net/readcapfile/readcapfile_example.c, net/replay/replay_example.c, net/replay4GA/replay4ga_example.c, and net/replayGS/replayGS_example.c.
Referenced by GetTimeStamp(), and main().
int NT_NetFileOpen_v2 | ( | NtNetStreamFile_t * | hStream, |
const char * | name, | ||
enum NtNetInterface_e | netIntf, | ||
const char * | file, | ||
bool | noConvert | ||
) |
Opens a capture file (extended version)
This function is called to open a capture file, captured with a segment-based stream. The capture file must have an NT, PCAP or PCAP-NG file header otherwise it will fail when opening the capture file.
- Parameters
-
[out] hStream Reference to a NetFile_t stream pointer [in] name A stream friendly name - used in, for example, logging statements [in] netIntf Deliver packets or segments [in] file The capture file to open [in] noConvert Do not convert PCAP files (Native PCAP tx for 4GA)
- Return values
-
NT_SUCCESS Success !=NT_SUCCESS Error - use NT_ExplainError for an error description
int NT_NetFileGet | ( | NtNetStreamFile_t | hStream, |
NtNetBuf_t * | netBuf | ||
) |
Gets packets/segments from a file stream.
This function is called to retrieve packets or segments from a capture file
- Note
- This function has no mutex protection, therefore the same hStream cannot be used by multiple threads
- Parameters
-
[in] hStream NetFile stream handle [out] netBuf Packet/segment container reference
- Return values
-
NT_SUCCESS (0) Success NT_STATUS_END_OF_FILE EOF indicator - See note otherwise Error - use NT_ExplainError for an error description
- Note
- When NT_STATUS_END_OF_FILE is returned the internal file offset that been reset making it possible to call NT_NetFileGet() again without having to close and open the file, which improves performance when replaying a file continuously.
- Examples:
- net/readcapfile/readcapfile_example.c, net/replay/replay_example.c, net/replay4GA/replay4ga_example.c, and net/replayGS/replayGS_example.c.
Referenced by GetTimeStamp(), and main().
int NT_NetFileRelease | ( | NtNetStreamFile_t | hStream, |
NtNetBuf_t | netBuf | ||
) |
Releases the network buffer.
This function will release the netBuf data obtained via NT_FileGet
- Note
- This function has no mutex protection, therefore the same hStream cannot be used by multiple threads
- Parameters
-
[in] hStream NetStreamFile stream handle [in] netBuf The network buffer is received via NT_FileGet
- Return values
-
NT_SUCCESS Success !=NT_SUCCESS Error - use NT_ExplainError for an error description
- Examples:
- net/readcapfile/readcapfile_example.c, net/replay/replay_example.c, net/replay4GA/replay4ga_example.c, and net/replayGS/replayGS_example.c.
Referenced by main().
int NT_NetFileClose | ( | NtNetStreamFile_t | hStream | ) |
Closes a file stream.
This function is called to close a file stream
- Parameters
-
[in] hStream The file stream handle to close
- Return values
-
NT_SUCCESS Success !=NT_SUCCESS Error - use NT_ExplainError for an error description
- Examples:
- net/readcapfile/readcapfile_example.c, net/replay/replay_example.c, net/replay4GA/replay4ga_example.c, and net/replayGS/replayGS_example.c.
Referenced by GetTimeStamp(), and main().
int NT_NetFileRead | ( | NtNetStreamFile_t | hStream, |
NtNetFileRead_t * | data | ||
) |
Read information about a file stream.
This function is called to read information about a file stream
- Parameters
-
[in] hStream The file stream handle [in,out] data Structure containing command and returned data
- Return values
-
NT_SUCCESS Success !=NT_SUCCESS Error - use NT_ExplainError for an error description
- Examples:
- net/replay4GA/replay4ga_example.c, and net/replayGS/replayGS_example.c.
Referenced by main().
int NT_NetFileOpen_Attr | ( | NtNetStreamFile_t * | hStream, |
const char * | file, | ||
const NtNetFileAttr_t * | attr | ||
) |
Opens a capture file.
This function is called to open a capture file, captured with a segment-based stream. The capture file must have an NT, PCAP or PCAP-NG file header otherwise it will fail when opening the capture file.
- Parameters
-
[out] hStream Reference to a NetFile_t stream pointer [in] file The capture file to open [in] attr Attributes of the stream
- Return values
-
NT_SUCCESS Success !=NT_SUCCESS Error - use NT_ExplainError for an error description
void NT_NetFileOpenAttrInit | ( | NtNetFileAttr_t * | attr | ) |
Initialize NetFile stream attributes.
The attributes are initialized to the following default values:
name = NULL
netIntf = NT_NET_INTERFACE_SEGMENT
pcapToNtConversion = True
convertedTsType = NT_TIMESTAMP_TYPE_NATIVE_UNIX
- Parameters
-
[in] attr Pointer to the attributes structure
void NT_NetFileOpenAttrSetName | ( | NtNetFileAttr_t * | attr, |
const char * | name | ||
) |
Sets the stream name attribute.
- Parameters
-
[in] attr Pointer to the attributes structure [in] name Stream friendly name - used in, for example, logging statements
const char* NT_NetFileOpenAttrGetName | ( | const NtNetFileAttr_t * | attr | ) |
Returns the name attribute.
- Parameters
-
[in] attr Pointer to the attributes structure
- Returns
- The name attribute
void NT_NetFileOpenAttrSetInterface | ( | NtNetFileAttr_t * | attr, |
enum NtNetInterface_e | netIntf | ||
) |
Sets the interface type attribute.
- Parameters
-
[in] attr Pointer to the attributes structure [in] netIntf Interface type - segment or packet
enum NtNetInterface_e NT_NetTxOpenAttrGetInterface | ( | NtNetTxAttr_t * | attr | ) |
Returns the interface type attribute.
- Parameters
-
[in] attr Pointer to the attributes structure
- Returns
- The interface type attribute
void NT_NetFileOpenAttrSetEnablePcapToNtConversion | ( | NtNetFileAttr_t * | attr, |
bool | enableFlag | ||
) |
Enable or disable automatic conversion from PCAP to NT format.
- Parameters
-
[in] attr Pointer to the attributes structure [in] enableFlag True enables automatic conversion from PCAP to NT format for 3GA. Automatic conversion does not apply to 4GA, which has native support for PCAP.
bool NT_NetFileOpenAttrGetEnablePcapToNtConversion | ( | const NtNetTxAttr_t * | attr | ) |
Returns whether automatic conversion from PCAP to NT format is enabled.
- Parameters
-
[in] attr Pointer to the attributes structure
- Returns
- A boolean where True denotes that automatic conversion from PCAP to NT format is enabled (only applicable to 3GA).
int NT_NetFileOpenAttrSetConvertedTsType | ( | NtNetFileAttr_t * | attr, |
enum NtTimestampType_e | convertedTsType | ||
) |
Sets the converted timstamp type attribute.
This attribute is only used, when a PCAP file is converted to an NT capture file.
Valid values are: NT_TIMESTAMP_TYPE_NATIVE_UNIX NT_TIMESTAMP_TYPE_UNIX_NANOTIME
- Parameters
-
[in] attr Pointer to the attributes structure [in] convertedTsType Converted timestamp type
enum NtTimestampType_e NT_NetFileOpenAttrGetConvertedTsType | ( | NtNetTxAttr_t * | attr | ) |
Gets the converted timstamp type attribute.
- Parameters
-
[in] attr Pointer to the attributes structure
- Returns
- the converted Timestamp Type attribute
Typedef Documentation
typedef struct NtNetStreamFile_s* NtNetStreamFile_t |
Network file stream handle - used for file streams
Definition at line 1482 of file stream_net.h.