7 #include <sys/socket.h>
8 #include <netinet/in_systm.h>
9 #include <netinet/in.h>
10 #include <arpa/inet.h>
15 #define hash_table_size 256
17 int ns_hash_compare(void* a, void* b) {
18 struct in6_addr* aa = (struct in6_addr*)a;
19 struct in6_addr* bb = (struct in6_addr*)b;
20 return IN6_ARE_ADDR_EQUAL(aa, bb);
23 static int __inline__ hash_uint32(uint32_t n) {
24 return ((n & 0x000000FF)
25 + ((n & 0x0000FF00) >> 8)
26 + ((n & 0x00FF0000) >> 16)
27 + ((n & 0xFF000000) >> 24));
30 int ns_hash_hash(void* key) {
32 uint32_t* addr6 = (uint32_t*)((struct in6_addr *) key)->s6_addr;
34 hash = ( hash_uint32(addr6[0])
35 + hash_uint32(addr6[1])
36 + hash_uint32(addr6[2])
37 + hash_uint32(addr6[3])) % 0xFF;
42 void* ns_hash_copy_key(void* orig) {
43 struct in6_addr* copy;
45 copy = xmalloc(sizeof *copy);
46 memcpy(copy, orig, sizeof *copy);
51 void ns_hash_delete_key(void* key) {
56 * Allocate and return a hash
58 hash_type* ns_hash_create() {
59 hash_type* hash_table;
60 hash_table = xcalloc(hash_table_size, sizeof *hash_table);
61 hash_table->size = hash_table_size;
62 hash_table->compare = &ns_hash_compare;
63 hash_table->hash = &ns_hash_hash;
64 hash_table->delete_key = &ns_hash_delete_key;
65 hash_table->copy_key = &ns_hash_copy_key;
66 hash_initialise(hash_table);