From 589c7620399d1207e7067f0f6e2acecc011a3c06 Mon Sep 17 00:00:00 2001 From: Eric Molitor Date: Mon, 1 Jun 2020 16:56:12 +0100 Subject: Autodetect if IPv6 address is used and display warning --- toys/pending/route.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'toys/pending/route.c') 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 * Copyright 2013 Kyungwan Han + * Copyright 2020 Eric Molitor * * 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); } -- cgit v1.2.3