Skip to content

Commit

Permalink
Bug #844 PR# 846: fix regression on nanosecond timestamp
Browse files Browse the repository at this point in the history
libpcap nanosec values are reported in tv_usec.

Not so for legacy libpcap which has usec values in tv_usec.
  • Loading branch information
fklassen committed Jun 2, 2024
1 parent eaf2622 commit 71058cd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/defines.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,17 @@ typedef u_int8_t uint8_t typedef u_int16_t uint16_t typedef u_int32_t uint32_t
(a)->tv_nsec = (b)->tv_nsec; \
} while (0)

#define TIMEVAL_TO_TIMESPEC_SET(a, b) \
do { \
(a)->tv_sec = (b)->tv_sec; \
(a)->tv_nsec = (b)->tv_usec * 1000; \
} while(0)

/* libpcap puts nanosec values in tv_usec when pcap file is read with nanosec precision*/
#define TIMEVAL_AS_TIMESPEC_SET(a, b) \
do { \
(a)->tv_sec = (b)->tv_sec; \
(a)->tv_nsec = (b)->tv_usec * 1000; \
(a)->tv_nsec = (b)->tv_usec; \
} while(0)

/*
Expand Down
8 changes: 7 additions & 1 deletion src/send_packets.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,13 @@ send_packets(tcpreplay_t *ctx, pcap_t *pcap, int idx)
while (!ctx->abort && read_next_packet &&
(pktdata = get_next_packet(options, pcap, &pkthdr, idx, prev_packet)) != NULL) {
struct timespec pkthdr_ts;
TIMEVAL_AS_TIMESPEC_SET(&pkthdr_ts, &pkthdr.ts); // libpcap puts nanosec values in tv_usec
#ifdef HAVE_PCAP_OPEN_OFFLINE_WITH_TSTAMP_PRECISION
// libpcap puts nanosecond values in tv_usec
TIMEVAL_AS_TIMESPEC_SET(&pkthdr_ts, &pkthdr.ts);
#else
// libpcap puts microsecond values in tv_usec
TIMEVAL_TO_TIMESPEC_SET(&pkthdr_ts, &pkthdr.ts);
#endif
now_is_now = false;
packetnum++;
#if defined TCPREPLAY || defined TCPREPLAY_EDIT
Expand Down

0 comments on commit 71058cd

Please sign in to comment.