From 6ad9af1a25875bfc3ca29139f8d542c34c84807e Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Sun, 8 Jul 2012 13:24:08 +0200 Subject: [PATCH] Correctly handle a negative log message interval. Signed-off-by: Richard Cochran --- port.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/port.c b/port.c index 989a3b3..e88a7b2 100644 --- a/port.c +++ b/port.c @@ -111,9 +111,15 @@ static void announce_to_dataset(struct ptp_message *m, struct clock *c, static int msg_current(struct ptp_message *m, struct timespec now) { int64_t t1, t2, tmo; + t1 = m->ts.host.tv_sec * NSEC2SEC + m->ts.host.tv_nsec; t2 = now.tv_sec * NSEC2SEC + now.tv_nsec; - tmo = 4 * (1 << m->header.logMessageInterval) * NSEC2SEC; + + if (m->header.logMessageInterval < 0) + tmo = 4LL * NSEC2SEC / (1 << -m->header.logMessageInterval); + else + tmo = 4LL * (1 << m->header.logMessageInterval) * NSEC2SEC; + return t2 - t1 < tmo; }