Skip to content

Commit

Permalink
Write PCAPs without using libnet
Browse files Browse the repository at this point in the history
Issue:		droe#234
  • Loading branch information
droe committed Oct 11, 2018
1 parent e6f2a87 commit e072333
Show file tree
Hide file tree
Showing 2 changed files with 264 additions and 97 deletions.
26 changes: 1 addition & 25 deletions log.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,6 @@ static logger_t *content_file_log = NULL;
static int content_pcap_clisock = -1;
static logger_t *content_pcap_log = NULL;
static logger_t *content_mirror_log = NULL;
libnet_t *content_pcap_libnet = NULL;
libnet_t *content_mirror_libnet = NULL;
static uint8_t content_pcap_src_ether[ETHER_ADDR_LEN] = {
0x02, 0x00, 0x00, 0x11, 0x11, 0x11};
Expand Down Expand Up @@ -704,7 +703,7 @@ log_content_open(log_content_ctx_t *ctx, opts_t *opts,
memset(ctx->pcap, 0, sizeof(log_content_pcap_ctx_t));

if (logpkt_ctx_init(&ctx->pcap->state,
content_pcap_libnet,
NULL,
content_pcap_src_ether,
content_pcap_dst_ether,
srchost, srcport,
Expand Down Expand Up @@ -1129,26 +1128,6 @@ static char *content_pcap_fn = NULL;
static int
log_content_pcap_preinit(const char *pcapfile)
{
char errbuf[LIBNET_ERRBUF_SIZE];

#ifdef LIBNET_NONE
content_pcap_libnet = libnet_init(LIBNET_NONE, NULL, errbuf);
#else /* !LIBNET_NONE */
/* Old versions of libnet do not support LIBNET_NONE; on those, we use
* LIBNET_LINK, which has the unfortunate side-effect of needlessly
* opening a raw socket, which requires root privileges. Also, the
* type of link layer encapsulation generated by this libnet instance
* will depend on the active network interface chosen by libnet for the
* raw socket, which may result in uncommon link encapsulations being
* used for the PCAP files written. */
content_pcap_libnet = libnet_init(LIBNET_LINK, NULL, errbuf);
#endif /* !LIBNET_NONE */
if (content_pcap_libnet == NULL) {
log_err_printf("Failed to init pcap libnet: %s\n", errbuf);
return -1;
}
libnet_seed_prand(content_pcap_libnet);

if (!pcapfile)
return 0;

Expand Down Expand Up @@ -1190,9 +1169,6 @@ log_content_pcap_fini(void)
close(content_pcap_fd);
content_pcap_fd = -1;
}
if (content_pcap_libnet) {
libnet_destroy(content_pcap_libnet);
}
}

static int
Expand Down
Loading

0 comments on commit e072333

Please sign in to comment.