Fixed segfault bug.
This commit is contained in:
@@ -28,7 +28,7 @@ int hash(void* key) {
|
|||||||
+ (addr & 0xFF000000 >> 24)) % 0xFF;
|
+ (addr & 0xFF000000 >> 24)) % 0xFF;
|
||||||
|
|
||||||
addr = (long)ap->dst.s_addr;
|
addr = (long)ap->dst.s_addr;
|
||||||
hash += ((addr & 0x000000FF)
|
hash = ( hash + (addr & 0x000000FF)
|
||||||
+ (addr & 0x0000FF00 >> 8)
|
+ (addr & 0x0000FF00 >> 8)
|
||||||
+ (addr & 0x00FF0000 >> 16)
|
+ (addr & 0x00FF0000 >> 16)
|
||||||
+ (addr & 0xFF000000 >> 24)) % 0xFF;
|
+ (addr & 0xFF000000 >> 24)) % 0xFF;
|
||||||
|
|||||||
14
hash.c
14
hash.c
@@ -44,12 +44,14 @@ hash_status_enum hash_delete(hash_type* hash_table, void* key) {
|
|||||||
if (!p) return HASH_STATUS_KEY_NOT_FOUND;
|
if (!p) return HASH_STATUS_KEY_NOT_FOUND;
|
||||||
|
|
||||||
/* p designates node to delete, remove it from list */
|
/* p designates node to delete, remove it from list */
|
||||||
if (p0)
|
if (p0) {
|
||||||
/* not first node, p0 points to previous node */
|
/* not first node, p0 points to previous node */
|
||||||
p0->next = p->next;
|
p0->next = p->next;
|
||||||
else
|
}
|
||||||
|
else {
|
||||||
/* first node on chain */
|
/* first node on chain */
|
||||||
hash_table->table[bucket] = p->next;
|
hash_table->table[bucket] = p->next;
|
||||||
|
}
|
||||||
|
|
||||||
hash_table->delete_key(p->key);
|
hash_table->delete_key(p->key);
|
||||||
free (p);
|
free (p);
|
||||||
@@ -62,9 +64,13 @@ hash_status_enum hash_find(hash_type* hash_table, void* key, void **rec) {
|
|||||||
/*******************************
|
/*******************************
|
||||||
* find node containing data *
|
* find node containing data *
|
||||||
*******************************/
|
*******************************/
|
||||||
p = hash_table->table[hash_table->hash(key)];
|
int bucket = hash_table->hash(key);
|
||||||
while (p && !hash_table->compare(p->key, key))
|
|
||||||
|
p = hash_table->table[bucket];
|
||||||
|
|
||||||
|
while (p && !hash_table->compare(p->key, key)) {
|
||||||
p = p->next;
|
p = p->next;
|
||||||
|
}
|
||||||
if (!p) return HASH_STATUS_KEY_NOT_FOUND;
|
if (!p) return HASH_STATUS_KEY_NOT_FOUND;
|
||||||
*rec = p->rec;
|
*rec = p->rec;
|
||||||
return HASH_STATUS_OK;
|
return HASH_STATUS_OK;
|
||||||
|
|||||||
6
iftop.c
6
iftop.c
@@ -96,13 +96,13 @@ void tick(int print) {
|
|||||||
t = time(NULL);
|
t = time(NULL);
|
||||||
if(t - last_timestamp >= RESOLUTION) {
|
if(t - last_timestamp >= RESOLUTION) {
|
||||||
//printf("TICKING\n");
|
//printf("TICKING\n");
|
||||||
analyse_data();
|
analyse_data();
|
||||||
ui_print();
|
ui_print();
|
||||||
history_rotate();
|
history_rotate();
|
||||||
last_timestamp = t;
|
last_timestamp = t;
|
||||||
}
|
}
|
||||||
else if(print) {
|
else if(print) {
|
||||||
ui_print();
|
ui_print();
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_unlock(&tick_mutex);
|
pthread_mutex_unlock(&tick_mutex);
|
||||||
@@ -187,7 +187,7 @@ static void handle_packet(char* args, const struct pcap_pkthdr* pkthdr,const cha
|
|||||||
hash_insert(history, &ap, ht);
|
hash_insert(history, &ap, ht);
|
||||||
}
|
}
|
||||||
|
|
||||||
len = ntohs(iptr->ip_len);
|
len = ntohs(iptr->ip_len);
|
||||||
|
|
||||||
/* Update record */
|
/* Update record */
|
||||||
ht->last_write = history_pos;
|
ht->last_write = history_pos;
|
||||||
|
|||||||
Reference in New Issue
Block a user