diff --git a/usr.bin/ftp/fetch.c b/usr.bin/ftp/fetch.c index 62b64e9e35dd..fa6a0e44ba18 100644 --- a/usr.bin/ftp/fetch.c +++ b/usr.bin/ftp/fetch.c @@ -98,7 +98,7 @@ url_get(origline, proxyenv) const char *proxyenv; { struct addrinfo hints; - struct addrinfo *res; + struct addrinfo *res0, *res; char nameinfo[2 * INET6_ADDRSTRLEN + 1]; int i, out, isftpurl; char *port; @@ -207,9 +207,10 @@ url_get(origline, proxyenv) hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; error = getaddrinfo(host, port, &hints, &res); + res0 = res; if (error) { warnx("%s: %s", host, gai_strerror(error)); - if (error = EAI_SYSTEM) + if (error == EAI_SYSTEM) warnx("%s: %s", host, strerror(errno)); goto cleanup_url_get; } @@ -238,11 +239,13 @@ url_get(origline, proxyenv) res = res->ai_next; if (res) continue; + warn("Can't connect to %s", host); goto cleanup_url_get; } break; } + freeaddrinfo(res0); /* * Construct and send the request. We're expecting a return @@ -394,6 +397,8 @@ cleanup_url_get: if (proxy) free(proxy); free(line); + if (res0 != NULL) + freeaddrinfo(res0); return (-1); } diff --git a/usr.bin/ftp/ftp.c b/usr.bin/ftp/ftp.c index e2c6a39ad456..86dc44dec645 100644 --- a/usr.bin/ftp/ftp.c +++ b/usr.bin/ftp/ftp.c @@ -166,6 +166,7 @@ hookup(host, port) goto bad; } memcpy(&hisctladdr, res->ai_addr, res->ai_addrlen); + freeaddrinfo(res0); len = sizeof(myctladdr); if (getsockname(s, (struct sockaddr *)&myctladdr, &len) < 0) { warn("getsockname"); diff --git a/usr.bin/ftp/main.c b/usr.bin/ftp/main.c index aeb74878c8a7..5a1e5e626ed4 100644 --- a/usr.bin/ftp/main.c +++ b/usr.bin/ftp/main.c @@ -232,10 +232,9 @@ main(argc, argv) hints.ai_socktype = SOCK_STREAM; error = getaddrinfo(src_addr, NULL, &hints, &res); if (error) { - fprintf(stderr, "%s: %s", src_addr, - gai_strerror(error)); + warnx("%s: %s", src_addr, gai_strerror(error)); if (error == EAI_SYSTEM) - errx(1, "%s", strerror(errno)); + warnx("%s", strerror(errno)); exit(1); } memcpy(&bindto, res->ai_addr, res->ai_addrlen);