summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/sp_network_utils.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/sp_network_utils.c b/src/sp_network_utils.c
index 206ae5b..6fc0b1f 100644
--- a/src/sp_network_utils.c
+++ b/src/sp_network_utils.c
@@ -23,28 +23,30 @@ static inline bool cidr4_match(const struct in_addr addr,
23 23
24static inline bool cidr6_match(const struct in6_addr address, 24static inline bool cidr6_match(const struct in6_addr address,
25 const struct in6_addr network, uint8_t bits) { 25 const struct in6_addr network, uint8_t bits) {
26 //#ifdef LINUX 26#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
27 const uint32_t *a = address.s6_addr32;
28 const uint32_t *n = network.s6_addr32;
29 /*
30#else
31 const uint32_t *a = address.__u6_addr.__u6_addr32; 27 const uint32_t *a = address.__u6_addr.__u6_addr32;
32 const uint32_t *n = network.__u6_addr.__u6_addr32; 28 const uint32_t *n = network.__u6_addr.__u6_addr32;
29#else
30 const uint32_t *a = address.s6_addr32;
31 const uint32_t *n = network.s6_addr32;
33#endif 32#endif
34*/ 33
35 int bits_whole = bits >> 5; // number of whole u32 34 int bits_whole = bits >> 5; // number of whole u32
36 int bits_incomplete = bits & 0x1F; // number of bits in incomplete u32 35 int bits_incomplete = bits & 0x1F; // number of bits in incomplete u32
36
37 if (bits_whole) { 37 if (bits_whole) {
38 if (memcmp(a, n, bits_whole << 2)) { 38 if (memcmp(a, n, bits_whole << 2)) {
39 return false; 39 return false;
40 } 40 }
41 } 41 }
42
42 if (bits_incomplete) { 43 if (bits_incomplete) {
43 uint32_t mask = htonl((0xFFFFFFFFu) << (32 - bits_incomplete)); 44 uint32_t mask = htonl((0xFFFFFFFFu) << (32 - bits_incomplete));
44 if ((a[bits_whole] ^ n[bits_whole]) & mask) { 45 if ((a[bits_whole] ^ n[bits_whole]) & mask) {
45 return false; 46 return false;
46 } 47 }
47 } 48 }
49
48 return true; 50 return true;
49} 51}
50 52