]> git.ipfire.org Git - people/ms/libloc.git/blobdiff - src/loc/private.h
Refactor compating IP addresses
[people/ms/libloc.git] / src / loc / private.h
index 2788705ab6f20f903de0d86c4ac8a9988203f69e..7008fdf09e1f9ce9723dc7c0edea55926dcc7835 100644 (file)
@@ -58,7 +58,15 @@ void loc_log(struct loc_ctx *ctx,
        const char *format, ...) __attribute__((format(printf, 6, 7)));
 
 static inline int in6_addr_cmp(const struct in6_addr* a1, const struct in6_addr* a2) {
-       return memcmp(&a1->s6_addr, &a2->s6_addr, sizeof(a1->s6_addr));
+       for (unsigned int i = 0; i < 16; i++) {
+               if (a1->s6_addr[i] > a2->s6_addr[i])
+                       return 1;
+
+               else if (a1->s6_addr[i] < a2->s6_addr[i])
+                       return -1;
+       }
+
+       return 0;
 }
 
 static inline int in6_addr_get_bit(const struct in6_addr* address, unsigned int i) {