5 #include <netinet/in.h>
6 #include "counter_hash.h"
10 #define hash_table_size 256
12 int counter_hash_compare(void* a, void* b) {
13 return *(long*)a == *(long*)b;
16 int counter_hash_hash(void* key) {
22 hash = ((addr & 0x000000FF)
23 + (addr & 0x0000FF00 >> 8)
24 + (addr & 0x00FF0000 >> 16)
25 + (addr & 0xFF000000 >> 24)
31 void* counter_hash_copy_key(void* orig) {
33 copy = xmalloc(sizeof *copy);
34 *copy = *(struct in_addr*)orig;
38 void counter_hash_delete_key(void* key) {
43 * Allocate and return a hash
45 hash_type* counter_hash_create() {
46 hash_type* hash_table;
47 hash_table = xcalloc(hash_table_size, sizeof *hash_table);
48 hash_table->size = hash_table_size;
49 hash_table->compare = &counter_hash_compare;
50 hash_table->hash = &counter_hash_hash;
51 hash_table->delete_key = &counter_hash_delete_key;
52 hash_table->copy_key = &counter_hash_copy_key;
53 hash_initialise(hash_table);