Skip to content

Commit

Permalink
complete SO_TIMESTAMPNS to SO_TIMESTAMP fallback
Browse files Browse the repository at this point in the history
Commit e866063 added a
fallback from setting the socket option SO_TIMESTAMPNS to
setting the socket option SO_TIMESTAMP if the nanosecond
timestamp option could not be set.  But it did not add
code to also look for the control message related to
SO_TIMESTAMP.  Thus microsecond timestamps were requested,
but not read.

This commit adds the missing code to read microsecond
timestamp control messages.

The problem was reported in GitHub issue schweikert#374 by @payload.
  • Loading branch information
auerswal committed Jan 16, 2025
1 parent cb83286 commit fdd5dee
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Next
====

## Bugfixes and other changes

- Fix fallback to SO\_TIMESTAMP if SO\_TIMESTAMPNS is not available (#375, thanks
@auerswal)

fping 5.3 (2025-01-02)
======================

Expand Down
13 changes: 13 additions & 0 deletions src/fping.c
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,14 @@ static inline int64_t timespec_ns(struct timespec *a)
return ((int64_t)a->tv_sec * 1000000000) + a->tv_nsec;
}

#if HAVE_SO_TIMESTAMPNS
/* convert a struct timeval to nanoseconds */
static inline int64_t timeval_ns(struct timeval *a)
{
return ((int64_t)a->tv_sec * 1000000000) + ((int64_t)a->tv_usec * 1000);
}
#endif /* HAVE_SO_TIMESTAMPNS */

void add_cidr(char *addr)
{
char *addr_end;
Expand Down Expand Up @@ -2105,13 +2113,18 @@ int receive_packet(int64_t wait_time,
/* ancilliary data */
{
struct timespec reply_timestamp_ts;
struct timeval reply_timestamp_tv;
for (cmsg = CMSG_FIRSTHDR(&recv_msghdr);
cmsg != NULL;
cmsg = CMSG_NXTHDR(&recv_msghdr, cmsg)) {
if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_TIMESTAMPNS) {
memcpy(&reply_timestamp_ts, CMSG_DATA(cmsg), sizeof(reply_timestamp_ts));
*reply_timestamp = timespec_ns(&reply_timestamp_ts);
}
if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_TIMESTAMP) {
memcpy(&reply_timestamp_tv, CMSG_DATA(cmsg), sizeof(reply_timestamp_tv));
*reply_timestamp = timeval_ns(&reply_timestamp_tv);
}
}
}
#endif
Expand Down

0 comments on commit fdd5dee

Please sign in to comment.