Date: Fri, 1 Jan 2021 17:27:48 GMT From: Alan Somers <asomers@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: b586c66baf48 - main - ping: fix ping when the kernel was built without INET6 Message-ID: <202101011727.101HRmUm001690@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=b586c66baf4824d175d051b3f5b06588c9aa2bc8 commit b586c66baf4824d175d051b3f5b06588c9aa2bc8 Author: Alan Somers <asomers@FreeBSD.org> AuthorDate: 2021-01-01 17:25:49 +0000 Commit: Alan Somers <asomers@FreeBSD.org> CommitDate: 2021-01-01 17:25:49 +0000 ping: fix ping when the kernel was built without INET6 If the kernel was built without INET6, default to ICMP. Or, if it was built without INET, default to ICMPv6. PR: 251725 Reported by: jbeich Reviewed by: jbeich Tested by: jbeich MFC with: 368045 --- sbin/ping/main.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/sbin/ping/main.c b/sbin/ping/main.c index 5d28a2b4a5cd..01442679efff 100644 --- a/sbin/ping/main.c +++ b/sbin/ping/main.c @@ -126,15 +126,21 @@ main(int argc, char *argv[]) else if (ipv4) hints.ai_family = AF_INET; else { - struct addrinfo *res; - - memset(&hints, 0, sizeof(hints)); - hints.ai_socktype = SOCK_RAW; - hints.ai_family = AF_UNSPEC; - getaddrinfo(argv[argc - 1], NULL, &hints, &res); - if (res != NULL) { - hints.ai_family = res[0].ai_family; - freeaddrinfo(res); + if (!feature_present("inet6")) + hints.ai_family = AF_INET; + else if (!feature_present("inet")) + hints.ai_family = AF_INET6; + else { + struct addrinfo *res; + + memset(&hints, 0, sizeof(hints)); + hints.ai_socktype = SOCK_RAW; + hints.ai_family = AF_UNSPEC; + getaddrinfo(argv[argc - 1], NULL, &hints, &res); + if (res != NULL) { + hints.ai_family = res[0].ai_family; + freeaddrinfo(res); + } } } #elif defined(INET)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202101011727.101HRmUm001690>