From 3ee915e882804d6e2454699c3806808c44615655 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Markus=20K=C3=B6tter?= Date: Wed, 14 Aug 2019 13:41:41 +0200 Subject: [PATCH] simplification - address addrcmp --- ui/curses.c | 11 ++++------- ui/dns.c | 2 +- ui/gtk.c | 2 +- ui/net.c | 29 ++++++++++++++++------------- ui/net.h | 8 ++------ ui/split.c | 2 +- 6 files changed, 25 insertions(+), 29 deletions(-) diff --git a/ui/curses.c b/ui/curses.c index b0bc02e..02e4f6b 100644 --- a/ui/curses.c +++ b/ui/curses.c @@ -424,8 +424,7 @@ static void mtr_curses_hosts( addr = net_addr(at); mpls = net_mpls(at); - addrcmp_result = addrcmp( - (void *) addr, (void *) &ctl->unspec_addr, ctl->af); + addrcmp_result = addrcmp(addr, &ctl->unspec_addr, ctl->af); if (err == 0 && addrcmp_result != 0) { name = dns_lookup(ctl, addr); @@ -475,11 +474,9 @@ static void mtr_curses_hosts( for (i = 0; i < MAXPATH; i++) { addrs = net_addrs(at, i); mplss = net_mplss(at, i); - if (addrcmp((void *) addrs, (void *) addr, ctl->af) == 0) + if (addrcmp(addrs, addr, ctl->af) == 0) continue; - if (addrcmp - ((void *) addrs, (void *) &ctl->unspec_addr, - ctl->af) == 0) + if (addrcmp(addrs, &ctl->unspec_addr,ctl->af) == 0) break; name = dns_lookup(ctl, addrs); @@ -645,7 +642,7 @@ static void mtr_curses_graph( } if (err == 0 - && addrcmp((void *) addr, (void *) &ctl->unspec_addr, ctl->af)) { + && addrcmp(addr, &ctl->unspec_addr, ctl->af)) { if (!net_up(at)) { attron(A_BOLD); diff --git a/ui/dns.c b/ui/dns.c index c4417de..4072dd6 100644 --- a/ui/dns.c +++ b/ui/dns.c @@ -106,7 +106,7 @@ static struct dns_results *findip( struct dns_results *t; for (t = results; t; t = t->next) { - if (addrcmp((void *) ip, (void *) &t->ip, ctl->af) == 0) + if (addrcmp(ip, &t->ip, ctl->af) == 0) return t; } diff --git a/ui/gtk.c b/ui/gtk.c index a978d35..7b22d8a 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -507,7 +507,7 @@ static void update_tree_row( char str[256] = "???", *name = str; addr = net_addr(row); - if (addrcmp((void *) addr, (void *) &ctl->unspec_addr, ctl->af)) { + if (addrcmp(addr, &ctl->unspec_addr, ctl->af)) { if ((name = dns_lookup(ctl, addr))) { if (ctl->show_ips) { snprintf(str, sizeof(str), "%s (%s)", name, diff --git a/ui/net.c b/ui/net.c index 62e85b0..bf3e956 100644 --- a/ui/net.c +++ b/ui/net.c @@ -107,6 +107,14 @@ static char localaddr[INET_ADDRSTRLEN]; static int batch_at = 0; static int numhosts = 10; + +#define host_addr_cmp(index, other, af) \ + addrcmp((void *) &(host[(index)].addr), (void *) (other), (af)) + +#define host_addrs_cmp(index, path, other, af) \ + addrcmp((void *) &(host[(index)].addrs[path]), (void *) (other), (af)) + + /* return the number of microseconds to wait before sending the next ping */ int calc_deltatime( @@ -198,6 +206,7 @@ static int mark_sequence_complete( Record the round trip time and address of the responding host. */ + static void net_process_ping( struct mtr_ctl *ctl, int seq, @@ -460,8 +469,7 @@ int net_max( max = 0; for (at = 0; at < ctl->maxTTL; at++) { - if (addrcmp((void *) &(host[at].addr), - (void *) remoteaddress, ctl->af) == 0) { + if (host_addr_cmp(at , remoteaddress, ctl->af) == 0) { return at + 1; } else if (host[at].err != 0) { /* @@ -470,8 +478,7 @@ int net_max( final hop. */ return at + 1; - } else if (addrcmp((void *) &(host[at].addr), - (void *) &ctl->unspec_addr, ctl->af) != 0) { + } else if (host_addr_cmp(at, &ctl->unspec_addr, ctl->af) != 0) { max = at + 2; } } @@ -560,9 +567,7 @@ int net_send_batch( net_send_query(ctl, batch_at, abs(packetsize)); for (i = ctl->fstTTL - 1; i < batch_at; i++) { - if (addrcmp - ((void *) &(host[i].addr), (void *) &ctl->unspec_addr, - ctl->af) == 0) + if (host_addr_cmp(i, &ctl->unspec_addr, ctl->af) == 0) n_unknown++; /* The second condition in the next "if" statement was added in mtr-0.56, @@ -570,14 +575,12 @@ int net_send_batch( hosts. Removed in 0.65. If the line proves necessary, it should at least NOT trigger that line when host[i].addr == 0 */ - if ((addrcmp((void *) &(host[i].addr), - (void *) remoteaddress, ctl->af) == 0)) + if (host_addr_cmp(i, remoteaddress, ctl->af) == 0) n_unknown = MaxHost; /* Make sure we drop into "we should restart" */ } if ( /* success in reaching target */ - (addrcmp((void *) &(host[batch_at].addr), - (void *) remoteaddress, ctl->af) == 0) || + (host_addr_cmp(batch_at, remoteaddress, ctl->af) == 0) || /* fail in consecutive maxUnknown (firewall?) */ (n_unknown > ctl->maxUnknown) || /* or reach limit */ @@ -852,8 +855,8 @@ void net_save_return( /* Address comparison. */ int addrcmp( - char *a, - char *b, + void *a, + void *b, int family) { int rc = -1; diff --git a/ui/net.h b/ui/net.h index 0fb4700..8a0d775 100644 --- a/ui/net.h +++ b/ui/net.h @@ -117,12 +117,8 @@ extern void net_save_return( int ms); extern int addrcmp( - char *a, - char *b, - int af); -extern void addrcpy( - char *a, - char *b, + void *a, + void *b, int af); extern void net_add_fds( diff --git a/ui/split.c b/ui/split.c index c0f46be..d300404 100644 --- a/ui/split.c +++ b/ui/split.c @@ -92,7 +92,7 @@ void split_redraw( */ for (at = 0; at < max; at++) { addr = net_addr(at); - if (addrcmp((void *) addr, (void *) &ctl->unspec_addr, ctl->af)) { + if (addrcmp(addr, &ctl->unspec_addr, ctl->af)) { char str[256], *name; if (!(name = dns_lookup(ctl, addr))) name = strlongip(ctl, addr); -- 2.47.3