aboutgitcodebugslistschat
path: root/pcap.c
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2021-08-12 15:42:43 +0200
committerStefano Brivio <sbrivio@redhat.com>2021-09-01 17:00:27 +0200
commit1e49d194d01788afbc4b8216e27c794651a4facf (patch)
tree3397d4b687a74fe9552e057138c3a795917a5afa /pcap.c
parent1b1b27c06a27067a7d7a380f1df545e72268c411 (diff)
downloadpasst-1e49d194d01788afbc4b8216e27c794651a4facf.tar
passt-1e49d194d01788afbc4b8216e27c794651a4facf.tar.gz
passt-1e49d194d01788afbc4b8216e27c794651a4facf.tar.bz2
passt-1e49d194d01788afbc4b8216e27c794651a4facf.tar.lz
passt-1e49d194d01788afbc4b8216e27c794651a4facf.tar.xz
passt-1e49d194d01788afbc4b8216e27c794651a4facf.tar.zst
passt-1e49d194d01788afbc4b8216e27c794651a4facf.zip
passt, pasta: Introduce command-line options and port re-mapping
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'pcap.c')
-rw-r--r--pcap.c60
1 files changed, 21 insertions, 39 deletions
diff --git a/pcap.c b/pcap.c
index 90529ec..43474da 100644
--- a/pcap.c
+++ b/pcap.c
@@ -24,14 +24,13 @@
#include <fcntl.h>
#include <time.h>
#include <net/ethernet.h>
+#include <netinet/in.h>
#include <unistd.h>
#include <net/if.h>
#include "util.h"
#include "passt.h"
-#ifdef DEBUG
-
#define PCAP_PREFIX "/tmp/passt_"
#define PCAP_PREFIX_PASTA "/tmp/pasta_"
#define PCAP_ISO8601_FORMAT "%FT%H:%M:%SZ"
@@ -165,52 +164,35 @@ void pcap_init(struct ctx *c, int index)
if (pcap_fd != -1)
close(pcap_fd);
- if (c->mode == MODE_PASTA)
- memcpy(name, PCAP_PREFIX_PASTA, sizeof(PCAP_PREFIX_PASTA));
+ if (!*c->pcap)
+ return;
- gettimeofday(&tv, NULL);
- tm = localtime(&tv.tv_sec);
- strftime(name + strlen(PCAP_PREFIX), sizeof(PCAP_ISO8601_STR) - 1,
- PCAP_ISO8601_FORMAT, tm);
+ if (*c->pcap == 1) {
+ if (c->mode == MODE_PASTA)
+ memcpy(name, PCAP_PREFIX_PASTA,
+ sizeof(PCAP_PREFIX_PASTA));
- snprintf(name + strlen(PCAP_PREFIX) + strlen(PCAP_ISO8601_STR),
- sizeof(name) - strlen(PCAP_PREFIX) - strlen(PCAP_ISO8601_STR),
- "_%i.pcap", index);
+ gettimeofday(&tv, NULL);
+ tm = localtime(&tv.tv_sec);
+ strftime(name + strlen(PCAP_PREFIX),
+ sizeof(PCAP_ISO8601_STR) - 1, PCAP_ISO8601_FORMAT, tm);
+
+ snprintf(name + strlen(PCAP_PREFIX) + strlen(PCAP_ISO8601_STR),
+ sizeof(name) - strlen(PCAP_PREFIX) -
+ strlen(PCAP_ISO8601_STR),
+ "_%i.pcap", index);
+
+ strncpy(c->pcap, name, PATH_MAX);
+ }
- pcap_fd = open(name, O_WRONLY | O_CREAT | O_APPEND | O_DSYNC,
+ pcap_fd = open(c->pcap, O_WRONLY | O_CREAT | O_TRUNC | O_DSYNC,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (pcap_fd == -1) {
perror("open");
return;
}
- info("Saving packet capture at %s", name);
+ info("Saving packet capture at %s", c->pcap);
write(pcap_fd, &pcap_hdr, sizeof(pcap_hdr));
}
-
-#else /* DEBUG */
-void pcap(char *pkt, size_t len)
-{
- (void)pkt;
- (void)len;
-}
-
-void pcapm(struct msghdr *mh)
-{
- (void)mh;
-}
-
-void pcapmm(struct mmsghdr *mmh, unsigned int vlen)
-{
- (void)mmh;
- (void)vlen;
-}
-
-void pcap_init(struct ctx *c, int sock_index)
-{
- (void)c;
- (void)sock_index;
-
-}
-#endif