From a7a8985a914509351cb590ccae8cf3574f42f628 Mon Sep 17 00:00:00 2001 From: Aaron Lipinski Date: Sun, 4 Apr 2021 12:16:26 +1200 Subject: [PATCH 01/17] tell dns process if we want 4 or 6 --- ui/dns.c | 10 ++++++---- ui/dns.h | 2 +- ui/mtr.c | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/ui/dns.c b/ui/dns.c index 94af8b7..902aa67 100644 --- a/ui/dns.c +++ b/ui/dns.c @@ -124,7 +124,7 @@ static void set_sockaddr_ip( } void dns_open( - sa_family_t family) + void) { int pid; @@ -173,7 +173,8 @@ void dns_open( buf[strlen(buf) - 1] = 0; /* chomp newline. */ - longipstr(buf, &host, family); + sa_family_t family = (buf[0] == '4') ? AF_INET : AF_INET6; + longipstr(buf +1, &host, family); set_sockaddr_ip(family, &sa, &host); salen = (family == AF_INET) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6); @@ -256,7 +257,7 @@ char *dns_lookup2( ip_t * ip) { struct dns_results *r; - char buf[INET6_ADDRSTRLEN + 1]; + char buf[INET6_ADDRSTRLEN + 2]; // af_byte + addr + null int rv; r = findip(ctl, ip); @@ -270,7 +271,8 @@ char *dns_lookup2( r->name = NULL; r->next = results; results = r; - snprintf(buf, sizeof(buf), "%s\n", strlongip(ctl->af, ip)); + char ip4or6 = (ctl->af == AF_INET) ? '4' : '6'; + snprintf(buf, sizeof(buf), "%c%s\n", ip4or6, strlongip(ctl->af, ip)); rv = write(todns[1], buf, strlen(buf)); if (rv < 0) error(0, errno, "couldn't write to resolver process"); diff --git a/ui/dns.h b/ui/dns.h index b15d6ad..921110e 100644 --- a/ui/dns.h +++ b/ui/dns.h @@ -23,7 +23,7 @@ /* Prototypes for dns.c */ extern void dns_open( - sa_family_t family); + void); extern int dns_waitfd( void); extern void dns_ack( diff --git a/ui/mtr.c b/ui/mtr.c index b959919..91773f4 100644 --- a/ui/mtr.c +++ b/ui/mtr.c @@ -858,7 +858,7 @@ int main( } lock(stdout); - dns_open(ctl.af); + dns_open(); display_open(&ctl); display_loop(&ctl); -- 2.27.0 From d9116f22d273de98a8f15758eaaa6e8fa1df4fab Mon Sep 17 00:00:00 2001 From: Aaron Lipinski Date: Sun, 4 Apr 2021 13:02:54 +1200 Subject: [PATCH 02/17] resolve ipv6 only if we have ipv6 --- test/probe.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/probe.py b/test/probe.py index b1f0fff..88739cb 100755 --- a/test/probe.py +++ b/test/probe.py @@ -268,9 +268,10 @@ class TestProbeICMPv6(mtrpacket.MtrPacketTest): '''Test sending probes using IP version 6''' def __init__(self, *args): - google_addr = resolve_ipv6_address(mtrpacket.IPV6_TEST_HOST) + if mtrpacket.HAVE_IPV6: + google_addr = resolve_ipv6_address(mtrpacket.IPV6_TEST_HOST) - self.google_addr = google_addr # type: str + self.google_addr = google_addr # type: str super(TestProbeICMPv6, self).__init__(*args) -- 2.27.0 From 571004f8544ee638a2667c4f39bc9022a503915d Mon Sep 17 00:00:00 2001 From: Aaron Lipinski Date: Tue, 6 Apr 2021 12:25:12 +1200 Subject: [PATCH 03/17] remove wrapper only function --- ui/dns.c | 12 ------------ ui/dns.h | 2 -- ui/gtk.c | 2 +- 3 files changed, 1 insertion(+), 15 deletions(-) diff --git a/ui/dns.c b/ui/dns.c index 902aa67..8f47316 100644 --- a/ui/dns.c +++ b/ui/dns.c @@ -87,18 +87,6 @@ static int longipstr( } -struct hostent *dns_forward( - const char *name) -{ - struct hostent *host; - - if ((host = gethostbyname(name))) - return host; - else - return NULL; -} - - static struct dns_results *findip( struct mtr_ctl *ctl, ip_t * ip) diff --git a/ui/dns.h b/ui/dns.h index 921110e..918bc51 100644 --- a/ui/dns.h +++ b/ui/dns.h @@ -41,8 +41,6 @@ extern char *dns_lookup( extern char *dns_lookup2( struct mtr_ctl *ctl, ip_t * address); -extern struct hostent *dns_forward( - const char *name); extern char *strlongip( sa_family_t family, ip_t * ip); diff --git a/ui/gtk.c b/ui/gtk.c index e23abf2..a98154a 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -246,7 +246,7 @@ static gint Host_activate( struct mtr_ctl *ctl = (struct mtr_ctl *) data; struct hostent *addr; - addr = dns_forward(gtk_entry_get_text(GTK_ENTRY(entry))); + addr = gethostbyname(gtk_entry_get_text(GTK_ENTRY(entry))); if (addr) { net_reopen(ctl, addr); net_send_batch(ctl); -- 2.27.0 From 78301a8026500b584b22d27151edc746ccd7b673 Mon Sep 17 00:00:00 2001 From: Aaron Lipinski Date: Tue, 6 Apr 2021 13:23:14 +1200 Subject: [PATCH 04/17] init structures correctly wired up --- ui/mtr.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ui/mtr.c b/ui/mtr.c index 91773f4..ef567f6 100644 --- a/ui/mtr.c +++ b/ui/mtr.c @@ -766,9 +766,9 @@ int main( int argc, char **argv) { - struct hostent *host = NULL; - struct hostent trhost; char *alptr[2]; + struct hostent trhost; + struct hostent *host = &trhost; names_t *names_head = NULL; names_t *names_walk; @@ -837,7 +837,6 @@ int main( sizeof(ctl.LocalHostname)); } - host = &trhost; if (get_hostent_from_name(&ctl, host, ctl.Hostname, alptr) != 0) { if (ctl.Interactive) exit(EXIT_FAILURE); -- 2.27.0 From 14ec0550ab9e1e86025b5913e415f239b7d44260 Mon Sep 17 00:00:00 2001 From: Aaron Lipinski Date: Tue, 6 Apr 2021 13:25:10 +1200 Subject: [PATCH 05/17] prepare host with h_addr_list --- ui/mtr.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/ui/mtr.c b/ui/mtr.c index ef567f6..a8ccc0a 100644 --- a/ui/mtr.c +++ b/ui/mtr.c @@ -706,8 +706,7 @@ static void init_rand( static int get_hostent_from_name( struct mtr_ctl *ctl, struct hostent *host, - const char *name, - char **alptr) + const char *name) { int gai_error; struct addrinfo hints, *res; @@ -732,22 +731,20 @@ static int get_hostent_from_name( } /* Convert the first addrinfo into a hostent. */ - memset(host, 0, sizeof(struct hostent)); host->h_name = res->ai_canonname; host->h_aliases = NULL; host->h_addrtype = res->ai_family; ctl->af = res->ai_family; host->h_length = res->ai_addrlen; - host->h_addr_list = alptr; switch (ctl->af) { case AF_INET: sa4 = (struct sockaddr_in *) res->ai_addr; - alptr[0] = (void *) &(sa4->sin_addr); + host->h_addr_list[0] = (void *) &(sa4->sin_addr); break; #ifdef ENABLE_IPV6 case AF_INET6: sa6 = (struct sockaddr_in6 *) res->ai_addr; - alptr[0] = (void *) &(sa6->sin6_addr); + host->h_addr_list[0] = (void *) &(sa6->sin6_addr); break; #endif default: @@ -756,7 +753,7 @@ static int get_hostent_from_name( errno = EINVAL; return -1; } - alptr[1] = NULL; + host->h_addr_list[1] = NULL; return 0; } @@ -767,7 +764,7 @@ int main( char **argv) { char *alptr[2]; - struct hostent trhost; + struct hostent trhost = { .h_addr_list = alptr }; struct hostent *host = &trhost; names_t *names_head = NULL; names_t *names_walk; @@ -837,7 +834,7 @@ int main( sizeof(ctl.LocalHostname)); } - if (get_hostent_from_name(&ctl, host, ctl.Hostname, alptr) != 0) { + if (get_hostent_from_name(&ctl, host, ctl.Hostname) != 0) { if (ctl.Interactive) exit(EXIT_FAILURE); else { -- 2.27.0 From 92569b381b4f974bd3fdda0524b2b0bd2ce322e6 Mon Sep 17 00:00:00 2001 From: Aaron Lipinski Date: Tue, 6 Apr 2021 13:49:08 +1200 Subject: [PATCH 06/17] remove temporaries --- ui/mtr.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/ui/mtr.c b/ui/mtr.c index a8ccc0a..554264a 100644 --- a/ui/mtr.c +++ b/ui/mtr.c @@ -710,10 +710,6 @@ static int get_hostent_from_name( { int gai_error; struct addrinfo hints, *res; - struct sockaddr_in *sa4; -#ifdef ENABLE_IPV6 - struct sockaddr_in6 *sa6; -#endif /* gethostbyname2() is deprecated so we'll use getaddrinfo() instead. */ memset(&hints, 0, sizeof hints); @@ -738,13 +734,11 @@ static int get_hostent_from_name( host->h_length = res->ai_addrlen; switch (ctl->af) { case AF_INET: - sa4 = (struct sockaddr_in *) res->ai_addr; - host->h_addr_list[0] = (void *) &(sa4->sin_addr); + host->h_addr_list[0] = (char*)&((struct sockaddr_in *)res->ai_addr)->sin_addr; break; #ifdef ENABLE_IPV6 case AF_INET6: - sa6 = (struct sockaddr_in6 *) res->ai_addr; - host->h_addr_list[0] = (void *) &(sa6->sin6_addr); + host->h_addr_list[0] = (char*)&((struct sockaddr_in6 *)res->ai_addr)->sin6_addr; break; #endif default: -- 2.27.0 From b1f0f03a3a545695809183925fb259b44f2f2396 Mon Sep 17 00:00:00 2001 From: Aaron Lipinski Date: Tue, 6 Apr 2021 15:09:29 +1200 Subject: [PATCH 07/17] extract convert_addrinfo_to_hostent function --- ui/mtr.c | 49 ++++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/ui/mtr.c b/ui/mtr.c index 554264a..de32215 100644 --- a/ui/mtr.c +++ b/ui/mtr.c @@ -696,6 +696,30 @@ static void init_rand( srand((getpid() << 16) ^ getuid() ^ tv.tv_sec ^ tv.tv_usec); } +static int convert_addrinfo_to_hostent(struct hostent *host, struct addrinfo *res) +{ + host->h_name = res->ai_canonname; + host->h_aliases = NULL; + host->h_addrtype = res->ai_family; + host->h_length = res->ai_addrlen; + switch (res->ai_family) { + case AF_INET: + host->h_addr_list[0] = (char*)&((struct sockaddr_in *)res->ai_addr)->sin_addr; + break; +#ifdef ENABLE_IPV6 + case AF_INET6: + host->h_addr_list[0] = (char*)&((struct sockaddr_in6 *)res->ai_addr)->sin6_addr; + break; +#endif + default: + error(0, 0, "unknown address type"); + + errno = EINVAL; + return -1; + } + host->h_addr_list[1] = NULL; + return 0; +} /* For historical reasons, we need a hostent structure to represent @@ -726,30 +750,9 @@ static int get_hostent_from_name( return -1; } - /* Convert the first addrinfo into a hostent. */ - host->h_name = res->ai_canonname; - host->h_aliases = NULL; - host->h_addrtype = res->ai_family; ctl->af = res->ai_family; - host->h_length = res->ai_addrlen; - switch (ctl->af) { - case AF_INET: - host->h_addr_list[0] = (char*)&((struct sockaddr_in *)res->ai_addr)->sin_addr; - break; -#ifdef ENABLE_IPV6 - case AF_INET6: - host->h_addr_list[0] = (char*)&((struct sockaddr_in6 *)res->ai_addr)->sin6_addr; - break; -#endif - default: - error(0, 0, "unknown address type"); - - errno = EINVAL; - return -1; - } - host->h_addr_list[1] = NULL; - - return 0; + /* Convert the first addrinfo into a hostent. */ + return convert_addrinfo_to_hostent(host, res); } -- 2.27.0 From 5fd5c2b59d0bf1517492d88e672e8d6e69df657d Mon Sep 17 00:00:00 2001 From: Aaron Lipinski Date: Tue, 6 Apr 2021 15:39:57 +1200 Subject: [PATCH 08/17] move conversion call to caller --- ui/mtr.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/ui/mtr.c b/ui/mtr.c index de32215..ff1d995 100644 --- a/ui/mtr.c +++ b/ui/mtr.c @@ -729,17 +729,17 @@ static int convert_addrinfo_to_hostent(struct hostent *host, struct addrinfo *re */ static int get_hostent_from_name( struct mtr_ctl *ctl, - struct hostent *host, + struct addrinfo **res, const char *name) { int gai_error; - struct addrinfo hints, *res; + struct addrinfo hints; /* gethostbyname2() is deprecated so we'll use getaddrinfo() instead. */ memset(&hints, 0, sizeof hints); hints.ai_family = ctl->af; hints.ai_socktype = SOCK_DGRAM; - gai_error = getaddrinfo(name, NULL, &hints, &res); + gai_error = getaddrinfo(name, NULL, &hints, res); if (gai_error) { if (gai_error == EAI_SYSTEM) error(0, 0, "Failed to resolve host: %s", name); @@ -750,9 +750,8 @@ static int get_hostent_from_name( return -1; } - ctl->af = res->ai_family; - /* Convert the first addrinfo into a hostent. */ - return convert_addrinfo_to_hostent(host, res); + ctl->af = (*res)->ai_family; + return 0; } @@ -831,7 +830,10 @@ int main( sizeof(ctl.LocalHostname)); } - if (get_hostent_from_name(&ctl, host, ctl.Hostname) != 0) { + struct addrinfo *res = NULL; + if (get_hostent_from_name(&ctl, &res, ctl.Hostname) != 0 || + /* Convert the first addrinfo into a hostent. */ + convert_addrinfo_to_hostent(host, res) != 0) { if (ctl.Interactive) exit(EXIT_FAILURE); else { -- 2.27.0 From 6e2e4674a3c4c3ff7fb477bc7cf38ec9ccf8d4d3 Mon Sep 17 00:00:00 2001 From: Aaron Lipinski Date: Tue, 6 Apr 2021 16:00:41 +1200 Subject: [PATCH 09/17] use addrinfo --- ui/mtr.c | 2 +- ui/net.c | 10 +++++----- ui/net.h | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ui/mtr.c b/ui/mtr.c index ff1d995..253861b 100644 --- a/ui/mtr.c +++ b/ui/mtr.c @@ -842,7 +842,7 @@ int main( } } - if (net_open(&ctl, host) != 0) { + if (net_open(&ctl, res) != 0) { error(0, 0, "Unable to start net module"); if (ctl.Interactive) exit(EXIT_FAILURE); diff --git a/ui/net.c b/ui/net.c index 60d33e0..1df3503 100644 --- a/ui/net.c +++ b/ui/net.c @@ -736,7 +736,7 @@ static void net_find_local_address( int net_open( struct mtr_ctl *ctl, - struct hostent *hostent) + struct addrinfo *res) { int err; @@ -746,7 +746,7 @@ int net_open( return err; } - net_reopen(ctl, hostent); + net_reopen(ctl, res); return 0; } @@ -754,7 +754,7 @@ int net_open( void net_reopen( struct mtr_ctl *ctl, - struct hostent *hostent) + struct addrinfo *res) { int at; @@ -764,9 +764,9 @@ void net_reopen( net_reset(ctl); - ctl->af = remotesockaddr->sa_family = sourcesockaddr->sa_family = hostent->h_addrtype; + ctl->af = remotesockaddr->sa_family = sourcesockaddr->sa_family = res->ai_family; remoteaddress = sockaddr_addr_offset(remotesockaddr); - memcpy(remoteaddress, hostent->h_addr, sockaddr_addr_size(remotesockaddr)); + memcpy(remoteaddress, sockaddr_addr_offset(res->ai_addr), sockaddr_addr_size(remotesockaddr)); inet_ntop(remotesockaddr->sa_family, remoteaddress, remoteaddr, sizeof(remoteaddr)); sourceaddress = sockaddr_addr_offset(sourcesockaddr); diff --git a/ui/net.h b/ui/net.h index 38718fe..b323c25 100644 --- a/ui/net.h +++ b/ui/net.h @@ -33,10 +33,10 @@ extern int net_open( struct mtr_ctl *ctl, - struct hostent *host); + struct addrinfo *res); extern void net_reopen( struct mtr_ctl *ctl, - struct hostent *address); + struct addrinfo *res); extern void net_reset( struct mtr_ctl *ctl); extern void net_close( -- 2.27.0 From 5a45ca9cc2fb5d1e0d85b7421b938ee01204ab7e Mon Sep 17 00:00:00 2001 From: Aaron Lipinski Date: Tue, 6 Apr 2021 16:12:36 +1200 Subject: [PATCH 10/17] remove conversion function --- ui/mtr.c | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/ui/mtr.c b/ui/mtr.c index 253861b..8edca64 100644 --- a/ui/mtr.c +++ b/ui/mtr.c @@ -696,31 +696,6 @@ static void init_rand( srand((getpid() << 16) ^ getuid() ^ tv.tv_sec ^ tv.tv_usec); } -static int convert_addrinfo_to_hostent(struct hostent *host, struct addrinfo *res) -{ - host->h_name = res->ai_canonname; - host->h_aliases = NULL; - host->h_addrtype = res->ai_family; - host->h_length = res->ai_addrlen; - switch (res->ai_family) { - case AF_INET: - host->h_addr_list[0] = (char*)&((struct sockaddr_in *)res->ai_addr)->sin_addr; - break; -#ifdef ENABLE_IPV6 - case AF_INET6: - host->h_addr_list[0] = (char*)&((struct sockaddr_in6 *)res->ai_addr)->sin6_addr; - break; -#endif - default: - error(0, 0, "unknown address type"); - - errno = EINVAL; - return -1; - } - host->h_addr_list[1] = NULL; - return 0; -} - /* For historical reasons, we need a hostent structure to represent our remote target for probing. The obsolete way of doing this @@ -759,9 +734,6 @@ int main( int argc, char **argv) { - char *alptr[2]; - struct hostent trhost = { .h_addr_list = alptr }; - struct hostent *host = &trhost; names_t *names_head = NULL; names_t *names_walk; @@ -831,9 +803,7 @@ int main( } struct addrinfo *res = NULL; - if (get_hostent_from_name(&ctl, &res, ctl.Hostname) != 0 || - /* Convert the first addrinfo into a hostent. */ - convert_addrinfo_to_hostent(host, res) != 0) { + if (get_hostent_from_name(&ctl, &res, ctl.Hostname) != 0) { if (ctl.Interactive) exit(EXIT_FAILURE); else { -- 2.27.0 From 6a8471e48d33a9017ed226d2f6084e655421a793 Mon Sep 17 00:00:00 2001 From: Aaron Lipinski Date: Tue, 6 Apr 2021 16:52:18 +1200 Subject: [PATCH 11/17] switch gui to addrinfo --- ui/gtk.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ui/gtk.c b/ui/gtk.c index a98154a..aa07324 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -244,11 +244,11 @@ static gint Host_activate( gpointer data) { struct mtr_ctl *ctl = (struct mtr_ctl *) data; - struct hostent *addr; + struct addrinfo *res = NULL; - addr = gethostbyname(gtk_entry_get_text(GTK_ENTRY(entry))); - if (addr) { - net_reopen(ctl, addr); + ctl->Hostname = gtk_entry_get_text(GTK_ENTRY(entry)); + if (get_hostent_from_name(ctl, &res, ctl->Hostname) == 0) { + net_reopen(ctl, res); net_send_batch(ctl); /* If we are "Paused" at this point it is usually because someone entered a non-existing host. Therefore do the go-ahead... */ -- 2.27.0 From cf1b9bc7e7e9d46153b91021ca1f102dc0c79ac5 Mon Sep 17 00:00:00 2001 From: Aaron Lipinski Date: Thu, 8 Apr 2021 07:46:26 +1200 Subject: [PATCH 12/17] export DEFAULT_AF --- ui/mtr.c | 7 ------- ui/mtr.h | 2 ++ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/ui/mtr.c b/ui/mtr.c index 8edca64..23411cb 100644 --- a/ui/mtr.c +++ b/ui/mtr.c @@ -63,13 +63,6 @@ #include "portability/getopt.h" #endif -#ifdef ENABLE_IPV6 -#define DEFAULT_AF AF_UNSPEC -#else -#define DEFAULT_AF AF_INET -#endif - - char *myname; const struct fields data_fields[MAXFLD] = { diff --git a/ui/mtr.h b/ui/mtr.h index 01536f5..92dd8a1 100644 --- a/ui/mtr.h +++ b/ui/mtr.h @@ -32,8 +32,10 @@ /* Typedefs */ #ifdef ENABLE_IPV6 +#define DEFAULT_AF AF_UNSPEC typedef struct in6_addr ip_t; #else +#define DEFAULT_AF AF_INET typedef struct in_addr ip_t; #endif -- 2.27.0 From fd29a7e6306743c04171decff08334cc3fca6e8e Mon Sep 17 00:00:00 2001 From: Aaron Lipinski Date: Tue, 6 Apr 2021 16:57:59 +1200 Subject: [PATCH 13/17] reset addr family before searching again --- ui/gtk.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ui/gtk.c b/ui/gtk.c index aa07324..6e3a376 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -246,6 +246,7 @@ static gint Host_activate( struct mtr_ctl *ctl = (struct mtr_ctl *) data; struct addrinfo *res = NULL; + ctl->af = DEFAULT_AF; // should this obey the cmd line option? ctl->Hostname = gtk_entry_get_text(GTK_ENTRY(entry)); if (get_hostent_from_name(ctl, &res, ctl->Hostname) == 0) { net_reopen(ctl, res); -- 2.27.0 From e956e556217fcdd1865d21dea1cfb87a96550046 Mon Sep 17 00:00:00 2001 From: Aaron Lipinski Date: Wed, 7 Apr 2021 13:08:36 +1200 Subject: [PATCH 14/17] freeaddrinfo --- ui/gtk.c | 1 + ui/mtr.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/ui/gtk.c b/ui/gtk.c index 6e3a376..8ad0bbd 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -250,6 +250,7 @@ static gint Host_activate( ctl->Hostname = gtk_entry_get_text(GTK_ENTRY(entry)); if (get_hostent_from_name(ctl, &res, ctl->Hostname) == 0) { net_reopen(ctl, res); + freeaddrinfo(res); net_send_batch(ctl); /* If we are "Paused" at this point it is usually because someone entered a non-existing host. Therefore do the go-ahead... */ diff --git a/ui/mtr.c b/ui/mtr.c index 23411cb..9586780 100644 --- a/ui/mtr.c +++ b/ui/mtr.c @@ -815,6 +815,8 @@ int main( } } + freeaddrinfo(res); + lock(stdout); dns_open(); display_open(&ctl); -- 2.27.0 From 6521dc4fb0a0aa6baff11af20b066b2f713edbf8 Mon Sep 17 00:00:00 2001 From: Aaron Lipinski Date: Wed, 7 Apr 2021 13:11:55 +1200 Subject: [PATCH 15/17] export get_hostent_from_name --- ui/mtr.c | 4 ++-- ui/mtr.h | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ui/mtr.c b/ui/mtr.c index 9586780..a044d1e 100644 --- a/ui/mtr.c +++ b/ui/mtr.c @@ -38,7 +38,6 @@ #include #endif -#include #include #include #include @@ -695,11 +694,12 @@ static void init_rand( would be to use gethostbyname(). We'll use getaddrinfo() instead to generate the hostent. */ -static int get_hostent_from_name( +int get_hostent_from_name( struct mtr_ctl *ctl, struct addrinfo **res, const char *name) { + printf("get_hostent_from_name: %x %s\n", ctl->af, name); int gai_error; struct addrinfo hints; diff --git a/ui/mtr.h b/ui/mtr.h index 92dd8a1..5de5d9f 100644 --- a/ui/mtr.h +++ b/ui/mtr.h @@ -23,6 +23,7 @@ #include "config.h" #include +#include #include #include @@ -148,4 +149,9 @@ struct mplslen { #define running_as_root() (getuid() == 0) #endif +int get_hostent_from_name( + struct mtr_ctl *ctl, + struct addrinfo **res, + const char *name); + #endif /* MTR_MTR_H */ -- 2.27.0 From a351f650537e09f93738e3c76c06ebfa51552561 Mon Sep 17 00:00:00 2001 From: Aaron Lipinski Date: Wed, 7 Apr 2021 13:15:05 +1200 Subject: [PATCH 16/17] make Hostname as const --- ui/mtr.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/mtr.h b/ui/mtr.h index 5de5d9f..46c7a18 100644 --- a/ui/mtr.h +++ b/ui/mtr.h @@ -85,7 +85,7 @@ struct mtr_ctl { int MaxPing; float WaitTime; float GraceTime; - char *Hostname; + const char *Hostname; char *InterfaceName; char *InterfaceAddress; char LocalHostname[128]; -- 2.27.0 From 9e01af2ac2e4bd6520ea41e453e770e092050c23 Mon Sep 17 00:00:00 2001 From: Aaron Lipinski Date: Thu, 8 Apr 2021 08:14:00 +1200 Subject: [PATCH 17/17] rename function --- ui/gtk.c | 2 +- ui/mtr.c | 5 ++--- ui/mtr.h | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/ui/gtk.c b/ui/gtk.c index 8ad0bbd..7c4a9fd 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -248,7 +248,7 @@ static gint Host_activate( ctl->af = DEFAULT_AF; // should this obey the cmd line option? ctl->Hostname = gtk_entry_get_text(GTK_ENTRY(entry)); - if (get_hostent_from_name(ctl, &res, ctl->Hostname) == 0) { + if (get_addrinfo_from_name(ctl, &res, ctl->Hostname) == 0) { net_reopen(ctl, res); freeaddrinfo(res); net_send_batch(ctl); diff --git a/ui/mtr.c b/ui/mtr.c index a044d1e..6fd0d70 100644 --- a/ui/mtr.c +++ b/ui/mtr.c @@ -694,12 +694,11 @@ static void init_rand( would be to use gethostbyname(). We'll use getaddrinfo() instead to generate the hostent. */ -int get_hostent_from_name( +int get_addrinfo_from_name( struct mtr_ctl *ctl, struct addrinfo **res, const char *name) { - printf("get_hostent_from_name: %x %s\n", ctl->af, name); int gai_error; struct addrinfo hints; @@ -796,7 +795,7 @@ int main( } struct addrinfo *res = NULL; - if (get_hostent_from_name(&ctl, &res, ctl.Hostname) != 0) { + if (get_addrinfo_from_name(&ctl, &res, ctl.Hostname) != 0) { if (ctl.Interactive) exit(EXIT_FAILURE); else { diff --git a/ui/mtr.h b/ui/mtr.h index 46c7a18..9297be7 100644 --- a/ui/mtr.h +++ b/ui/mtr.h @@ -149,7 +149,7 @@ struct mplslen { #define running_as_root() (getuid() == 0) #endif -int get_hostent_from_name( +int get_addrinfo_from_name( struct mtr_ctl *ctl, struct addrinfo **res, const char *name); -- 2.27.0