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