capfileconvert_example.c

Reference Documentation

product_line_custom
IntelĀ® PAC
Napatech SmartNIC
category
Reference Information
Napatech Software Suite: examples/net/capfileconvert/capfileconvert_example.c File Reference
capfileconvert_example.c File Reference
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <argparse.h>
#include <nt.h>
#include "capfileconvert_example.h"

Go to the source code of this file.

Functions

static void DisplayProgramHeader (void)
 
static void DisplayProgramFooter (void)
 
static void StopApplication (int sig)
 
static int _Convert (void)
 
int main (int argc, const char *argv[])
 

Data Structures

struct  Nt2GSegmentDumpHeader_s
 
struct  pcap_hdr_s
 
struct  nttimeval
 
struct  ntpcap
 

Macros

#define _GNU_SOURCE
 
#define PKTBUF_SIZE   (16*1024)
 
#define CAPFILE_MAX_SIZE   ((size_t)-1)
 
#define NT_2GD_SEGMENT_DUMP_MAGIC   0xFEDEABBA
 
#define PCAP_MAGIC   0xa1b2c3d4
 
#define PCAP_SWAPPED_MAGIC   0xd4c3b2a1
 
#define PCAP_MODIFIED_MAGIC   0xa1b2cd34
 
#define PCAP_SWAPPED_MODIFIED_MAGIC   0x34cdb2a1
 
#define PCAP_NSEC_MAGIC   0xa1b23c4d
 
#define PCAP_SWAPPED_NSEC_MAGIC   0x4d3cb2a1
 
#define SWAPLONG(y)    ((((y)&0xff)<<24) | (((y)&0xff00)<<8) | (((y)&0xff0000)>>8) | (((y)>>24)&0xff))
 
#define SWAPSHORT(y)   ( (((y)&0xff)<<8) | ((u_short)((y)&0xff00)>>8) )
 

Enumerations

enum  InputFormat_e {
  INPUT_FORMAT_UNKNOWN = 0, INPUT_FORMAT_3GD, INPUT_FORMAT_PCAP, INPUT_FORMAT_PCAPNANO,
  INPUT_FORMAT_2GD, INPUT_FORMAT_3GDNANO
}
 
enum  OutputFormat_e {
  OUTPUT_FORMAT_UNKNOWN =0, OUTPUT_FORMAT_PCAP, OUTPUT_FORMAT_PCAPNANO, OUTPUT_FORMAT_NT3GD,
  OUTPUT_FORMAT_NT3GDNANO
}
 
enum  InputPCAPFormat_e { INPUT_PCAPFORMAT_UNKNOWN =0, INPUT_PCAPFORMAT_LIBPCAP, INPUT_PCAPFORMAT_NAPATECH }
 

Variables

static enum InputFormat_e input_format = 0
 
static const char * progname = "capfileconvert"
 
static int appRunning = 1
 
static unsigned long long pktNum
 
static unsigned long long pktSkipNum
 
static char * opt_input_file = NULL
 
static char * opt_output_file = NULL
 
static char * opt_output_format = NULL
 
static char * opt_input_format = NULL
 
static int opt_verbose = 0
 
static enum OutputFormat_e opt_outputformat = 0
 
static enum InputPCAPFormat_e opt_inputformat = 0
 
struct argparse_option arg_options []
 
static struct NtFileHeader0_s nt3gdFileHeader
 
static struct NtFileHeader0_s nt3gdNsFileHeader
 
static struct pcap_hdr_s pcapGlobalHdr
 
static struct pcap_hdr_s pcapGlobalHdrNano
 

Function Documentation

static void DisplayProgramHeader ( void  )
static
Examples:
net/capfileconvert/capfileconvert_example.c, and net/replayGS/replayGS_example.c.

Definition at line 229 of file capfileconvert_example.c.

Referenced by main().

static void DisplayProgramFooter ( void  )
static
Examples:
net/capfileconvert/capfileconvert_example.c, and net/replayGS/replayGS_example.c.

Definition at line 240 of file capfileconvert_example.c.

Referenced by main().

static void StopApplication ( int  sig)
static

Definition at line 248 of file capfileconvert_example.c.

Referenced by main().

static int _Convert ( void  )
static

Try to detect input file format

PCAP has not been detected, assume legacy 2GD Capture but perform some sanity checks first though.

The input file has been detected at this point. Do the convertion.

Examples:
net/capfileconvert/capfileconvert_example.c.

Definition at line 254 of file capfileconvert_example.c.

Referenced by main().

int main ( int  argc,
const char *  argv[] 
)

Definition at line 1008 of file capfileconvert_example.c.

Macro Definition Documentation

#define _GNU_SOURCE

Definition at line 52 of file capfileconvert_example.c.

#define PKTBUF_SIZE   (16*1024)
Examples:
net/capfileconvert/capfileconvert_example.c.

Definition at line 74 of file capfileconvert_example.c.

Referenced by _Convert().

#define CAPFILE_MAX_SIZE   ((size_t)-1)
Examples:
net/capfileconvert/capfileconvert_example.c.

Definition at line 75 of file capfileconvert_example.c.

Referenced by _Convert().

#define NT_2GD_SEGMENT_DUMP_MAGIC   0xFEDEABBA
Examples:
net/capfileconvert/capfileconvert_example.c.

Definition at line 130 of file capfileconvert_example.c.

Referenced by _Convert().

#define PCAP_MAGIC   0xa1b2c3d4
Examples:
net/capfileconvert/capfileconvert_example.c.

Definition at line 169 of file capfileconvert_example.c.

Referenced by _Convert().

#define PCAP_SWAPPED_MAGIC   0xd4c3b2a1
Examples:
net/capfileconvert/capfileconvert_example.c.

Definition at line 170 of file capfileconvert_example.c.

Referenced by _Convert().

#define PCAP_MODIFIED_MAGIC   0xa1b2cd34
Examples:
net/capfileconvert/capfileconvert_example.c.

Definition at line 171 of file capfileconvert_example.c.

Referenced by _Convert().

#define PCAP_SWAPPED_MODIFIED_MAGIC   0x34cdb2a1
Examples:
net/capfileconvert/capfileconvert_example.c.

Definition at line 172 of file capfileconvert_example.c.

Referenced by _Convert().

#define PCAP_NSEC_MAGIC   0xa1b23c4d
Examples:
net/capfileconvert/capfileconvert_example.c.

Definition at line 173 of file capfileconvert_example.c.

Referenced by _Convert().

#define PCAP_SWAPPED_NSEC_MAGIC   0x4d3cb2a1
Examples:
net/capfileconvert/capfileconvert_example.c.

Definition at line 174 of file capfileconvert_example.c.

Referenced by _Convert().

#define SWAPLONG (   y)    ((((y)&0xff)<<24) | (((y)&0xff00)<<8) | (((y)&0xff0000)>>8) | (((y)>>24)&0xff))

Definition at line 176 of file capfileconvert_example.c.

#define SWAPSHORT (   y)    ( (((y)&0xff)<<8) | ((u_short)((y)&0xff00)>>8) )

Definition at line 178 of file capfileconvert_example.c.

Enumeration Type Documentation

Enumerator
INPUT_FORMAT_UNKNOWN 
INPUT_FORMAT_3GD 
INPUT_FORMAT_PCAP 
INPUT_FORMAT_PCAPNANO 
INPUT_FORMAT_2GD 
INPUT_FORMAT_3GDNANO 

Definition at line 81 of file capfileconvert_example.c.

Enumerator
OUTPUT_FORMAT_UNKNOWN 
OUTPUT_FORMAT_PCAP 
OUTPUT_FORMAT_PCAPNANO 
OUTPUT_FORMAT_NT3GD 
OUTPUT_FORMAT_NT3GDNANO 

Definition at line 102 of file capfileconvert_example.c.

Enumerator
INPUT_PCAPFORMAT_UNKNOWN 
INPUT_PCAPFORMAT_LIBPCAP 
INPUT_PCAPFORMAT_NAPATECH 

Definition at line 110 of file capfileconvert_example.c.

Variable Documentation

enum InputFormat_e input_format = 0
static
Examples:
net/capfileconvert/capfileconvert_example.c.

Referenced by _Convert().

const char* progname = "capfileconvert"
static
Examples:
net/capfileconvert/capfileconvert_example.c, and net/replayGS/replayGS_example.c.

Definition at line 91 of file capfileconvert_example.c.

Referenced by DisplayProgramHeader().

int appRunning = 1
static
Examples:
net/capfileconvert/capfileconvert_example.c, net/replayGS/replayGS_example.c, net/transmit_multifunction/transmit_multifunction_example.c, and statUsage/statUsage_example.c.

Definition at line 92 of file capfileconvert_example.c.

Referenced by _Convert(), and StopApplication().

unsigned long long pktNum
static
Examples:
net/capfileconvert/capfileconvert_example.c.

Definition at line 93 of file capfileconvert_example.c.

Referenced by _Convert().

unsigned long long pktSkipNum
static
Examples:
net/capfileconvert/capfileconvert_example.c.

Definition at line 94 of file capfileconvert_example.c.

Referenced by _Convert().

char* opt_input_file = NULL
static
Examples:
net/capfileconvert/capfileconvert_example.c.

Definition at line 96 of file capfileconvert_example.c.

Referenced by _Convert(), and main().

char* opt_output_file = NULL
static
Examples:
net/capfileconvert/capfileconvert_example.c.

Definition at line 97 of file capfileconvert_example.c.

Referenced by _Convert(), and main().

char* opt_output_format = NULL
static
Examples:
net/capfileconvert/capfileconvert_example.c.

Definition at line 98 of file capfileconvert_example.c.

Referenced by main().

char* opt_input_format = NULL
static
Examples:
net/capfileconvert/capfileconvert_example.c.

Definition at line 99 of file capfileconvert_example.c.

Referenced by main().

int opt_verbose = 0
static
Examples:
net/capfileconvert/capfileconvert_example.c.

Definition at line 100 of file capfileconvert_example.c.

Referenced by _Convert().

enum OutputFormat_e opt_outputformat = 0
static
Examples:
net/capfileconvert/capfileconvert_example.c.

Referenced by _Convert(), and main().

enum InputPCAPFormat_e opt_inputformat = 0
static
Examples:
net/capfileconvert/capfileconvert_example.c.

Referenced by _Convert(), and main().

struct argparse_option arg_options[]
Initial value:
= {
OPT_BOOLEAN('v', "verbose", &opt_verbose, "Print extra information", NULL, 0, 0, NULL),
OPT_STRING( 'i', "input", &opt_input_file, "Specifies the input file", NULL, 0, 0, "file"),
OPT_STRING( 'o', "output", &opt_output_file, "Specifies the output file", NULL, 0, 0, "file"),
OPT_STRING( 'f', "outputformat", &opt_output_format, "Specifies the output format: <pcap | pcapnano | nt3gd | nt3gdnano>", NULL, 0, 0, "format"),
OPT_STRING( 'n', "inputformat", &opt_input_format, "Specifies the input format when converting a pcap file: <libpcap | ntpcap>", NULL, 0, 0, "format"),
}

Table of valid options. Mainly used for the getopt_long_only function. For further info see the manpage.

Definition at line 120 of file capfileconvert_example.c.

struct NtFileHeader0_s nt3gdFileHeader
static
Initial value:
=
{
NT_STID_FILE_HEADER0,
0,
NT_FILE_HEADER0_COOKIE,
0,
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
}
Examples:
net/capfileconvert/capfileconvert_example.c.

Definition at line 143 of file capfileconvert_example.c.

Referenced by _Convert().

struct NtFileHeader0_s nt3gdNsFileHeader
static
Initial value:
=
{
NT_STID_FILE_HEADER0,
0,
NT_FILE_HEADER0_COOKIE,
0,
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
}
Examples:
net/capfileconvert/capfileconvert_example.c.

Definition at line 156 of file capfileconvert_example.c.

Referenced by _Convert().

struct pcap_hdr_s pcapGlobalHdr
static
Initial value:
=
{
2,
4,
0,
0,
10000,
1
}

Definition at line 195 of file capfileconvert_example.c.

struct pcap_hdr_s pcapGlobalHdrNano
static
Initial value:
=
{
2,
4,
0,
0,
10000,
1
}

Definition at line 206 of file capfileconvert_example.c.