diff --git a/include/hexagram/pcapng.h b/include/hexagram/pcapng.h index 278c588..b3d9dad 100644 --- a/include/hexagram/pcapng.h +++ b/include/hexagram/pcapng.h @@ -34,9 +34,10 @@ typedef struct _hexagram_pcapng_option { * pcapng block types and structure */ typedef enum { - HEXAGRAM_PCAPNG_BLOCK_SECTION = 0x0a0d0d0a, - HEXAGRAM_PCAPNG_BLOCK_INTERFACE = 0x1, - HEXAGRAM_PCAPNG_BLOCK_PACKET = 0x6 + HEXAGRAM_PCAPNG_BLOCK_SECTION = 0x0a0d0d0a, + HEXAGRAM_PCAPNG_BLOCK_IF = 0x1, + HEXAGRAM_PCAPNG_BLOCK_IF_STATS = 0x5, + HEXAGRAM_PCAPNG_BLOCK_PACKET = 0x6 } hexagram_pcapng_block_type; typedef struct _hexagram_pcapng_block_header { @@ -80,11 +81,28 @@ typedef struct _hexagram_pcapng_section { #define HEXAGRAM_PCAPNG_OPTION_IF_FCSLEN 13 #define HEXAGRAM_PCAPNG_OPTION_IF_TSOFFSET 14 -typedef struct _hexagram_pcapng_interface { +typedef struct _hexagram_pcapng_if { uint16_t linktype, reserved; uint32_t snaplen; -} hexagram_pcapng_interface; +} hexagram_pcapng_if; + +/* + * pcapng interface statistics block structure + */ +#define HEXAGRAM_PCAPNG_OPTION_ISB_STARTTIME 2 +#define HEXAGRAM_PCAPNG_OPTION_ISB_ENDTIME 3 +#define HEXAGRAM_PCAPNG_OPTION_ISB_IFRECV 4 +#define HEXAGRAM_PCAPNG_OPTION_ISB_IFDROP 5 +#define HEXAGRAM_PCAPNG_OPTION_ISB_FILTERACCEPT 6 +#define HEXAGRAM_PCAPNG_OPTION_ISB_OSDROP 7 +#define HEXAGRAM_PCAPNG_OPTION_ISB_USRDELIV 8 + +typedef struct _hexagram_pcapng_if_stats { + uint32_t if_id, + timestamp_high, + timestamp_low; +} hexagram_pcapng_if_stats; /* * pcapng packet block structure @@ -100,12 +118,21 @@ typedef struct _hexagram_pcapng_packet { origlen; } hexagram_pcapng_packet; +/* + * pcapng stream reading facilities + */ +typedef struct _hexagram_pcapng_stream hexagram_pcapng_stream; + typedef int (hexagram_pcapng_block_handler)(int fd, uint32_t type, size_t length); + + ssize_t hexagram_pcapng_stream_read(int fd, hexagram_pcapng_block_handler *handler, int *error); + + #endif /* _HEXAGRAM_PCAPNG_H */ diff --git a/src/pcapng.c b/src/pcapng.c index 50917a6..910ef85 100644 --- a/src/pcapng.c +++ b/src/pcapng.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -6,6 +7,29 @@ #include +struct _hexagram_pcapng_stream { + int fd; + uint32_t if_count; + hexagram_pcapng_section *section; + hexagram_pcapng_if *ifs; + hexagram_pcapng_if_stats *stats; +}; + +hexagram_pcapng_stream *hexagram_pcapng_stream_open_fd(int fd) { + hexagram_pcapng_stream *stream; + + if ((stream = malloc(sizeof(*stream))) == NULL) { + goto error_malloc_stream; + } + + stream->if_count = 0; + + return stream; + +error_malloc_stream: + return NULL; +} + ssize_t hexagram_pcapng_stream_read(fd, handler, error) int fd; hexagram_pcapng_block_handler *handler;