libpcap  1.10.1
About: libpcap is a packet filter library used by tools like tcpdump.
  Fossies Dox: libpcap-1.10.1.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

sf-pcapng.c File Reference
#include <pcap/pcap-inttypes.h>
#include <errno.h>
#include <memory.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "pcap-int.h"
#include "pcap-common.h"
#include "sf-pcapng.h"
Include dependency graph for sf-pcapng.c:

Go to the source code of this file.

Data Structures

struct  block_header
 
struct  block_trailer
 
struct  option_header
 
struct  section_header_block
 
struct  interface_description_block
 
struct  enhanced_packet_block
 
struct  simple_packet_block
 
struct  packet_block
 
struct  block_cursor
 
struct  pcap_ng_if
 
struct  pcap_ng_sf
 

Macros

#define OPT_ENDOFOPT   0 /* end of options */
 
#define OPT_COMMENT   1 /* comment string */
 
#define BT_SHB   0x0A0D0D0A
 
#define BT_SHB_INSANE_MAX   1024U*1024U*1U /* 1MB should be enough */
 
#define BYTE_ORDER_MAGIC   0x1A2B3C4D
 
#define PCAP_NG_VERSION_MAJOR   1
 
#define PCAP_NG_VERSION_MINOR   0
 
#define BT_IDB   0x00000001
 
#define IF_NAME   2 /* interface name string */
 
#define IF_DESCRIPTION   3 /* interface description string */
 
#define IF_IPV4ADDR   4 /* interface's IPv4 address and netmask */
 
#define IF_IPV6ADDR   5 /* interface's IPv6 address and prefix length */
 
#define IF_MACADDR   6 /* interface's MAC address */
 
#define IF_EUIADDR   7 /* interface's EUI address */
 
#define IF_SPEED   8 /* interface's speed, in bits/s */
 
#define IF_TSRESOL   9 /* interface's time stamp resolution */
 
#define IF_TZONE   10 /* interface's time zone */
 
#define IF_FILTER   11 /* filter used when capturing on interface */
 
#define IF_OS   12 /* string OS on which capture on this interface was done */
 
#define IF_FCSLEN   13 /* FCS length for this interface */
 
#define IF_TSOFFSET   14 /* time stamp offset for this interface */
 
#define BT_EPB   0x00000006
 
#define BT_SPB   0x00000003
 
#define BT_PB   0x00000002
 
#define INITIAL_MAX_BLOCKSIZE   (16*1024*1024)
 
#define MAX_BLOCKSIZE_FOR_SNAPLEN(max_snaplen)
 

Enumerations

enum  tstamp_scale_type_t {
  PASS_THROUGH , SCALE_UP , SCALE_DOWN , PASS_THROUGH ,
  SCALE_UP_DEC , SCALE_DOWN_DEC , SCALE_UP_BIN , SCALE_DOWN_BIN
}
 

Functions

static void pcap_ng_cleanup (pcap_t *p)
 
static int pcap_ng_next_packet (pcap_t *p, struct pcap_pkthdr *hdr, u_char **data)
 
static int read_bytes (FILE *fp, void *buf, size_t bytes_to_read, int fail_on_eof, char *errbuf)
 
static int read_block (FILE *fp, pcap_t *p, struct block_cursor *cursor, char *errbuf)
 
static void * get_from_block_data (struct block_cursor *cursor, size_t chunk_size, char *errbuf)
 
static struct option_headerget_opthdr_from_block_data (pcap_t *p, struct block_cursor *cursor, char *errbuf)
 
static void * get_optvalue_from_block_data (struct block_cursor *cursor, struct option_header *opthdr, char *errbuf)
 
static int process_idb_options (pcap_t *p, struct block_cursor *cursor, uint64_t *tsresol, uint64_t *tsoffset, int *is_binary, char *errbuf)
 
static int add_interface (pcap_t *p, struct interface_description_block *idbp, struct block_cursor *cursor, char *errbuf)
 
pcap_tpcap_ng_check_header (const uint8_t *magic, FILE *fp, u_int precision, char *errbuf, int *err)
 

Macro Definition Documentation

◆ BT_EPB

#define BT_EPB   0x00000006

Definition at line 142 of file sf-pcapng.c.

◆ BT_IDB

#define BT_IDB   0x00000001

Definition at line 113 of file sf-pcapng.c.

◆ BT_PB

#define BT_PB   0x00000002

Definition at line 166 of file sf-pcapng.c.

◆ BT_SHB

#define BT_SHB   0x0A0D0D0A

Definition at line 87 of file sf-pcapng.c.

◆ BT_SHB_INSANE_MAX

#define BT_SHB_INSANE_MAX   1024U*1024U*1U /* 1MB should be enough */

Definition at line 88 of file sf-pcapng.c.

◆ BT_SPB

#define BT_SPB   0x00000003

Definition at line 156 of file sf-pcapng.c.

◆ BYTE_ORDER_MAGIC

#define BYTE_ORDER_MAGIC   0x1A2B3C4D

Definition at line 100 of file sf-pcapng.c.

◆ IF_DESCRIPTION

#define IF_DESCRIPTION   3 /* interface description string */

Definition at line 126 of file sf-pcapng.c.

◆ IF_EUIADDR

#define IF_EUIADDR   7 /* interface's EUI address */

Definition at line 130 of file sf-pcapng.c.

◆ IF_FCSLEN

#define IF_FCSLEN   13 /* FCS length for this interface */

Definition at line 136 of file sf-pcapng.c.

◆ IF_FILTER

#define IF_FILTER   11 /* filter used when capturing on interface */

Definition at line 134 of file sf-pcapng.c.

◆ IF_IPV4ADDR

#define IF_IPV4ADDR   4 /* interface's IPv4 address and netmask */

Definition at line 127 of file sf-pcapng.c.

◆ IF_IPV6ADDR

#define IF_IPV6ADDR   5 /* interface's IPv6 address and prefix length */

Definition at line 128 of file sf-pcapng.c.

◆ IF_MACADDR

#define IF_MACADDR   6 /* interface's MAC address */

Definition at line 129 of file sf-pcapng.c.

◆ IF_NAME

#define IF_NAME   2 /* interface name string */

Definition at line 125 of file sf-pcapng.c.

◆ IF_OS

#define IF_OS   12 /* string OS on which capture on this interface was done */

Definition at line 135 of file sf-pcapng.c.

◆ IF_SPEED

#define IF_SPEED   8 /* interface's speed, in bits/s */

Definition at line 131 of file sf-pcapng.c.

◆ IF_TSOFFSET

#define IF_TSOFFSET   14 /* time stamp offset for this interface */

Definition at line 137 of file sf-pcapng.c.

◆ IF_TSRESOL

#define IF_TSRESOL   9 /* interface's time stamp resolution */

Definition at line 132 of file sf-pcapng.c.

◆ IF_TZONE

#define IF_TZONE   10 /* interface's time zone */

Definition at line 133 of file sf-pcapng.c.

◆ INITIAL_MAX_BLOCKSIZE

#define INITIAL_MAX_BLOCKSIZE   (16*1024*1024)

Definition at line 239 of file sf-pcapng.c.

◆ MAX_BLOCKSIZE_FOR_SNAPLEN

#define MAX_BLOCKSIZE_FOR_SNAPLEN (   max_snaplen)
Value:
(sizeof (struct block_header) + \
sizeof (struct enhanced_packet_block) + \
(max_snaplen) + 131072 + \
sizeof (struct block_trailer))

Definition at line 246 of file sf-pcapng.c.

◆ OPT_COMMENT

#define OPT_COMMENT   1 /* comment string */

Definition at line 69 of file sf-pcapng.c.

◆ OPT_ENDOFOPT

#define OPT_ENDOFOPT   0 /* end of options */

Definition at line 68 of file sf-pcapng.c.

◆ PCAP_NG_VERSION_MAJOR

#define PCAP_NG_VERSION_MAJOR   1

Definition at line 107 of file sf-pcapng.c.

◆ PCAP_NG_VERSION_MINOR

#define PCAP_NG_VERSION_MINOR   0

Definition at line 108 of file sf-pcapng.c.

Enumeration Type Documentation

◆ tstamp_scale_type_t

Enumerator
PASS_THROUGH 
SCALE_UP 
SCALE_DOWN 
PASS_THROUGH 
SCALE_UP_DEC 
SCALE_DOWN_DEC 
SCALE_UP_BIN 
SCALE_DOWN_BIN 

Definition at line 189 of file sf-pcapng.c.

Function Documentation

◆ add_interface()

◆ get_from_block_data()

static void* get_from_block_data ( struct block_cursor cursor,
size_t  chunk_size,
char *  errbuf 
)
static

◆ get_opthdr_from_block_data()

static struct option_header* get_opthdr_from_block_data ( pcap_t p,
struct block_cursor cursor,
char *  errbuf 
)
static

◆ get_optvalue_from_block_data()

static void* get_optvalue_from_block_data ( struct block_cursor cursor,
struct option_header opthdr,
char *  errbuf 
)
static

Definition at line 439 of file sf-pcapng.c.

References get_from_block_data(), and option_header::option_length.

Referenced by process_idb_options().

◆ pcap_ng_check_header()

◆ pcap_ng_cleanup()

static void pcap_ng_cleanup ( pcap_t p)
static

Definition at line 1087 of file sf-pcapng.c.

References pcap_ng_sf::ifaces, pcap::priv, and sf_cleanup().

Referenced by pcap_ng_check_header().

◆ pcap_ng_next_packet()

◆ process_idb_options()

static int process_idb_options ( pcap_t p,
struct block_cursor cursor,
uint64_t *  tsresol,
uint64_t *  tsoffset,
int *  is_binary,
char *  errbuf 
)
static

◆ read_block()

◆ read_bytes()

static int read_bytes ( FILE *  fp,
void *  buf,
size_t  bytes_to_read,
int  fail_on_eof,
char *  errbuf 
)
static

Definition at line 257 of file sf-pcapng.c.

References errno, PCAP_ERRBUF_SIZE, pcap_fmt_errmsg_for_errno(), and snprintf().

Referenced by pcap_ng_check_header(), and read_block().