Skip to content

Commit

Permalink
Merge pull request #692 from appneta/PR_#682_stage_pr_from_halver94
Browse files Browse the repository at this point in the history
PR #682 stage PR from @halver94
  • Loading branch information
fklassen authored Jan 25, 2022
2 parents 2f72123 + 00c57ed commit 017b7ff
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 11 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
06/19/2021 Version 4.4.0-beta1
- add a security policy document (#689)
- ability to specify directory of pcap files (#682)
- option --skipbroadcast not working (#677)
- add feature VLAN Q-in-Q (#625)

Expand Down
3 changes: 3 additions & 0 deletions docs/CREDIT
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,6 @@ Dave Craig <GitHub @davecraig>

Vincent Bernat <GitHub @vincentbernat>
- tcprewrite: fix DLT name for DLT_C_JNPR_ETHER in documentation

Halver <GigHub @Halver>
- specify directories as files
51 changes: 41 additions & 10 deletions src/tcpreplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <fts.h>
#include <unistd.h>
#include <errno.h>

Expand Down Expand Up @@ -108,23 +108,54 @@ main(int argc, char *argv[])
notice("File Cache is enabled");
}

/*
* Check if remaining args are directories or files
*/
for (i = 0; i < argc; i++) {
struct stat statbuf;
if (stat(argv[i], &statbuf) != 0) {
errx(-1,
"Unable to retrieve informations from file %s: %s",
argv[i],
strerror(errno));
}

/* If it is a directory, walk the file tree and treat only pcap files */
if (S_ISDIR(statbuf.st_mode)) {
FTSENT *entry = NULL;
FTS *fts = fts_open(&argv[i], FTS_NOCHDIR | FTS_LOGICAL, NULL);
if (fts == NULL) {
errx(-1, "Unable to open %s", argv[1]);
}

while ((entry = fts_read(fts)) != NULL) {
switch (entry->fts_info) {
case FTS_F:
if (entry->fts_path) {
tcpreplay_add_pcapfile(ctx, entry->fts_path);
}
break;
default:
break;
}
}

fts_close(fts);
} else {
tcpreplay_add_pcapfile(ctx, argv[i]);
}
}

/*
* Setup up the file cache, if required
*/
if (ctx->options->preload_pcap) {
/* Initialize each of the file cache structures */
for (i = 0; i < argc; i++) {
for (i = 0; i < ctx->options->source_cnt; i++) {
ctx->options->file_cache[i].index = i;
ctx->options->file_cache[i].cached = FALSE;
ctx->options->file_cache[i].packet_cache = NULL;
}
}

for (i = 0; i < argc; i++) {
tcpreplay_add_pcapfile(ctx, argv[i]);

/* preload our pcap file? */
if (ctx->options->preload_pcap) {
/* preload our pcap file */
preload_pcap_file(ctx, i);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/tcpreplay_opts.def
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ gnu-usage;
help-value = "H";
save-opts-value = "";
load-opts-value = "";
argument = "<pcap_file(s)>";
argument = "<pcap_file(s)> | <pcap_dir(s)>";


config-header = "config.h";
Expand Down

0 comments on commit 017b7ff

Please sign in to comment.