From e7b79a711824a6eb40fa5584b8f4499d67fc39e8 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Sun, 20 Jan 2019 14:58:44 -0600 Subject: [PATCH] Stub pcapng data structures into their own headers --- include/hexagram/pcapng.h | 122 ++--------------------------- include/hexagram/pcapng/block.h | 23 ++++++ include/hexagram/pcapng/error.h | 15 ++++ include/hexagram/pcapng/if.h | 27 +++++++ include/hexagram/pcapng/if_stats.h | 21 +++++ include/hexagram/pcapng/option.h | 19 +++++ include/hexagram/pcapng/packet.h | 18 +++++ include/hexagram/pcapng/section.h | 19 +++++ 8 files changed, 149 insertions(+), 115 deletions(-) create mode 100644 include/hexagram/pcapng/block.h create mode 100644 include/hexagram/pcapng/error.h create mode 100644 include/hexagram/pcapng/if.h create mode 100644 include/hexagram/pcapng/if_stats.h create mode 100644 include/hexagram/pcapng/option.h create mode 100644 include/hexagram/pcapng/packet.h create mode 100644 include/hexagram/pcapng/section.h diff --git a/include/hexagram/pcapng.h b/include/hexagram/pcapng.h index b3d9dad..037a1c9 100644 --- a/include/hexagram/pcapng.h +++ b/include/hexagram/pcapng.h @@ -4,119 +4,13 @@ #include #include -/* - * pcapng reader error states - */ -typedef enum { - HEXAGRAM_PCAPNG_ERROR_OK = 0, - HEXAGRAM_PCAPNG_ERROR_IO = 1, - HEXAGRAM_PCAPNG_ERROR_TRUNCATED = 2, - HEXAGRAM_PCAPNG_ERROR_FORMAT = 3, - HEXAGRAM_PCAPNG_ERROR_HANDLER = 4 -} hexagram_pcapng_error; - -/* - * pcapng block option types and structure - */ -#define HEXAGRAM_PCAPNG_OPTION_END 0x0 -#define HEXAGRAM_PCAPNG_OPTION_COMMENT 0x1 -#define HEXAGRAM_PCAPNG_OPTION_CUSTOM1 0x0bac -#define HEXAGRAM_PCAPNG_OPTION_CUSTOM2 0x0bad -#define HEXAGRAM_PCAPNG_OPTION_CUSTOM3 0x4bac -#define HEXAGRAM_PCAPNG_OPTION_CUSTOM4 0x4bad - -typedef struct _hexagram_pcapng_option { - uint16_t code, - length; -} hexagram_pcapng_option; - -/* - * pcapng block types and structure - */ -typedef enum { - 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 { - uint32_t type, - length; -} hexagram_pcapng_block_header; - -typedef struct _hexagram_pcapng_block_footer { - uint32_t length; -} hexagram_pcapng_block_footer; - -/* - * pcapng section block structure and byte order magic - */ -#define HEXAGRAM_PCAPNG_SECTION_MAGIC 0x1a2b3c4d - -#define HEXAGRAM_PCAPNG_OPTION_SHB_HARDWARE 2 -#define HEXAGRAM_PCAPNG_OPTION_SHB_OS 3 -#define HEXAGRAM_PCAPNG_OPTION_SHB_USERAPPL 4 - -typedef struct _hexagram_pcapng_section { - uint32_t magic; - uint16_t major, minor; - uint64_t length; -} hexagram_pcapng_section; - -/* - * pcapng interface description block structure - */ -#define HEXAGRAM_PCAPNG_OPTION_IF_NAME 2 -#define HEXAGRAM_PCAPNG_OPTION_IF_DESCRIPTION 3 -#define HEXAGRAM_PCAPNG_OPTION_IF_IPV4_ADDR 4 -#define HEXAGRAM_PCAPNG_OPTION_IF_IPV6_ADDR 5 -#define HEXAGRAM_PCAPNG_OPTION_IF_MAC_ADDR 6 -#define HEXAGRAM_PCAPNG_OPTION_IF_EUI_ADDR 7 -#define HEXAGRAM_PCAPNG_OPTION_IF_SPEED 8 -#define HEXAGRAM_PCAPNG_OPTION_IF_TSRESOL 9 -#define HEXAGRAM_PCAPNG_OPTION_IF_TZONE 10 -#define HEXAGRAM_PCAPNG_OPTION_IF_FILTER 11 -#define HEXAGRAM_PCAPNG_OPTION_IF_OS 12 -#define HEXAGRAM_PCAPNG_OPTION_IF_FCSLEN 13 -#define HEXAGRAM_PCAPNG_OPTION_IF_TSOFFSET 14 - -typedef struct _hexagram_pcapng_if { - uint16_t linktype, - reserved; - uint32_t snaplen; -} 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 - */ -#define HEXAGRAM_PCAPNG_OPTION_EPB_FLAGS 2 -#define HEXAGRAM_PCAPNG_OPTION_EPB_HASH 3 -#define HEXAGRAM_PCAPNG_OPTION_EPB_DROPCOUNT 4 - -typedef struct _hexagram_pcapng_packet { - uint32_t interface, - timestamp[2], - caplen, - origlen; -} hexagram_pcapng_packet; +#include +#include +#include +#include +#include +#include +#include /* * pcapng stream reading facilities @@ -127,8 +21,6 @@ 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); diff --git a/include/hexagram/pcapng/block.h b/include/hexagram/pcapng/block.h new file mode 100644 index 0000000..0c6c68d --- /dev/null +++ b/include/hexagram/pcapng/block.h @@ -0,0 +1,23 @@ +#ifndef _HEXAGRAM_PCAPNG_BLOCK_H +#define _HEXAGRAM_PCAPNG_BLOCK_H + +/* + * pcapng block types and structure + */ +typedef enum { + 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 { + uint32_t type, + length; +} hexagram_pcapng_block_header; + +typedef struct _hexagram_pcapng_block_footer { + uint32_t length; +} hexagram_pcapng_block_footer; + +#endif /* _HEXAGRAM_PCAPNG_BLOCK_H */ diff --git a/include/hexagram/pcapng/error.h b/include/hexagram/pcapng/error.h new file mode 100644 index 0000000..1f6109d --- /dev/null +++ b/include/hexagram/pcapng/error.h @@ -0,0 +1,15 @@ +#ifndef _HEXAGRAM_PCAPNG_ERROR_H +#define _HEXAGRAM_PCAPNG_ERROR_H + +/* + * pcapng reader error states + */ +typedef enum { + HEXAGRAM_PCAPNG_ERROR_OK = 0, + HEXAGRAM_PCAPNG_ERROR_IO = 1, + HEXAGRAM_PCAPNG_ERROR_TRUNCATED = 2, + HEXAGRAM_PCAPNG_ERROR_FORMAT = 3, + HEXAGRAM_PCAPNG_ERROR_HANDLER = 4 +} hexagram_pcapng_error; + +#endif /* _HEXAGRAM_PCAPNG_ERROR_H */ diff --git a/include/hexagram/pcapng/if.h b/include/hexagram/pcapng/if.h new file mode 100644 index 0000000..16c8476 --- /dev/null +++ b/include/hexagram/pcapng/if.h @@ -0,0 +1,27 @@ +#ifndef _HEXAGRAM_PCAPNG_IF_H +#define _HEXAGRAM_PCAPNG_IF_H + +/* + * pcapng interface description block structure + */ +#define HEXAGRAM_PCAPNG_OPTION_IF_NAME 2 +#define HEXAGRAM_PCAPNG_OPTION_IF_DESCRIPTION 3 +#define HEXAGRAM_PCAPNG_OPTION_IF_IPV4_ADDR 4 +#define HEXAGRAM_PCAPNG_OPTION_IF_IPV6_ADDR 5 +#define HEXAGRAM_PCAPNG_OPTION_IF_MAC_ADDR 6 +#define HEXAGRAM_PCAPNG_OPTION_IF_EUI_ADDR 7 +#define HEXAGRAM_PCAPNG_OPTION_IF_SPEED 8 +#define HEXAGRAM_PCAPNG_OPTION_IF_TSRESOL 9 +#define HEXAGRAM_PCAPNG_OPTION_IF_TZONE 10 +#define HEXAGRAM_PCAPNG_OPTION_IF_FILTER 11 +#define HEXAGRAM_PCAPNG_OPTION_IF_OS 12 +#define HEXAGRAM_PCAPNG_OPTION_IF_FCSLEN 13 +#define HEXAGRAM_PCAPNG_OPTION_IF_TSOFFSET 14 + +typedef struct _hexagram_pcapng_if { + uint16_t linktype, + reserved; + uint32_t snaplen; +} hexagram_pcapng_if; + +#endif /* _HEXAGRAM_PCAPNG_IF_H */ diff --git a/include/hexagram/pcapng/if_stats.h b/include/hexagram/pcapng/if_stats.h new file mode 100644 index 0000000..794ca8e --- /dev/null +++ b/include/hexagram/pcapng/if_stats.h @@ -0,0 +1,21 @@ +#ifndef _HEXAGRAM_PCAPNG_IF_STATS_H +#define _HEXAGRAM_PCAPNG_IF_STATS_H + +/* + * 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; + +#endif /* _HEXAGRAM_PCAPNG_IF_STATS_H */ diff --git a/include/hexagram/pcapng/option.h b/include/hexagram/pcapng/option.h new file mode 100644 index 0000000..07ef203 --- /dev/null +++ b/include/hexagram/pcapng/option.h @@ -0,0 +1,19 @@ +#ifndef _HEXAGRAM_PCAPNG_OPTION_H +#define _HEXAGRAM_PCAPNG_OPTION_H + +/* + * pcapng block option types and structure + */ +#define HEXAGRAM_PCAPNG_OPTION_END 0x0 +#define HEXAGRAM_PCAPNG_OPTION_COMMENT 0x1 +#define HEXAGRAM_PCAPNG_OPTION_CUSTOM1 0x0bac +#define HEXAGRAM_PCAPNG_OPTION_CUSTOM2 0x0bad +#define HEXAGRAM_PCAPNG_OPTION_CUSTOM3 0x4bac +#define HEXAGRAM_PCAPNG_OPTION_CUSTOM4 0x4bad + +typedef struct _hexagram_pcapng_option { + uint16_t code, + length; +} hexagram_pcapng_option; + +#endif /* _HEXAGRAM_PCAPNG_OPTION_H */ diff --git a/include/hexagram/pcapng/packet.h b/include/hexagram/pcapng/packet.h new file mode 100644 index 0000000..4143c21 --- /dev/null +++ b/include/hexagram/pcapng/packet.h @@ -0,0 +1,18 @@ +#ifndef _HEXAGRAM_PCAPNG_PACKET_H +#define _HEXAGRAM_PCAPNG_PACKET_H + +/* + * pcapng packet block structure + */ +#define HEXAGRAM_PCAPNG_OPTION_EPB_FLAGS 2 +#define HEXAGRAM_PCAPNG_OPTION_EPB_HASH 3 +#define HEXAGRAM_PCAPNG_OPTION_EPB_DROPCOUNT 4 + +typedef struct _hexagram_pcapng_packet { + uint32_t interface, + timestamp[2], + caplen, + origlen; +} hexagram_pcapng_packet; + +#endif /* _HEXAGRAM_PCAPNG_PACKET_H */ diff --git a/include/hexagram/pcapng/section.h b/include/hexagram/pcapng/section.h new file mode 100644 index 0000000..e2539ae --- /dev/null +++ b/include/hexagram/pcapng/section.h @@ -0,0 +1,19 @@ +#ifndef _HEXAGRAM_PCAPNG_SECTION_H +#define _HEXAGRAM_PCAPNG_SECTION_H + +/* + * pcapng section block structure and byte order magic + */ +#define HEXAGRAM_PCAPNG_SECTION_MAGIC 0x1a2b3c4d + +#define HEXAGRAM_PCAPNG_OPTION_SHB_HARDWARE 2 +#define HEXAGRAM_PCAPNG_OPTION_SHB_OS 3 +#define HEXAGRAM_PCAPNG_OPTION_SHB_USERAPPL 4 + +typedef struct _hexagram_pcapng_section { + uint32_t magic; + uint16_t major, minor; + uint64_t length; +} hexagram_pcapng_section; + +#endif /* _HEXAGRAM_PCAPNG_SECTION_H */