aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Molitor <emolitor@molitor.org>2020-06-01 16:56:12 +0100
committerRob Landley <rob@landley.net>2020-06-02 10:46:21 -0500
commit589c7620399d1207e7067f0f6e2acecc011a3c06 (patch)
tree51bdefd3e673829245c4455b4ed2c82c234aa4d9
parent1949f56ddde09653a10e8e5baa12fb3d10305a06 (diff)
downloadtoybox-589c7620399d1207e7067f0f6e2acecc011a3c06.tar.gz
Autodetect if IPv6 address is used and display warning
-rw-r--r--toys/pending/route.c12
1 files 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@gmail.com>
* Copyright 2013 Kyungwan Han <asura321@gmail.com>
+ * Copyright 2020 Eric Molitor <eric@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);
}