|
|
| version 1.1, 2012/02/21 16:57:34 | version 1.1.1.2, 2016/10/18 14:04:50 |
|---|---|
| Line 2 | Line 2 |
| #include <stdio.h> | #include <stdio.h> |
| #include <stdlib.h> | #include <stdlib.h> |
| #include <string.h> | |
| #include <sys/types.h> | #include <sys/types.h> |
| #include <sys/socket.h> | #include <sys/socket.h> |
| #include <netinet/in_systm.h> | #include <netinet/in_systm.h> |
| Line 14 | Line 15 |
| #define hash_table_size 256 | #define hash_table_size 256 |
| int ns_hash_compare(void* a, void* b) { | int ns_hash_compare(void* a, void* b) { |
| struct in_addr* aa = (struct in_addr*)a; | struct in6_addr* aa = (struct in6_addr*)a; |
| struct in_addr* bb = (struct in_addr*)b; | struct in6_addr* bb = (struct in6_addr*)b; |
| return (aa->s_addr == bb->s_addr); | return IN6_ARE_ADDR_EQUAL(aa, bb); |
| } | } |
| static int __inline__ hash_uint32(uint32_t n) { | |
| return ((n & 0x000000FF) | |
| + ((n & 0x0000FF00) >> 8) | |
| + ((n & 0x00FF0000) >> 16) | |
| + ((n & 0xFF000000) >> 24)); | |
| } | |
| int ns_hash_hash(void* key) { | int ns_hash_hash(void* key) { |
| int hash; | int hash; |
| long addr; | uint32_t* addr6 = (uint32_t*)((struct in6_addr *) key)->s6_addr; |
| addr = (long)((struct in_addr*)key)->s_addr; | |
| hash = ((addr & 0x000000FF) | hash = ( hash_uint32(addr6[0]) |
| + (addr & 0x0000FF00 >> 8) | + hash_uint32(addr6[1]) |
| + (addr & 0x00FF0000 >> 16) | + hash_uint32(addr6[2]) |
| + (addr & 0xFF000000 >> 24)) % 0xFF; | + hash_uint32(addr6[3])) % 0xFF; |
| return hash; | return hash; |
| } | } |
| void* ns_hash_copy_key(void* orig) { | void* ns_hash_copy_key(void* orig) { |
| struct in_addr* copy; | struct in6_addr* copy; |
| copy = xmalloc(sizeof *copy); | copy = xmalloc(sizeof *copy); |
| *copy = *(struct in_addr*)orig; | memcpy(copy, orig, sizeof *copy); |
| return copy; | return copy; |
| } | } |