Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR #682 stage PR from @halver94 #692

Merged
merged 4 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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