aboutsummaryrefslogtreecommitdiff
path: root/sbin/ping
diff options
context:
space:
mode:
authorAlan Somers <asomers@FreeBSD.org>2020-11-28 23:24:19 +0000
committerAlan Somers <asomers@FreeBSD.org>2020-11-28 23:24:19 +0000
commitfd26389be7e149849c75a10311805a29d7215918 (patch)
tree345957919f01f66b53d8343b497302de43372048 /sbin/ping
parent5667729fba644a8dc105eb7435142b6c20969562 (diff)
downloadsrc-fd26389be7e149849c75a10311805a29d7215918.tar.gz
src-fd26389be7e149849c75a10311805a29d7215918.zip
ping: allow building without INET support
Building without INET6 support was already possible. Now it's possible to build ping with only INET6, or even with neither INET nor INET6. Reported by: bz Reviewed by: bz MFC-With: 368045 Differential Revision: https://reviews.freebsd.org/D27394
Notes
Notes: svn path=/head/; revision=368131
Diffstat (limited to 'sbin/ping')
-rw-r--r--sbin/ping/Makefile7
-rw-r--r--sbin/ping/main.c57
2 files changed, 43 insertions, 21 deletions
diff --git a/sbin/ping/Makefile b/sbin/ping/Makefile
index c9cc63bbf74d..23bac6d62d90 100644
--- a/sbin/ping/Makefile
+++ b/sbin/ping/Makefile
@@ -5,12 +5,17 @@
PACKAGE=runtime
PROG= ping
-SRCS= main.c ping.c utils.c
+SRCS= main.c
MAN= ping.8
BINOWN= root
BINMODE=4555
LIBADD= m
+.if ${MK_INET_SUPPORT}!= "no"
+CFLAGS+= -DINET
+SRCS+= ping.c utils.c
+.endif
+
.if ${MK_INET6_SUPPORT} != "no"
CFLAGS+= -DINET6 -DKAME_SCOPEID
SRCS+= ping6.c
diff --git a/sbin/ping/main.c b/sbin/ping/main.c
index 96150beec8b7..5d28a2b4a5cd 100644
--- a/sbin/ping/main.c
+++ b/sbin/ping/main.c
@@ -44,40 +44,51 @@ __FBSDID("$FreeBSD$");
#include <unistd.h>
#include "main.h"
+#ifdef INET
#include "ping.h"
+#endif
#ifdef INET6
#include "ping6.h"
#endif
-#ifdef INET6
+#if defined(INET) && defined(INET6)
#define OPTSTR ":46"
-#else
+#elif defined(INET)
#define OPTSTR ":4"
+#elif defined(INET6)
+#define OPTSTR ":6"
+#else
+#define OPTSTR ""
#endif
int
main(int argc, char *argv[])
{
+#if defined(INET) && defined(INET6)
struct in_addr a;
+ struct in6_addr a6;
+#endif
+#if defined(INET) || defined(INET6)
struct addrinfo hints;
+#endif
int ch;
- bool ipv4;
+#ifdef INET
+ bool ipv4 = false;
+#endif
#ifdef INET6
- struct in6_addr a6;
- bool ipv6;
+ bool ipv6 = false;
if (strcmp(getprogname(), "ping6") == 0)
ipv6 = true;
- else
- ipv6 = false;
#endif
- ipv4 = false;
while ((ch = getopt(argc, argv, OPTSTR)) != -1) {
switch(ch) {
+#ifdef INET
case '4':
ipv4 = true;
break;
+#endif
#ifdef INET6
case '6':
ipv6 = true;
@@ -93,20 +104,18 @@ main(int argc, char *argv[])
optreset = 1;
optind = 1;
-#ifdef INET6
+#if defined(INET) && defined(INET6)
if (ipv4 && ipv6)
errx(1, "-4 and -6 cannot be used simultaneously");
#endif
+#if defined(INET) && defined(INET6)
if (inet_pton(AF_INET, argv[argc - 1], &a) == 1) {
-#ifdef INET6
if (ipv6)
errx(1, "IPv6 requested but IPv4 target address "
"provided");
-#endif
hints.ai_family = AF_INET;
}
-#ifdef INET6
else if (inet_pton(AF_INET6, argv[argc - 1], &a6) == 1) {
if (ipv4)
errx(1, "IPv4 requested but IPv6 target address "
@@ -114,7 +123,6 @@ main(int argc, char *argv[])
hints.ai_family = AF_INET6;
} else if (ipv6)
hints.ai_family = AF_INET6;
-#endif
else if (ipv4)
hints.ai_family = AF_INET;
else {
@@ -129,22 +137,30 @@ main(int argc, char *argv[])
freeaddrinfo(res);
}
}
+#elif defined(INET)
+ hints.ai_family = AF_INET;
+#elif defined(INET6)
+ hints.ai_family = AF_INET6;
+#endif
+#ifdef INET
if (hints.ai_family == AF_INET)
return ping(argc, argv);
+#endif /* INET */
#ifdef INET6
- else if (hints.ai_family == AF_INET6)
+ if (hints.ai_family == AF_INET6)
return ping6(argc, argv);
-#endif
- else
- errx(1, "Unknown host");
+#endif /* INET6 */
+ errx(1, "Unknown host");
}
void
usage(void)
{
(void)fprintf(stderr,
- "usage: ping [-4AaDdfHnoQqRrv] [-C pcp] [-c count] "
+ "usage:\n"
+#ifdef INET
+ "\tping [-4AaDdfHnoQqRrv] [-C pcp] [-c count] "
"[-G sweepmaxsize]\n"
" [-g sweepminsize] [-h sweepincrsize] [-i wait] "
"[-l preload]\n"
@@ -155,7 +171,7 @@ usage(void)
"[-p pattern] [-S src_addr] \n"
" [-s packetsize] [-t timeout] [-W waittime] [-z tos] "
"IPv4-host\n"
- " ping [-4AaDdfHLnoQqRrv] [-C pcp] [-c count] [-I iface] "
+ "\tping [-4AaDdfHLnoQqRrv] [-C pcp] [-c count] [-I iface] "
"[-i wait]\n"
" [-l preload] [-M mask | time] [-m ttl] "
#ifdef IPSEC
@@ -164,8 +180,9 @@ usage(void)
"[-p pattern]\n"
" [-S src_addr] [-s packetsize] [-T ttl] [-t timeout] [-W waittime]\n"
" [-z tos] IPv4-mcast-group\n"
+#endif /* INET */
#ifdef INET6
- " ping [-6aADd"
+ "\tping [-6aADd"
#if defined(IPSEC) && !defined(IPSEC_POLICY_IPSEC)
"E"
#endif