4 * netof - return the net address part of an ip address in a sockaddr_storage structure
10 #include "ntp_stdlib.h"
13 #define NUM_NETOF_BUFS 10
14 static struct sockaddr_storage ssbuf
[NUM_NETOF_BUFS
];
15 static int next_ssbuf
= 0;
17 struct sockaddr_storage
*
19 struct sockaddr_storage
* hostaddr
22 register u_int32 netnum
;
23 struct sockaddr_storage
*netaddr
;
25 netaddr
= &ssbuf
[next_ssbuf
++];
26 if (next_ssbuf
== NUM_NETOF_BUFS
)
28 memcpy(netaddr
, hostaddr
, sizeof(struct sockaddr_storage
));
30 if(netaddr
->ss_family
== AF_INET
) {
31 netnum
= ((struct sockaddr_in
*)netaddr
)->sin_addr
.s_addr
;
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.
39 netnum
&= IN_CLASSC_NET
;
40 else if (IN_CLASSB(netnum
))
41 netnum
&= IN_CLASSB_NET
;
42 ((struct sockaddr_in
*)netaddr
)->sin_addr
.s_addr
= netnum
;
44 else if(netaddr
->ss_family
== AF_INET6
) {
45 /* Here we put 0 at the local link address so we get net address */
46 memset(&((struct sockaddr_in6
*)netaddr
)->sin6_addr
.s6_addr
[8], 0, 8*sizeof(u_char
));