Permalink
Browse files

add date format strings to --out

netsniff-ng: add date format strings to --out.

Fixes netsniff-ng#158

This adds the ability to use date(1) style format strings when
specifying an output file.

Example:

netsniff-ng --out %Y-%m-%d.pcap ### outputs to 2018-04-20.pcap

Signed-off-by: Daniel Roberson daniel@planethacker.net
  • Loading branch information...
droberson committed Apr 19, 2018
1 parent 3b282c9 commit d29a8299b9ce895bc1d6cb39b41514fca1504d8d
Showing with 18 additions and 3 deletions.
  1. +18 −3 netsniff-ng.c
View
@@ -23,6 +23,7 @@
#include <pthread.h>
#include <fcntl.h>
#include <inttypes.h>
#include <limits.h>
#include "ring_rx.h"
#include "ring_tx.h"
@@ -793,7 +794,7 @@ static void finish_multi_pcap_file(struct ctx *ctx, int fd)
static int next_multi_pcap_file(struct ctx *ctx, int fd)
{
int ret;
char fname[512];
char fname[PATH_MAX];
time_t ftime;
__pcap_io->fsync_pcap(fd);
@@ -843,7 +844,7 @@ static void reset_interval(struct ctx *ctx)
static int begin_multi_pcap_file(struct ctx *ctx)
{
int fd, ret;
char fname[256];
char fname[PATH_MAX];
bug_on(!__pcap_io);
@@ -887,6 +888,7 @@ static void finish_single_pcap_file(struct ctx *ctx, int fd)
static int begin_single_pcap_file(struct ctx *ctx)
{
int fd, ret;
char fname[PATH_MAX];
bug_on(!__pcap_io);
@@ -896,7 +898,20 @@ static int begin_single_pcap_file(struct ctx *ctx)
if (ctx->pcap == PCAP_OPS_MM)
ctx->pcap = PCAP_OPS_SG;
} else {
fd = open_or_die_m(ctx->device_out,
time_t t;
struct tm *ltm;
t = time(NULL);
if (t == -1)
panic("time() failed\n");
ltm = localtime(&t);
if (ltm == NULL)
panic("localtime() failed\n");
strftime(fname, sizeof(fname), ctx->device_out, ltm);
fd = open_or_die_m(fname,
O_RDWR | O_CREAT | O_TRUNC |
O_LARGEFILE, DEFFILEMODE);
}

0 comments on commit d29a829

Please sign in to comment.