From 42fd1d9ac619e7cc86cb397bbb1b84ffc2f0a9bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20K=C3=B6tter?= Date: Thu, 8 Aug 2019 11:07:37 +0200 Subject: [PATCH 1/5] simplification - remove sockaddrtop --- Makefile.am | 1 + ui/net.c | 42 +++--------------------------------------- 2 files changed, 4 insertions(+), 39 deletions(-) diff --git a/Makefile.am b/Makefile.am index 29435e1..950ea8f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -55,6 +55,7 @@ mtr_SOURCES = ui/mtr.c ui/mtr.h \ ui/select.c ui/select.h \ ui/utils.c ui/utils.h \ packet/cmdparse.c packet/cmdparse.h \ + packet/sockaddr.c packet/sockaddr.h \ ui/mtr-curses.h \ img/mtr_icon.xpm \ ui/mtr-gtk.h diff --git a/ui/net.c b/ui/net.c index 1c78466..0536cdd 100644 --- a/ui/net.c +++ b/ui/net.c @@ -39,17 +39,13 @@ #include "display.h" #include "dns.h" #include "utils.h" +#include "packet/sockaddr.h" #define MinSequence 33000 #define MaxSequence 65536 static int packetsize; /* packet size used by ping */ -static void sockaddrtop( - struct sockaddr *saddr, - char *strptr, - size_t len); - struct nethost { ip_t addr; ip_t addrs[MAXPATH]; /* for multi paths byMin */ @@ -739,7 +735,7 @@ static void net_find_local_address( error(EXIT_FAILURE, errno, "local address determination failed"); } - sockaddrtop(sourcesockaddr, localaddr, sizeof(localaddr)); + inet_ntop(sourcesockaddr->sa_family, sockaddr_addr_offset(sourcesockaddr), localaddr, sizeof(localaddr)); close(udp_socket); } @@ -783,8 +779,7 @@ int net_open( } else if (ctl->InterfaceName) { net_find_interface_address_from_name( &sourcesockaddr_struct, ctl->af, ctl->InterfaceName); - - sockaddrtop(sourcesockaddr, localaddr, sizeof(localaddr)); + inet_ntop(sourcesockaddr->sa_family, sockaddr_addr_offset(sourcesockaddr), localaddr, sizeof(localaddr)); } else { net_find_local_address(); } @@ -907,37 +902,6 @@ void net_save_return( host[at].saved[idx] = ms; } -/* Similar to inet_ntop but uses a sockaddr as it's argument. */ -static void sockaddrtop( - struct sockaddr *saddr, - char *strptr, - size_t len) -{ - struct sockaddr_in *sa4; -#ifdef ENABLE_IPV6 - struct sockaddr_in6 *sa6; -#endif - - switch (saddr->sa_family) { - case AF_INET: - sa4 = (struct sockaddr_in *) saddr; - xstrncpy(strptr, inet_ntoa(sa4->sin_addr), len - 1); - strptr[len - 1] = '\0'; - return; -#ifdef ENABLE_IPV6 - case AF_INET6: - sa6 = (struct sockaddr_in6 *) saddr; - inet_ntop(sa6->sin6_family, &(sa6->sin6_addr), strptr, len); - return; -#endif - default: - error(0, 0, "sockaddrtop unknown address type"); - strptr[0] = '\0'; - return; - } -} - - /* Address comparison. */ int addrcmp( char *a, From eef2ed0985dd797366b59b8e3419427a662784b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20K=C3=B6tter?= Date: Thu, 8 Aug 2019 11:50:11 +0200 Subject: [PATCH 2/5] simplification - remove addrcpy --- ui/dns.c | 18 +++----------- ui/net.c | 71 ++++++++++---------------------------------------------- 2 files changed, 15 insertions(+), 74 deletions(-) diff --git a/ui/dns.c b/ui/dns.c index 8b323ff..c4417de 100644 --- a/ui/dns.c +++ b/ui/dns.c @@ -41,6 +41,7 @@ #include "dns.h" #include "net.h" #include "utils.h" +#include "packet/sockaddr.h" struct dns_results { ip_t ip; @@ -117,22 +118,9 @@ static void set_sockaddr_ip( struct sockaddr_storage *sa, ip_t * ip) { - struct sockaddr_in *sa_in; - struct sockaddr_in6 *sa_in6; - memset(sa, 0, sizeof(struct sockaddr_storage)); - switch (ctl->af) { - case AF_INET: - sa_in = (struct sockaddr_in *) sa; - sa_in->sin_family = ctl->af; - addrcpy((void *) &sa_in->sin_addr, (void *) ip, ctl->af); - break; - case AF_INET6: - sa_in6 = (struct sockaddr_in6 *) sa; - sa_in6->sin6_family = ctl->af; - addrcpy((void *) &sa_in6->sin6_addr, (void *) ip, ctl->af); - break; - } + sa->ss_family = ctl->af; + memcpy(sockaddr_addr_offset(sa), ip, sockaddr_addr_size(sa)); } void dns_open( diff --git a/ui/net.c b/ui/net.c index 0536cdd..4a7d880 100644 --- a/ui/net.c +++ b/ui/net.c @@ -87,8 +87,6 @@ static struct packet_command_pipe_t packet_command_pipe; #ifdef ENABLE_IPV6 static struct sockaddr_storage sourcesockaddr_struct; static struct sockaddr_storage remotesockaddr_struct; -static struct sockaddr_in6 *ssa6 = - (struct sockaddr_in6 *) &sourcesockaddr_struct; static struct sockaddr_in6 *rsa6 = (struct sockaddr_in6 *) &remotesockaddr_struct; #else @@ -100,8 +98,6 @@ static struct sockaddr *sourcesockaddr = (struct sockaddr *) &sourcesockaddr_struct; static struct sockaddr *remotesockaddr = (struct sockaddr *) &remotesockaddr_struct; -static struct sockaddr_in *ssa4 = - (struct sockaddr_in *) &sourcesockaddr_struct; static struct sockaddr_in *rsa4 = (struct sockaddr_in *) &remotesockaddr_struct; @@ -229,7 +225,7 @@ static void net_process_ping( char addrcopy[sizeof(struct in_addr)]; #endif - addrcpy((void *) &addrcopy, (char *) addr, ctl->af); + memcpy(&addrcopy, addr, sockaddr_addr_size(sourcesockaddr)); index = mark_sequence_complete(seq); if (index < 0) { @@ -241,12 +237,12 @@ static void net_process_ping( if (addrcmp((void *) &(host[index].addr), (void *) &ctl->unspec_addr, ctl->af) == 0) { /* should be out of if as addr can change */ - addrcpy((void *) &(host[index].addr), addrcopy, ctl->af); + memcpy(&(host[index].addr), addrcopy, sockaddr_addr_size(sourcesockaddr)); host[index].mpls = *mpls; display_rawhost(ctl, index, (void *) &(host[index].addr)); /* multi paths */ - addrcpy((void *) &(host[index].addrs[0]), addrcopy, ctl->af); + memcpy(&(host[index].addrs[0]), addrcopy, sockaddr_addr_size(sourcesockaddr)); host[index].mplss[0] = *mpls; } else { for (i = 0; i < MAXPATH;) { @@ -262,7 +258,9 @@ static void net_process_ping( if (addrcmp((void *) &(host[index].addrs[i]), addrcopy, ctl->af) != 0 && i < MAXPATH) { - addrcpy((void *) &(host[index].addrs[i]), addrcopy, ctl->af); + memcpy(&(host[index].addrs[i]), addrcopy, sockaddr_addr_size(sourcesockaddr)); + + host[index].mplss[i] = *mpls; display_rawhost(ctl, index, (void *) &(host[index].addrs[i])); } @@ -755,24 +753,11 @@ int net_open( net_reset(ctl); - remotesockaddr->sa_family = hostent->h_addrtype; + remotesockaddr->sa_family = sourcesockaddr->sa_family = hostent->h_addrtype; + memcpy(sockaddr_addr_offset(remotesockaddr), hostent->h_addr, sockaddr_addr_size(remotesockaddr)); - switch (hostent->h_addrtype) { - case AF_INET: - addrcpy((void *) &(rsa4->sin_addr), hostent->h_addr, AF_INET); - sourceaddress = (ip_t *) & (ssa4->sin_addr); - remoteaddress = (ip_t *) & (rsa4->sin_addr); - break; -#ifdef ENABLE_IPV6 - case AF_INET6: - addrcpy((void *) &(rsa6->sin6_addr), hostent->h_addr, AF_INET6); - sourceaddress = (ip_t *) & (ssa6->sin6_addr); - remoteaddress = (ip_t *) & (rsa6->sin6_addr); - break; -#endif - default: - error(EXIT_FAILURE, 0, "net_open bad address type"); - } + sourceaddress = sockaddr_addr_offset(sourcesockaddr); + remoteaddress = sockaddr_addr_offset(remotesockaddr); if (ctl->InterfaceAddress) { net_validate_interface_address(ctl->af, ctl->InterfaceAddress); @@ -799,21 +784,8 @@ void net_reopen( } remotesockaddr->sa_family = addr->h_addrtype; - addrcpy((void *) remoteaddress, addr->h_addr, addr->h_addrtype); - - switch (addr->h_addrtype) { - case AF_INET: - addrcpy((void *) &(rsa4->sin_addr), addr->h_addr, AF_INET); - break; -#ifdef ENABLE_IPV6 - case AF_INET6: - addrcpy((void *) &(rsa6->sin6_addr), addr->h_addr, AF_INET6); - break; -#endif - default: - error(EXIT_FAILURE, 0, "net_reopen bad address type"); - } - + memcpy(remoteaddress, addr->h_addr, sockaddr_addr_size(remotesockaddr)); + memcpy(sockaddr_addr_offset(remotesockaddr), addr->h_addr, sockaddr_addr_size(remotesockaddr)); net_reset(ctl); net_send_batch(ctl); } @@ -924,25 +896,6 @@ int addrcmp( return rc; } -/* Address copy. */ -void addrcpy( - char *a, - char *b, - int family) -{ - - switch (family) { - case AF_INET: - memcpy(a, b, sizeof(struct in_addr)); - break; -#ifdef ENABLE_IPV6 - case AF_INET6: - memcpy(a, b, sizeof(struct in6_addr)); - break; -#endif - } -} - /* for GTK frontend */ void net_harvest_fds( struct mtr_ctl *ctl) From be49b34c8a81747f52308fe679844ed89e8ef5ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20K=C3=B6tter?= Date: Thu, 8 Aug 2019 12:18:58 +0200 Subject: [PATCH 3/5] simplification - remove rsa{4,6} --- ui/net.c | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/ui/net.c b/ui/net.c index 4a7d880..62e85b0 100644 --- a/ui/net.c +++ b/ui/net.c @@ -84,22 +84,13 @@ static struct nethost host[MaxHost]; static struct sequence sequence[MaxSequence]; static struct packet_command_pipe_t packet_command_pipe; -#ifdef ENABLE_IPV6 static struct sockaddr_storage sourcesockaddr_struct; static struct sockaddr_storage remotesockaddr_struct; -static struct sockaddr_in6 *rsa6 = - (struct sockaddr_in6 *) &remotesockaddr_struct; -#else -static struct sockaddr_in sourcesockaddr_struct; -static struct sockaddr_in remotesockaddr_struct; -#endif static struct sockaddr *sourcesockaddr = (struct sockaddr *) &sourcesockaddr_struct; static struct sockaddr *remotesockaddr = (struct sockaddr *) &remotesockaddr_struct; -static struct sockaddr_in *rsa4 = - (struct sockaddr_in *) &remotesockaddr_struct; static ip_t *sourceaddress; static ip_t *remoteaddress; @@ -684,8 +675,6 @@ static void net_find_local_address( int udp_socket; int addr_length; struct sockaddr_storage remote_sockaddr; - struct sockaddr_in *remote4; - struct sockaddr_in6 *remote6; udp_socket = socket(remotesockaddr->sa_family, SOCK_DGRAM, IPPROTO_UDP); @@ -697,24 +686,11 @@ static void net_find_local_address( We need to set the port to a non-zero value for the connect to succeed. */ - if (remotesockaddr->sa_family == AF_INET6) { -#ifdef ENABLE_IPV6 - addr_length = sizeof(struct sockaddr_in6); - - memcpy(&remote_sockaddr, rsa6, addr_length); - remote6 = (struct sockaddr_in6 *) &remote_sockaddr; - remote6->sin6_port = htons(1); -#endif - } else { - addr_length = sizeof(struct sockaddr_in); - - memcpy(&remote_sockaddr, rsa4, addr_length); - remote4 = (struct sockaddr_in *) &remote_sockaddr; - remote4->sin_port = htons(1); - } + memcpy(&remote_sockaddr, &remotesockaddr_struct, sockaddr_size(&remotesockaddr_struct)); + *sockaddr_port_offset(&remote_sockaddr) = htons(1); if (connect - (udp_socket, (struct sockaddr *) &remote_sockaddr, addr_length)) { + (udp_socket, (struct sockaddr *) &remote_sockaddr, sockaddr_size(&remote_sockaddr))) { #ifdef __linux__ /* Linux doesn't require source address, so we can support * a case when mtr is run against unreachable host (that can become From 3ee915e882804d6e2454699c3806808c44615655 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20K=C3=B6tter?= Date: Wed, 14 Aug 2019 13:41:41 +0200 Subject: [PATCH 4/5] 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); From 283dc75726ef115d6ce0b632a9e32d05df4f1efb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20K=C3=B6tter?= Date: Wed, 14 Aug 2019 13:43:53 +0200 Subject: [PATCH 5/5] simplification - improve readability --- ui/net.c | 99 +++++++++++++++++++++++++++----------------------------- 1 file changed, 48 insertions(+), 51 deletions(-) diff --git a/ui/net.c b/ui/net.c index bf3e956..6e4942e 100644 --- a/ui/net.c +++ b/ui/net.c @@ -224,6 +224,7 @@ static void net_process_ping( #else char addrcopy[sizeof(struct in_addr)]; #endif + struct nethost *nh = NULL; memcpy(&addrcopy, addr, sockaddr_addr_size(sourcesockaddr)); @@ -231,89 +232,85 @@ static void net_process_ping( if (index < 0) { return; } + nh = &host[index]; + nh->err = err; - host[index].err = err; - if (addrcmp((void *) &(host[index].addr), - (void *) &ctl->unspec_addr, ctl->af) == 0) { + + if (addrcmp(&nh->addr, &ctl->unspec_addr, ctl->af) == 0) { /* should be out of if as addr can change */ - memcpy(&(host[index].addr), addrcopy, sockaddr_addr_size(sourcesockaddr)); - host[index].mpls = *mpls; - display_rawhost(ctl, index, (void *) &(host[index].addr)); + memcpy(&nh->addr, addrcopy, sockaddr_addr_size(sourcesockaddr)); + nh->mpls = *mpls; + display_rawhost(ctl, index, (void *) &(nh->addr)); /* multi paths */ - memcpy(&(host[index].addrs[0]), addrcopy, sockaddr_addr_size(sourcesockaddr)); - host[index].mplss[0] = *mpls; + memcpy(&nh->addrs[0], addrcopy, sockaddr_addr_size(sourcesockaddr)); + nh->mplss[0] = *mpls; } else { for (i = 0; i < MAXPATH;) { - if (addrcmp - ((void *) &(host[index].addrs[i]), (void *) &addrcopy, - ctl->af) == 0 - || addrcmp((void *) &(host[index].addrs[i]), - (void *) &ctl->unspec_addr, ctl->af) == 0) { + if (addrcmp(&nh->addrs[i], &addrcopy, ctl->af) == 0 || + addrcmp(&nh->addrs[i], &ctl->unspec_addr, ctl->af) == 0) { break; } i++; } - if (addrcmp((void *) &(host[index].addrs[i]), addrcopy, ctl->af) != - 0 && i < MAXPATH) { - memcpy(&(host[index].addrs[i]), addrcopy, sockaddr_addr_size(sourcesockaddr)); + if (addrcmp(&nh->addrs[i], &addrcopy, ctl->af) != 0 && i < MAXPATH) { + memcpy(&nh->addrs[i], addrcopy, sockaddr_addr_size(sourcesockaddr)); - - host[index].mplss[i] = *mpls; - display_rawhost(ctl, index, (void *) &(host[index].addrs[i])); + nh->mplss[i] = *mpls; + display_rawhost(ctl, index, (void *) &(nh->addrs[i])); } } - host[index].jitter = totusec - host[index].last; - if (host[index].jitter < 0) { - host[index].jitter = -host[index].jitter; + nh->jitter = totusec - nh->last; + if (nh->jitter < 0) { + nh->jitter = -nh->jitter; } - host[index].last = totusec; + nh->last = totusec; - if (host[index].returned < 1) { - host[index].best = host[index].worst = host[index].gmean = totusec; - host[index].avg = host[index].ssd = 0; + if (nh->returned < 1) { + nh->best = nh->worst = nh->gmean = totusec; + nh->avg = nh->ssd = 0; - host[index].jitter = host[index].jworst = host[index].jinta = 0; + nh->jitter = nh->jworst = nh->jinta = 0; } - if (totusec < host[index].best) { - host[index].best = totusec; + if (totusec < nh->best) { + nh->best = totusec; } - if (totusec > host[index].worst) { - host[index].worst = totusec; + if (totusec > nh->worst) { + nh->worst = totusec; } - if (host[index].jitter > host[index].jworst) { - host[index].jworst = host[index].jitter; + if (nh->jitter > nh->jworst) { + nh->jworst = nh->jitter; } - host[index].returned++; - oldavg = host[index].avg; - host[index].avg += (totusec - oldavg + .0) / host[index].returned; - host[index].ssd += - (totusec - oldavg + .0) * (totusec - host[index].avg); + nh->returned++; + oldavg = nh->avg; + nh->avg += (totusec - oldavg + .0) / nh->returned; + nh->ssd += + (totusec - oldavg + .0) * (totusec - nh->avg); - oldjavg = host[index].javg; - host[index].javg += - (host[index].jitter - oldjavg) / host[index].returned; + oldjavg = nh->javg; + nh->javg += + (nh->jitter - oldjavg) / nh->returned; /* below algorithm is from rfc1889, A.8 */ - host[index].jinta += - host[index].jitter - ((host[index].jinta + 8) >> 4); + nh->jinta += + nh->jitter - ((nh->jinta + 8) >> 4); - if (host[index].returned > 1) { - host[index].gmean = - pow((double) host[index].gmean, - (host[index].returned - 1.0) / host[index].returned) - * pow((double) totusec, 1.0 / host[index].returned); + if (nh->returned > 1) { + nh->gmean = + pow((double) nh->gmean, + (nh->returned - 1.0) / nh->returned) + * pow((double) totusec, 1.0 / nh->returned); } - host[index].sent = 0; - host[index].up = 1; - host[index].transit = 0; + nh->sent = 0; + nh->up = 1; + nh->transit = 0; net_save_return(index, sequence[seq].saved_seq, totusec); display_rawping(ctl, index, totusec, seq);