Skip to content

Commit

Permalink
pcap: Replace ':' with '_' in pcap file name timestamp
Browse files Browse the repository at this point in the history
It turns out scp misinteprets the ':' in file name to be the begining of
the path name after the host. Although this can be fixed with some quote
magic, it's too much to expect our users to know about it.

Signed-off-by: Siddharth Chandrasekaran <[email protected]>
  • Loading branch information
sidcha committed Feb 21, 2024
1 parent 17a56c2 commit c08e7c0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
21 changes: 16 additions & 5 deletions src/osdp_pcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,27 @@

#include "osdp_common.h"

static void pcap_file_name(struct osdp_pd *pd, char *buf, size_t size)
{
int n;
char *p;

n = snprintf(buf, size, "osdp-trace-%spd-%d-",
is_pd_mode(pd) ? "" : "cp-", pd->address);
n += add_iso8601_utc_datetime(buf + n, size - n);
strcpy(buf + n, ".pcap");

while ((p = strchr(buf, ":")) == NULL) {
*p = "_";
}
}

void osdp_packet_capture_init(struct osdp_pd *pd)
{
pcap_t *cap;
int n;
char path[128];

n = snprintf(path, sizeof(path), "osdp-trace-%spd-%d-",
is_pd_mode(pd) ? "" : "cp-", pd->address);
n += add_iso8601_utc_datetime(path + n, sizeof(path) - n);
strcpy(path + n, ".pcap");
pcap_file_name(pd, path, sizeof(path));
cap = pcap_start(path, OSDP_PACKET_BUF_SIZE, OSDP_PCAP_LINK_TYPE);
if (cap) {
LOG_WRN("Capturing packets to '%s'", path);
Expand Down
2 changes: 1 addition & 1 deletion src/osdp_phy.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ static int phy_check_packet(struct osdp_pd *pd, uint8_t *buf, int pkt_len)
}
cur = osdp_phy_get_seq_number(pd, is_pd_mode(pd));
if (cur != comp && !ISSET_FLAG(pd, PD_FLAG_SKIP_SEQ_CHECK)) {
LOG_ERR("packet seq mismatch %d/%d", cur, comp);
LOG_ERR("Packet sequence mismatch %d/%d", cur, comp);
pd->reply_id = REPLY_NAK;
pd->ephemeral_data[0] = OSDP_PD_NAK_SEQ_NUM;
return OSDP_ERR_PKT_NACK;
Expand Down

0 comments on commit c08e7c0

Please sign in to comment.