Page MenuHomeFreeBSD

D42159.id128610.diff
No OneTemporary

D42159.id128610.diff

diff --git a/sbin/ping/main.c b/sbin/ping/main.c
--- a/sbin/ping/main.c
+++ b/sbin/ping/main.c
@@ -41,6 +41,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sysexits.h>
#include <unistd.h>
#include "main.h"
@@ -94,6 +95,7 @@
#endif
#if defined(INET) && defined(INET6)
struct addrinfo hints, *res, *ai;
+ const char *target;
int error;
#endif
int opt;
@@ -143,6 +145,7 @@
usage();
#if defined(INET) && defined(INET6)
+ target = argv[argc - 1];
memset(&hints, 0, sizeof(hints));
hints.ai_socktype = SOCK_RAW;
if (feature_present("inet") && !feature_present("inet6"))
@@ -151,9 +154,10 @@
hints.ai_family = AF_INET6;
else
hints.ai_family = AF_UNSPEC;
- error = getaddrinfo(argv[argc - 1], NULL, &hints, &res);
+ error = getaddrinfo(target, NULL, &hints, &res);
if (res == NULL)
- errx(1, "%s", gai_strerror(error));
+ errx(EX_NOHOST, "cannot resolve %s: %s",
+ target, gai_strerror(error));
for (ai = res; ai != NULL; ai = ai->ai_next) {
if (ai->ai_family == AF_INET) {
freeaddrinfo(res);
@@ -165,7 +169,7 @@
}
}
freeaddrinfo(res);
- errx(1, "Unknown host");
+ errx(EX_NOHOST, "cannot resolve %s", target);
#endif
#ifdef INET
ping4:
diff --git a/sbin/ping/ping6.c b/sbin/ping/ping6.c
--- a/sbin/ping/ping6.c
+++ b/sbin/ping/ping6.c
@@ -654,14 +654,15 @@
error = cap_getaddrinfo(capdns, target, NULL, &hints, &res);
if (error)
- errx(1, "%s", gai_strerror(error));
+ errx(EX_NOHOST, "cannot resolve %s: %s",
+ target, gai_strerror(error));
if (res->ai_canonname)
hostname = strdup(res->ai_canonname);
else
hostname = target;
if (!res->ai_addr)
- errx(1, "cap_getaddrinfo failed");
+ errx(EX_NOHOST, "cannot resolve %s", target);
(void)memcpy(&dst, res->ai_addr, res->ai_addrlen);
diff --git a/sbin/ping/tests/ping_test.sh b/sbin/ping/tests/ping_test.sh
--- a/sbin/ping/tests/ping_test.sh
+++ b/sbin/ping/tests/ping_test.sh
@@ -165,6 +165,39 @@
ping6 -4 localhost
}
+atf_test_case ping_nohost
+ping_nohost_head()
+{
+ atf_set "descr" "ping a nonexistent host"
+}
+ping_nohost_body()
+{
+ atf_check -s exit:68 -e match:"cannot resolve" \
+ ping nonexistent.in-addr.arpa.
+}
+
+atf_test_case ping4_nohost
+ping4_nohost_head()
+{
+ atf_set "descr" "ping -4 a nonexistent host"
+}
+ping4_nohost_body()
+{
+ atf_check -s exit:68 -e match:"cannot resolve" \
+ ping -4 nonexistent.in-addr.arpa.
+}
+
+atf_test_case ping6_nohost
+ping6_nohost_head()
+{
+ atf_set "descr" "ping -6 a nonexistent host"
+}
+ping6_nohost_body()
+{
+ atf_check -s exit:68 -e match:"cannot resolve" \
+ ping -6 nonexistent.in-addr.arpa.
+}
+
atf_test_case "inject_opts" "cleanup"
inject_opts_head()
{
@@ -227,6 +260,9 @@
atf_add_test_case ping_46
atf_add_test_case ping_64
atf_add_test_case ping6_4
+ atf_add_test_case ping_nohost
+ atf_add_test_case ping4_nohost
+ atf_add_test_case ping6_nohost
atf_add_test_case inject_opts
atf_add_test_case inject_pip
atf_add_test_case inject_reply

File Metadata

Mime Type
text/plain
Expires
Wed, Sep 25, 3:33 AM (5 h, 59 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
12723476
Default Alt Text
D42159.id128610.diff (2 KB)

Event Timeline