summaryrefslogtreecommitdiff
path: root/sbin/ping6/ping6.c
diff options
context:
space:
mode:
authorFlorian Obser <florian@cvs.openbsd.org>2015-10-25 12:47:27 +0000
committerFlorian Obser <florian@cvs.openbsd.org>2015-10-25 12:47:27 +0000
commitb976dfe799ad6a51ea0610e588a6eddb4d1c6123 (patch)
treeec8632ed2188e5c4fb0568093115f42d708d7ebe /sbin/ping6/ping6.c
parentcb4a2414510d30f85c33547fca38c5120fbc2b02 (diff)
Implement ping(8)'s -L option in ping6:
Disable the loopback, so the transmitting host doesn't see the ICMP requests. For multicast pings. OK benno@
Diffstat (limited to 'sbin/ping6/ping6.c')
-rw-r--r--sbin/ping6/ping6.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/sbin/ping6/ping6.c b/sbin/ping6/ping6.c
index 47ab09dbace..02d0dc6f948 100644
--- a/sbin/ping6/ping6.c
+++ b/sbin/ping6/ping6.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ping6.c,v 1.131 2015/10/24 16:59:15 florian Exp $ */
+/* $OpenBSD: ping6.c,v 1.132 2015/10/25 12:47:26 florian Exp $ */
/* $KAME: ping6.c,v 1.163 2002/10/25 02:19:06 itojun Exp $ */
/*
@@ -148,6 +148,10 @@ struct payload {
#define F_AUD_MISS 0x400000
u_int options;
+/* multicast options */
+int moptions;
+#define MULTICAST_NOLOOP 0x001
+
#define DUMMY_PORT 10101
/*
@@ -235,7 +239,7 @@ main(int argc, char *argv[])
struct cmsghdr *scmsgp = NULL;
struct in6_pktinfo *pktinfo = NULL;
double intval;
- int mflag = 0;
+ int mflag = 0, loop = 1;
uid_t uid;
u_int rtableid = 0;
@@ -250,7 +254,7 @@ main(int argc, char *argv[])
preload = 0;
datap = &outpack[ICMP6ECHOLEN + ICMP6ECHOTMLEN];
while ((ch = getopt(argc, argv,
- "c:dEefg:Hh:I:i:l:mNnp:qS:s:V:vw:")) != -1) {
+ "c:dEefg:Hh:I:i:Ll:mNnp:qS:s:V:vw:")) != -1) {
switch (ch) {
case 'c':
npackets = strtonum(optarg, 0, INT_MAX, &errstr);
@@ -326,6 +330,10 @@ main(int argc, char *argv[])
}
options |= F_INTERVAL;
break;
+ case 'L':
+ moptions |= MULTICAST_NOLOOP;
+ loop = 0;
+ break;
case 'l':
if (getuid()) {
errno = EPERM;
@@ -463,6 +471,11 @@ main(int argc, char *argv[])
if ((options & F_FLOOD) && (options & (F_AUD_RECV | F_AUD_MISS)))
warnx("No audible output for flood pings");
+ if ((moptions & MULTICAST_NOLOOP) &&
+ setsockopt(s, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, &loop,
+ sizeof(loop)) < 0)
+ err(1, "setsockopt IP6_MULTICAST_LOOP");
+
if (datalen >= sizeof(struct payload)) {
/* we can time transfer */
timing = 1;
@@ -1645,7 +1658,7 @@ void
usage(void)
{
(void)fprintf(stderr,
- "usage: ping6 [-dEefHmnqv] [-c count] [-g gateway] [-h hoplimit] "
+ "usage: ping6 [-dEefHLmnqv] [-c count] [-g gateway] [-h hoplimit] "
"[-I sourceaddr]\n\t[-i wait] [-l preload] [-p pattern] "
"[-s packetsize] [-V rtable]\n\t[-w maxwait] host\n");
exit(1);