hmmst, gotta handle another block type we encountered

This commit is contained in:
XANTRONIX Development 2019-01-07 01:00:44 -06:00
parent bc62f8b3c9
commit 58b1ea1b60
2 changed files with 56 additions and 5 deletions

View file

@ -35,7 +35,8 @@ typedef struct _hexagram_pcapng_option {
*/ */
typedef enum { typedef enum {
HEXAGRAM_PCAPNG_BLOCK_SECTION = 0x0a0d0d0a, HEXAGRAM_PCAPNG_BLOCK_SECTION = 0x0a0d0d0a,
HEXAGRAM_PCAPNG_BLOCK_INTERFACE = 0x1, HEXAGRAM_PCAPNG_BLOCK_IF = 0x1,
HEXAGRAM_PCAPNG_BLOCK_IF_STATS = 0x5,
HEXAGRAM_PCAPNG_BLOCK_PACKET = 0x6 HEXAGRAM_PCAPNG_BLOCK_PACKET = 0x6
} hexagram_pcapng_block_type; } hexagram_pcapng_block_type;
@ -80,11 +81,28 @@ typedef struct _hexagram_pcapng_section {
#define HEXAGRAM_PCAPNG_OPTION_IF_FCSLEN 13 #define HEXAGRAM_PCAPNG_OPTION_IF_FCSLEN 13
#define HEXAGRAM_PCAPNG_OPTION_IF_TSOFFSET 14 #define HEXAGRAM_PCAPNG_OPTION_IF_TSOFFSET 14
typedef struct _hexagram_pcapng_interface { typedef struct _hexagram_pcapng_if {
uint16_t linktype, uint16_t linktype,
reserved; reserved;
uint32_t snaplen; 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 * pcapng packet block structure
@ -100,12 +118,21 @@ typedef struct _hexagram_pcapng_packet {
origlen; origlen;
} hexagram_pcapng_packet; } hexagram_pcapng_packet;
/*
* pcapng stream reading facilities
*/
typedef struct _hexagram_pcapng_stream hexagram_pcapng_stream;
typedef int (hexagram_pcapng_block_handler)(int fd, typedef int (hexagram_pcapng_block_handler)(int fd,
uint32_t type, uint32_t type,
size_t length); size_t length);
ssize_t hexagram_pcapng_stream_read(int fd, ssize_t hexagram_pcapng_stream_read(int fd,
hexagram_pcapng_block_handler *handler, hexagram_pcapng_block_handler *handler,
int *error); int *error);
#endif /* _HEXAGRAM_PCAPNG_H */ #endif /* _HEXAGRAM_PCAPNG_H */

View file

@ -1,3 +1,4 @@
#include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
@ -6,6 +7,29 @@
#include <hexagram/pcapng.h> #include <hexagram/pcapng.h>
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) ssize_t hexagram_pcapng_stream_read(fd, handler, error)
int fd; int fd;
hexagram_pcapng_block_handler *handler; hexagram_pcapng_block_handler *handler;