capfileconvert_example.c

Reference Documentation

Platform
Napatech SmartNIC
Content Type
Reference Information
Capture Software Version
Link™ Capture Software 12.15
Napatech Software Suite: examples/net/capfileconvert/capfileconvert_example.c File Reference
capfileconvert_example.c File Reference
#include <nt.h>
#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 "capfileconvert_example.h"

Go to the source code of this file.

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 }
 

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[])
 

Variables

static atomic_int appRunning = 1
 
static enum InputFormat_e input_format = 0
 
static const char * progname = "capfileconvert"
 
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
 

Macro Definition Documentation

#define _GNU_SOURCE

Definition at line 54 of file capfileconvert_example.c.

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

Definition at line 83 of file capfileconvert_example.c.

Referenced by _Convert().

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

Definition at line 84 of file capfileconvert_example.c.

Referenced by _Convert().

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

Definition at line 138 of file capfileconvert_example.c.

Referenced by _Convert().

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

Definition at line 177 of file capfileconvert_example.c.

Referenced by _Convert().

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

Definition at line 178 of file capfileconvert_example.c.

Referenced by _Convert().

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

Definition at line 179 of file capfileconvert_example.c.

Referenced by _Convert().

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

Definition at line 180 of file capfileconvert_example.c.

Referenced by _Convert().

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

Definition at line 181 of file capfileconvert_example.c.

Referenced by _Convert().

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

Definition at line 182 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 184 of file capfileconvert_example.c.

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

Definition at line 186 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 90 of file capfileconvert_example.c.

Enumerator
OUTPUT_FORMAT_UNKNOWN 
OUTPUT_FORMAT_PCAP 
OUTPUT_FORMAT_PCAPNANO 
OUTPUT_FORMAT_NT3GD 
OUTPUT_FORMAT_NT3GDNANO 

Definition at line 110 of file capfileconvert_example.c.

Enumerator
INPUT_PCAPFORMAT_UNKNOWN 
INPUT_PCAPFORMAT_LIBPCAP 
INPUT_PCAPFORMAT_NAPATECH 

Definition at line 118 of file capfileconvert_example.c.

Function Documentation

static void DisplayProgramHeader ( void  )
static
Examples:
net/capfileconvert/capfileconvert_example.c.

Definition at line 237 of file capfileconvert_example.c.

Referenced by main().

static void DisplayProgramFooter ( void  )
static
Examples:
net/capfileconvert/capfileconvert_example.c.

Definition at line 248 of file capfileconvert_example.c.

Referenced by main().

static void StopApplication ( int  sig)
static

Definition at line 264 of file capfileconvert_example.c.

Referenced by DisplayProgramFooter(), and 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 271 of file capfileconvert_example.c.

Referenced by main().

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

Definition at line 1025 of file capfileconvert_example.c.

Variable Documentation

atomic_int appRunning = 1
static

Definition at line 80 of file capfileconvert_example.c.

Referenced by _Convert(), DisplayProgramFooter(), and StopApplication().

enum InputFormat_e input_format = 0
static
const char* progname = "capfileconvert"
static
unsigned long long pktNum
static
Examples:
net/capfileconvert/capfileconvert_example.c.

Definition at line 101 of file capfileconvert_example.c.

Referenced by _Convert().

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

Definition at line 102 of file capfileconvert_example.c.

Referenced by _Convert().

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

Definition at line 104 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 105 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 106 of file capfileconvert_example.c.

Referenced by main().

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

Definition at line 107 of file capfileconvert_example.c.

Referenced by main().

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

Definition at line 108 of file capfileconvert_example.c.

Referenced by _Convert().

enum OutputFormat_e opt_outputformat = 0
static
enum InputPCAPFormat_e opt_inputformat = 0
static
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 128 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 151 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 164 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 203 of file capfileconvert_example.c.

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

Definition at line 214 of file capfileconvert_example.c.