]> git.ipfire.org Git - thirdparty/mtr.git/commitdiff
move conversion call to caller
authorAaron Lipinski <aaron.lipinski@roboticsplus.co.nz>
Tue, 6 Apr 2021 03:39:57 +0000 (15:39 +1200)
committerAaron Lipinski <aaron.lipinski@roboticsplus.co.nz>
Thu, 8 Apr 2021 20:36:25 +0000 (08:36 +1200)
ui/mtr.c

index de32215c0f45bdbf16f619134f38ab8b0a9b3335..ff1d995cb3dffeeaa425b8748cdf6e3abb2c5b92 100644 (file)
--- 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 {