Commit 33329637 authored by Joanne Hugé's avatar Joanne Hugé

Compare txtime to timestamp

parent c7ca3220
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <error.h> #include <error.h>
#include <fcntl.h> #include <fcntl.h>
#include <ifaddrs.h> #include <ifaddrs.h>
#include <inttypes.h>
#include <linux/errqueue.h> #include <linux/errqueue.h>
#include <linux/ethtool.h> #include <linux/ethtool.h>
#include <linux/net_tstamp.h> #include <linux/net_tstamp.h>
...@@ -41,8 +42,8 @@ ...@@ -41,8 +42,8 @@
#define MESSAGE ((uint32_t)0x00FACADE) #define MESSAGE ((uint32_t)0x00FACADE)
#define NSEC_PER_SEC 1000000000 #define NSEC_PER_SEC 1000000000
static void print_timestamps(struct msghdr *msg); static void print_timestamps(struct msghdr *msg, uint64_t txtime);
static void process_timestamps(); static void process_timestamps(uint64_t txtime);
static int so_priority = 3; static int so_priority = 3;
static struct sock_txtime sk_txtime; static struct sock_txtime sk_txtime;
...@@ -160,17 +161,16 @@ void send_udp_packet(int use_etf, int use_timestamps, uint64_t txtime, ...@@ -160,17 +161,16 @@ void send_udp_packet(int use_etf, int use_timestamps, uint64_t txtime,
if (sendmsgerr < 0) if (sendmsgerr < 0)
error(EXIT_FAILURE, errno, "sendmsg failed, ret value: %d\n", sendmsgerr); error(EXIT_FAILURE, errno, "sendmsg failed, ret value: %d\n", sendmsgerr);
if(use_timestamps) { if (use_timestamps) {
res = poll(&poll_fd, 1, 0); res = poll(&poll_fd, 1, 0);
if (res > 0) if (res > 0)
process_timestamps(); process_timestamps(txtime);
else else
fprintf(stderr, "select failed\n"); fprintf(stderr, "select failed\n");
} }
} }
static void process_timestamps() { static void process_timestamps(uint64_t txtime) {
char data[256]; char data[256];
struct msghdr msg; struct msghdr msg;
struct iovec entry; struct iovec entry;
...@@ -192,13 +192,12 @@ static void process_timestamps() { ...@@ -192,13 +192,12 @@ static void process_timestamps() {
if (recvmsg(fd, &msg, MSG_ERRQUEUE | MSG_DONTWAIT) == -1) { if (recvmsg(fd, &msg, MSG_ERRQUEUE | MSG_DONTWAIT) == -1) {
fprintf(stderr, "recvmsg failed\n"); fprintf(stderr, "recvmsg failed\n");
} } else {
else { print_timestamps(&msg, txtime);
print_timestamps(&msg);
} }
} }
static void print_timestamps(struct msghdr *msg) { static void print_timestamps(struct msghdr *msg, uint64_t txtime) {
struct cmsghdr *cmsg; struct cmsghdr *cmsg;
for (cmsg = CMSG_FIRSTHDR(msg); cmsg; cmsg = CMSG_NXTHDR(msg, cmsg)) { for (cmsg = CMSG_FIRSTHDR(msg); cmsg; cmsg = CMSG_NXTHDR(msg, cmsg)) {
...@@ -208,8 +207,11 @@ static void print_timestamps(struct msghdr *msg) { ...@@ -208,8 +207,11 @@ static void print_timestamps(struct msghdr *msg) {
switch (cmsg->cmsg_type) { switch (cmsg->cmsg_type) {
case SO_TIMESTAMPING: { case SO_TIMESTAMPING: {
struct timespec *stamp = (struct timespec *)CMSG_DATA(cmsg); struct timespec *stamp = (struct timespec *)CMSG_DATA(cmsg);
uint64_t timestamp_ns =
stamp->tv_sec * NSEC_PER_SEC + stamp->tv_nsec;
printf("SO_TIMESTAMPING "); printf("SO_TIMESTAMPING ");
printf("SW %ld.%09ld ", (long)stamp->tv_sec, (long)stamp->tv_nsec); printf("SW %" PRIu64 " - %" PRIu64 " (%" PRIi64 ") ", timestamp_ns,
txtime, ((int64_t)timestamp_ns) - txtime);
break; break;
} }
default: default:
...@@ -246,7 +248,6 @@ static int process_socket_error_queue() { ...@@ -246,7 +248,6 @@ static int process_socket_error_queue() {
.msg_control = msg_control, .msg_control = msg_control,
.msg_controllen = sizeof(msg_control)}; .msg_controllen = sizeof(msg_control)};
if (recvmsg(fd, &msg, MSG_ERRQUEUE) == -1) { if (recvmsg(fd, &msg, MSG_ERRQUEUE) == -1) {
fprintf(stderr, "recvmsg failed"); fprintf(stderr, "recvmsg failed");
return -1; return -1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment