2 * netof - return the net address part of an ip address in a sockaddr_storage structure
11 #include "ntp_stdlib.h"
19 static sockaddr_u netofbuf[8];
20 static int next_netofbuf;
24 netaddr = &netofbuf[next_netofbuf];
25 next_netofbuf = (next_netofbuf + 1) % COUNTOF(netofbuf);
27 memcpy(netaddr, hostaddr, sizeof(*netaddr));
29 if (IS_IPV4(netaddr)) {
30 netnum = SRCADR(netaddr);
33 * We live in a modern CIDR world where the basement nets, which
34 * used to be class A, are now probably associated with each
35 * host address. So, for class-A nets, all bits are significant.
37 if (IN_CLASSC(netnum))
38 netnum &= IN_CLASSC_NET;
39 else if (IN_CLASSB(netnum))
40 netnum &= IN_CLASSB_NET;
42 SET_ADDR4(netaddr, netnum);
44 } else if (IS_IPV6(netaddr))
45 /* assume the typical /64 subnet size */
46 zero_mem(&NSRCADR6(netaddr)[8], 8);
49 msyslog(LOG_ERR, "netof unknown AF %d", AF(netaddr));