]> git.ipfire.org Git - location/libloc.git/blobdiff - src/loc/private.h
database: Implement lookup
[location/libloc.git] / src / loc / private.h
index 19e0398e5cd16f9e26f46455b011a7704b98cd44..e7ed0f448cdbac71b93f1dd690cc84bcb15b3582 100644 (file)
@@ -19,6 +19,7 @@
 
 #ifdef LIBLOC_PRIVATE
 
+#include <netinet/in.h>
 #include <stdbool.h>
 #include <syslog.h>
 
@@ -56,5 +57,17 @@ void loc_log(struct loc_ctx *ctx,
        int priority, const char *file, int line, const char *fn,
        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, &a1->s6_addr, sizeof(a1->s6_addr));
+}
+
+static inline int in6_addr_get_bit(const struct in6_addr* address, unsigned int i) {
+       return ((address->s6_addr[i / 8] >> (i % 8)) & 1);
+}
+
+static inline void in6_addr_set_bit(struct in6_addr* address, unsigned int i, unsigned int val) {
+       address->s6_addr[i / 8] ^= (-val ^ address->s6_addr[i / 8]) & (1 << (i % 8));
+}
+
 #endif
 #endif