Bug: http://b/28027677 toybox ping doesn't support -m mark Test: strace -e setsockopt ./toybox ping -c 1 -m 0x1000 127.0.0.1 --- toys/net/ping.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
From 4f89d588340764706af24f77a712b1bfc88f79ee Mon Sep 17 00:00:00 2001 From: Elliott Hughes <e...@google.com> Date: Wed, 13 Jun 2018 14:24:30 -0700 Subject: [PATCH] ping: add -m, switch to xsetsockopt.
Bug: http://b/28027677 toybox ping doesn't support -m mark Test: strace -e setsockopt ./toybox ping -c 1 -m 0x1000 127.0.0.1 --- toys/net/ping.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/toys/net/ping.c b/toys/net/ping.c index cf1081a..f7c6ca1 100644 --- a/toys/net/ping.c +++ b/toys/net/ping.c @@ -11,7 +11,7 @@ * Yes, I wimped out and capped -s at sizeof(toybuf), waiting for a complaint... // -s > 4088 = sizeof(toybuf)-sizeof(struct icmphdr), then kernel adds 20 bytes -USE_PING(NEWTOY(ping, "<1>1t#<0>255=64c#<0=3s#<0>4088=56I:i:W#<0=10w#<0qf46[-46]", TOYFLAG_USR|TOYFLAG_BIN)) +USE_PING(NEWTOY(ping, "<1>1m#t#<0>255=64c#<0=3s#<0>4088=56I:i:W#<0=10w#<0qf46[-46]", TOYFLAG_USR|TOYFLAG_BIN)) config PING bool "ping" @@ -31,6 +31,7 @@ config PING -f Flood (print . and \b to show drops, default -c 15 -i 0.2) -i TIME Interval between packets (default 1, need root for < .2) -I IFACE/IP Source interface or address + -m MARK Tag outgoing packets using SO_MARK -q Quiet (stops after one returns true if host is alive) -s SIZE Data SIZE in bytes (default 56) -t TTL Set Time To Live (number of hops) @@ -52,6 +53,7 @@ GLOBALS( long s; long c; long t; + long m; struct sockaddr *sa; int sock; @@ -180,12 +182,18 @@ void ping_main(void) } if (TT.I && bind(TT.sock, sa, sizeof(src_addr))) perror_exit("bind"); + if (toys.optflags&FLAG_m) { + int mark = TT.m; + + xsetsockopt(TT.sock, SOL_SOCKET, SO_MARK, &mark, sizeof(mark)); + } + if (TT.t) { len = TT.t; if (ai->ai_family == AF_INET) - setsockopt(TT.sock, IPPROTO_IP, IP_TTL, &len, 4); - else setsockopt(TT.sock, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &len, 4); + xsetsockopt(TT.sock, IPPROTO_IP, IP_TTL, &len, 4); + else xsetsockopt(TT.sock, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &len, 4); } if (!(toys.optflags&FLAG_q)) { -- 2.18.0.rc1.242.g61856ae69a-goog
_______________________________________________ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net