From 2fd7012129ac64b99e64cddee6b3697f4adb76d1 Mon Sep 17 00:00:00 2001 From: pdw <> Date: Thu, 5 Feb 2004 22:58:06 +0000 Subject: [PATCH] Fixes for type-punned pointers - Henne Vogelsang --- iftop.c | 6 +++++- resolver.c | 12 ++++++++++-- ui.c | 13 +++++++++++-- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/iftop.c b/iftop.c index a3a6523..6dc8a8f 100644 --- a/iftop.c +++ b/iftop.c @@ -187,6 +187,10 @@ static void handle_ip_packet(struct ip* iptr, int hw_dir) { int direction = 0; /* incoming */ history_type* ht; + union { + history_type **ht_pp; + void **void_pp; + } u_ht = { &ht }; addr_pair ap; int len; @@ -261,7 +265,7 @@ static void handle_ip_packet(struct ip* iptr, int hw_dir) resolve(&iptr->ip_dst, NULL, 0); resolve(&iptr->ip_src, NULL, 0); - if(hash_find(history, &ap, (void**)&ht) == HASH_STATUS_KEY_NOT_FOUND) { + if(hash_find(history, &ap, u_ht.void_pp) == HASH_STATUS_KEY_NOT_FOUND) { ht = history_create(); hash_insert(history, &ap, ht); } diff --git a/resolver.c b/resolver.c index d051b25..3754654 100644 --- a/resolver.c +++ b/resolver.c @@ -392,7 +392,11 @@ void resolver_worker(void* ptr) { if(hostname != NULL) { char* old; - if(hash_find(ns_hash, &addr, (void**)&old) == HASH_STATUS_OK) { + union { + char **ch_pp; + void **void_pp; + } u_old = { &old }; + if(hash_find(ns_hash, &addr, u_old.void_pp) == HASH_STATUS_OK) { hash_delete(ns_hash, &addr); xfree(old); } @@ -424,13 +428,17 @@ void resolver_initialise() { void resolve(struct in_addr* addr, char* result, int buflen) { char* hostname; + union { + char **ch_pp; + void **void_pp; + } u_hostname = { &hostname }; int added = 0; if(options.dnsresolution == 1) { pthread_mutex_lock(&resolver_queue_mutex); - if(hash_find(ns_hash, addr, (void**)&hostname) == HASH_STATUS_OK) { + if(hash_find(ns_hash, addr, u_hostname.void_pp) == HASH_STATUS_OK) { /* Found => already resolved, or on the queue */ } else { diff --git a/ui.c b/ui.c index 0fbaf5c..17deb58 100644 --- a/ui.c +++ b/ui.c @@ -472,6 +472,10 @@ void analyse_data() { while(hash_next_item(history, &n) == HASH_STATUS_OK) { history_type* d = (history_type*)n->rec; host_pair_line* screen_line; + union { + host_pair_line **h_p_l_pp; + void **void_pp; + } u_screen_line = { &screen_line }; addr_pair ap; int i; int tsent, trecv; @@ -500,7 +504,7 @@ void analyse_data() { } - if(hash_find(screen_hash, &ap, (void**)&screen_line) == HASH_STATUS_KEY_NOT_FOUND) { + if(hash_find(screen_hash, &ap, u_screen_line.void_pp) == HASH_STATUS_KEY_NOT_FOUND) { screen_line = xcalloc(1, sizeof *screen_line); hash_insert(screen_hash, &ap, screen_line); screen_line->ap = ap; @@ -534,6 +538,11 @@ void sprint_host(char * line, struct in_addr* addr, unsigned int port, unsigned char hostname[HOSTNAME_LENGTH]; char service[HOSTNAME_LENGTH]; char* s_name; + union { + char **ch_pp; + void **void_pp; + } u_s_name = { &s_name }; + ip_service skey; int left; if(addr->s_addr == 0) { @@ -550,7 +559,7 @@ void sprint_host(char * line, struct in_addr* addr, unsigned int port, unsigned if(port != 0) { skey.port = port; skey.protocol = protocol; - if(options.portresolution && hash_find(service_hash, &skey, (void**)&s_name) == HASH_STATUS_OK) { + if(options.portresolution && hash_find(service_hash, &skey, u_s_name.void_pp) == HASH_STATUS_OK) { snprintf(service, HOSTNAME_LENGTH, ":%s", s_name); } else {