From b295df24b50fe0d6ccf8aa224458182a926a4803 Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Fri, 5 Dec 2014 23:44:38 +0100 Subject: [PATCH] Introduce a helper function to identify valid (non-zero) time stamps. Signed-off-by: Richard Cochran --- msg.c | 2 +- msg.h | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/msg.c b/msg.c index 7edbdd2..06a3812 100644 --- a/msg.c +++ b/msg.c @@ -468,5 +468,5 @@ int msg_sots_missing(struct ptp_message *m) default: return 0; } - return (!m->hwts.ts.tv_sec && !m->hwts.ts.tv_nsec) ? 1 : 0; + return msg_sots_valid(m) ? 0 : 1; } diff --git a/msg.h b/msg.h index 3fa5833..12e6ce8 100644 --- a/msg.h +++ b/msg.h @@ -338,6 +338,16 @@ void msg_put(struct ptp_message *m); */ int msg_sots_missing(struct ptp_message *m); +/** + * Test whether a message has a valid SO_TIMESTAMPING time stamp. + * @param m Message to test. + * @return One if the message has a valid time stamp, zero otherwise. + */ +static inline int msg_sots_valid(struct ptp_message *m) +{ + return (m->hwts.ts.tv_sec || m->hwts.ts.tv_nsec) ? 1 : 0; +} + /** * Work around buggy 802.1AS switches. */