]> git.ipfire.org Git - thirdparty/mtr.git/commitdiff
simplification - address addrcmp
authorMarkus Kötter <koetter@luis.uni-hannover.de>
Wed, 14 Aug 2019 11:41:41 +0000 (13:41 +0200)
committerMarkus Kötter <koetter@luis.uni-hannover.de>
Wed, 14 Aug 2019 11:41:41 +0000 (13:41 +0200)
ui/curses.c
ui/dns.c
ui/gtk.c
ui/net.c
ui/net.h
ui/split.c

index b0bc02e20b92da12ec9951b6b62925d3bee0b347..02e4f6b15b525bde3e8d8f93f32fa3a4839eda66 100644 (file)
@@ -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);
index c4417deacf3399478a28ccfe884880437bc084ba..4072dd67f077d55d0a3442ee9374a58cceca32d3 100644 (file)
--- 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;
     }
 
index a978d3573f2a55fca7af22338145b78073aa843a..7b22d8a11b5129ff19f6c211c20c4a483d4ba68a 100644 (file)
--- 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,
index 62e85b09d61c4b7dd0d922c342e7ddaf5e4e2861..bf3e956abc9fff3efc296d2db8f4f125ddacbac9 100644 (file)
--- 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;
index 0fb470027c437a77e04523038b53e56b7a0c01ae..8a0d7751e2de6facbe9069db31f9eb1b60259d6a 100644 (file)
--- 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(
index c0f46beb55881b084410a71fee0553710e4374f0..d3004041015e1704f297ce0737454e787b93003d 100644 (file)
@@ -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);