From: Michael Tremer Date: Tue, 30 Jan 2018 23:28:21 +0000 (+0000) Subject: Refactor compating IP addresses X-Git-Tag: 0.9.0~85 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e14564aa73ca484094414db249b77dea80c800ed;p=people%2Fms%2Flibloc.git Refactor compating IP addresses memcmp does not seem to be the best choice here. This function is a naive implementation but does the job very well. Signed-off-by: Michael Tremer --- diff --git a/src/loc/private.h b/src/loc/private.h index 2788705..7008fdf 100644 --- a/src/loc/private.h +++ b/src/loc/private.h @@ -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) {