From f17cdfeea25b77bff5a040c93cdfacf1aae87b74 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Sun, 16 Dec 2018 23:42:39 -0600 Subject: [PATCH] start declaring other sorts of block structures --- include/hexagram/pcapng.h | 64 ++++++++++++++++++++++++++++++++++++--- src/pcapng.c | 4 +-- 2 files changed, 62 insertions(+), 6 deletions(-) diff --git a/include/hexagram/pcapng.h b/include/hexagram/pcapng.h index 54fdc87..ba15cfd 100644 --- a/include/hexagram/pcapng.h +++ b/include/hexagram/pcapng.h @@ -4,6 +4,9 @@ #include #include +/* + * pcapng reader error states + */ enum { HEXAGRAM_PCAPNG_ERROR_OK = 0, HEXAGRAM_PCAPNG_ERROR_IO = 1, @@ -12,14 +15,67 @@ enum { HEXAGRAM_PCAPNG_ERROR_HANDLER = 4 } hexagram_pcapng_error; -typedef struct _hexagram_pcapng_header { +/* + * pcapng block option types and structure + */ +enum { + HEXAGRAM_PCAPNG_OPTION_END = 0, + HEXAGRAM_PCAPNG_OPTION_COMMENT = 1, + HEXAGRAM_PCAPNG_OPTION_CUSTOM1 = 0x0bac, + HEXAGRAM_PCAPNG_OPTION_CUSTOM2 = 0x0bad, + HEXAGRAM_PCAPNG_OPTION_CUSTOM3 = 0x4bac, + HEXAGRAM_PCAPNG_OPTION_CUSTOM4 = 0x4bad +} hexagram_pcapng_option_type; + +typedef struct _hexagram_pcapng_option { + uint16_t code, + length; +} hexagram_pcapng_option; + +/* + * pcapng block types and structure + */ +enum { + HEXAGRAM_PCAPNG_BLOCK_SECTION = 0x0a0d0d0a, + HEXAGRAM_PCAPNG_BLOCK_INTERFACE = 0x1, + HEXAGRAM_PCAPNG_BLOCK_PACKET = 0x6 +} hexagram_pcapng_block_type; + +typedef struct _hexagram_pcapng_block_header { uint32_t type, length; -} hexagram_pcapng_header; +} hexagram_pcapng_block_header; -typedef struct _hexagram_pcapng_footer { +typedef struct _hexagram_pcapng_block_footer { uint32_t length; -} hexagram_pcapng_footer; +} hexagram_pcapng_block_footer; + +/* + * pcapng section block structure and byte order magic + */ +#define HEXAGRAM_PCAPNG_SECTION_BYTEORDER 0x1a2b3c4d + +typedef struct _hexagram_pcapng_section { + uint32_t magic; + uint16_t major, minor; + uint64_t length; +} hexagram_pcapng_section; + +/* + * pcapng interface block structure + */ +typedef struct _hexagram_pcapng_interface { + uint16_t linktype, + reserved; + uint32_t snaplen; +} hexagram_pcapng_interface; + +/* + * pcapng packet block structure + */ +typedef struct _hexagram_pcapng_packet { + +} hexagram_pcapng_packet; typedef int (hexagram_pcapng_block_handler)(int fd, uint32_t type, diff --git a/src/pcapng.c b/src/pcapng.c index 505b42c..50917a6 100644 --- a/src/pcapng.c +++ b/src/pcapng.c @@ -11,8 +11,8 @@ ssize_t hexagram_pcapng_stream_read(fd, handler, error) hexagram_pcapng_block_handler *handler; int *error; { - hexagram_pcapng_header header; - hexagram_pcapng_footer footer; + hexagram_pcapng_block_header header; + hexagram_pcapng_block_footer footer; ssize_t total = 0; while (1) {