diff options
author | roberto <roberto@FreeBSD.org> | 2004-07-20 15:01:56 +0000 |
---|---|---|
committer | roberto <roberto@FreeBSD.org> | 2004-07-20 15:01:56 +0000 |
commit | 118e757284cbb8fc4f43a713e892b41504b50a5f (patch) | |
tree | 528d12dda44ebdc3ffcc38050f159ac553a69c17 /contrib/ntp/libntp/netof.c | |
parent | a85d9ae25e8e8696677bc30feb6eaf7fc150e529 (diff) | |
download | FreeBSD-src-118e757284cbb8fc4f43a713e892b41504b50a5f.zip FreeBSD-src-118e757284cbb8fc4f43a713e892b41504b50a5f.tar.gz |
Virgin import of ntpd 4.2.0
Diffstat (limited to 'contrib/ntp/libntp/netof.c')
-rw-r--r-- | contrib/ntp/libntp/netof.c | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/contrib/ntp/libntp/netof.c b/contrib/ntp/libntp/netof.c index df7657e..fd57568 100644 --- a/contrib/ntp/libntp/netof.c +++ b/contrib/ntp/libntp/netof.c @@ -1,25 +1,48 @@ /* - * netof - return the net address part of an ip address + * netof - return the net address part of an ip address in a sockaddr_storage structure * (zero out host part) */ #include <stdio.h> #include "ntp_fp.h" #include "ntp_stdlib.h" +#include "ntp.h" -u_int32 +#define NUM_NETOF_BUFS 10 +static struct sockaddr_storage ssbuf[NUM_NETOF_BUFS]; +static int next_ssbuf = 0; + +struct sockaddr_storage* netof( - u_int32 num + struct sockaddr_storage* hostaddr ) { register u_int32 netnum; + struct sockaddr_storage *netaddr; + + netaddr = &ssbuf[next_ssbuf++]; + if (next_ssbuf == NUM_NETOF_BUFS) + next_ssbuf = 0; + memcpy(netaddr, hostaddr, sizeof(struct sockaddr_storage)); + + if(netaddr->ss_family == AF_INET) { + netnum = ((struct sockaddr_in*)netaddr)->sin_addr.s_addr; + + /* + * We live in a modern CIDR world where the basement nets, which + * used to be class A, are now probably associated with each + * host address. So, for class-A nets, all bits are significant. + */ + if(IN_CLASSC(netnum)) + netnum &= IN_CLASSC_NET; + else if (IN_CLASSB(netnum)) + netnum &= IN_CLASSB_NET; + ((struct sockaddr_in*)netaddr)->sin_addr.s_addr = netnum; + } + else if(netaddr->ss_family == AF_INET6) { + /* Here we put 0 at the local link address so we get net address */ + memset(&((struct sockaddr_in6*)netaddr)->sin6_addr.s6_addr[8], 0, 8*sizeof(u_char)); + } - netnum = num; - if(IN_CLASSC(netnum)) - netnum &= IN_CLASSC_NET; - else if (IN_CLASSB(netnum)) - netnum &= IN_CLASSB_NET; - else /* treat all other like class A */ - netnum &= IN_CLASSA_NET; - return netnum; + return netaddr; } |