]> git.ipfire.org Git - thirdparty/mtr.git/commitdiff
prepare host with h_addr_list
authorAaron Lipinski <aaron.lipinski@roboticsplus.co.nz>
Tue, 6 Apr 2021 01:25:10 +0000 (13:25 +1200)
committerAaron Lipinski <aaron.lipinski@roboticsplus.co.nz>
Thu, 8 Apr 2021 20:36:25 +0000 (08:36 +1200)
ui/mtr.c

index ef567f6730de6d52d7f52d43ade750d38b1afaf4..a8ccc0a7340bfe37e9b6eea3f5d1a91c9e33caff 100644 (file)
--- 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 {