static struct function_record *new_record(unsigned long ip) { struct function_record *r = lookup_record(ip); if (r) return r; r = malloc(sizeof *r); memset(r, 0, sizeof *r); r->ip = ip; r->hash_next = fn_hash[hash_ip(ip)]; fn_hash[hash_ip(ip)] = r; return r; }
ip_context* get_ip_context(uint32_t src, uint32_t dst, ip_context **ip_context_list){ //TODO: collision! uint32_t cur_ip_hash = hash_ip(src, dst); if(ip_context_list[cur_ip_hash] == NULL){ ip_context_list[cur_ip_hash] = (ip_context*)malloc(sizeof(ip_context)); ip_context_list[cur_ip_hash]->user_context = (generic_context*)malloc(sizeof(generic_context)); int i; for(i=0; i<COUNT_PROTO; i++){ ip_context_list[cur_ip_hash]->next_context[i] = (void**)calloc(PROTO_HASH_SIZE, sizeof(void*)); } } return ip_context_list[cur_ip_hash]; }
static struct function_record *lookup_record(unsigned long ip) { struct function_record *f = fn_hash[hash_ip(ip)]; while (f && f->ip != ip) f = f->hash_next; return f; }