[Toybox] [PATCH 3/4] Autodetect if IPv6 address is used and display warning
Eric Molitor
emolitor at molitor.org
Mon Jun 1 08:56:12 PDT 2020
---
toys/pending/route.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/toys/pending/route.c b/toys/pending/route.c
index b37d3ecd..f7592312 100644
--- a/toys/pending/route.c
+++ b/toys/pending/route.c
@@ -2,10 +2,10 @@
*
* Copyright 2012 Ranjan Kumar <ranjankumar.bth at gmail.com>
* Copyright 2013 Kyungwan Han <asura321 at gmail.com>
+ * Copyright 2020 Eric Molitor <eric at molitor.org>
*
* No Standard
*
- * TODO: autodetect -net -host target dev -A (but complain)
* route add -net target 10.0.0.0 netmask 255.0.0.0 dev eth0
* route del delete
* delete net route, must match netmask, informative error message
@@ -416,12 +416,18 @@ static void setroute(sa_family_t family, char **argv)
void route_main(void)
{
- if (!TT.family) TT.family = "inet";
if (!*toys.optargs) {
- if (!strcmp(TT.family, "inet")) display_routes(AF_INET);
+ if ( (!TT.family) || (!strcmp(TT.family, "inet")) ) display_routes(AF_INET);
else if (!strcmp(TT.family, "inet6")) display_routes(AF_INET6);
else show_help(stdout, 1);
} else {
+ if (!TT.family) {
+ if ( (toys.optc > 1) && (strchr(toys.optargs[1], ':')) ) {
+ xprintf("WARNING: Implicit IPV6 address using -Ainet6\n");
+ TT.family = "inet6";
+ } else TT.family = "inet";
+ }
+
if (!strcmp(TT.family, "inet")) setroute(AF_INET, toys.optargs);
else setroute(AF_INET6, toys.optargs);
}
--
2.25.1
More information about the Toybox
mailing list