From c102a69a3a566c50799672df21e0a05242c7c650 Mon Sep 17 00:00:00 2001 From: naddy <> Date: Tue, 10 Jun 2008 03:51:53 +0000 Subject: [PATCH] For IPv6 addresses, return the first 32 bits of the MD5 hash of the address as ref ID (RFC4330). ok henning@ --- src/usr.sbin/ntpd/client.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/usr.sbin/ntpd/client.c b/src/usr.sbin/ntpd/client.c index 92a5199d..bf374510 100644 --- a/src/usr.sbin/ntpd/client.c +++ b/src/usr.sbin/ntpd/client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: client.c,v 1.80 2008/06/10 03:46:09 naddy Exp $ */ +/* $OpenBSD: client.c,v 1.81 2008/06/10 03:51:53 naddy Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -267,10 +268,20 @@ client_dispatch(struct ntp_peer *p, u_int8_t settime) p->reply[p->shift].status.poll = msg.ppoll; p->reply[p->shift].status.stratum = msg.stratum; - if (p->addr->ss.ss_family == AF_INET) + if (p->addr->ss.ss_family == AF_INET) { p->reply[p->shift].status.send_refid = ((struct sockaddr_in *)&p->addr->ss)->sin_addr.s_addr; - else + } else if (p->addr->ss.ss_family == AF_INET6) { + MD5_CTX context; + u_int8_t digest[MD5_DIGEST_LENGTH]; + + MD5Init(&context); + MD5Update(&context, ((struct sockaddr_in6 *)&p->addr->ss)-> + sin6_addr.s6_addr, sizeof(struct in6_addr)); + MD5Final(digest, &context); + memcpy((char *)&p->reply[p->shift].status.send_refid, digest, + sizeof(u_int32_t)); + } else p->reply[p->shift].status.send_refid = msg.xmttime.fractionl; if (p->trustlevel < TRUSTLEVEL_PATHETIC)