Commit d621c2e8 authored by Bernd Eckenfels's avatar Bernd Eckenfels

[Bug#22] Return non-zero exit code if route arguments fail verification (CEM@sf.net)

parent 038ed39a
/* /*
Modifications: * inet6_sr.c This files contains INET6 related route manipulation methods.
1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets *
* Part of net-tools, the Linux base networking tools
*
* This program is free software; you can redistribute it and/or modif
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License.
*/ */
#include "config.h" #include "config.h"
...@@ -41,12 +46,12 @@ extern struct aftype inet6_aftype; ...@@ -41,12 +46,12 @@ extern struct aftype inet6_aftype;
static int skfd = -1; static int skfd = -1;
static int usage(void) static int usage(const int rc)
{ {
fprintf(stderr, _("Usage: inet6_route [-vF] del Target\n")); fprintf(stderr, _("Usage: inet6_route [-vF] del Target\n"));
fprintf(stderr, _(" inet6_route [-vF] add Target [gw Gw] [metric M] [[dev] If]\n")); fprintf(stderr, _(" inet6_route [-vF] add Target [gw Gw] [metric M] [[dev] If]\n"));
fprintf(stderr, _(" inet6_route [-FC] flush NOT supported\n")); fprintf(stderr, _(" inet6_route [-FC] flush NOT supported\n"));
return (E_USAGE); return (rc);
} }
...@@ -61,7 +66,7 @@ static int INET6_setroute(int action, int options, char **args) ...@@ -61,7 +66,7 @@ static int INET6_setroute(int action, int options, char **args)
char *cp; char *cp;
if (*args == NULL) if (*args == NULL)
return (usage()); return usage(E_OPTERR);
safe_strncpy(target, *args++, sizeof(target)); safe_strncpy(target, *args++, sizeof(target));
if (!strcmp(target, "default")) { if (!strcmp(target, "default")) {
...@@ -71,7 +76,7 @@ static int INET6_setroute(int action, int options, char **args) ...@@ -71,7 +76,7 @@ static int INET6_setroute(int action, int options, char **args)
if ((cp = strchr(target, '/'))) { if ((cp = strchr(target, '/'))) {
prefix_len = atol(cp + 1); prefix_len = atol(cp + 1);
if ((prefix_len < 0) || (prefix_len > 128)) if ((prefix_len < 0) || (prefix_len > 128))
usage(); return usage(E_OPTERR);
*cp = 0; *cp = 0;
} else { } else {
prefix_len = 128; prefix_len = 128;
...@@ -100,7 +105,7 @@ static int INET6_setroute(int action, int options, char **args) ...@@ -100,7 +105,7 @@ static int INET6_setroute(int action, int options, char **args)
args++; args++;
if (!*args || !isdigit(**args)) if (!*args || !isdigit(**args))
return (usage()); return usage(E_OPTERR);
metric = atoi(*args); metric = atoi(*args);
rt.rtmsg_metric = metric; rt.rtmsg_metric = metric;
args++; args++;
...@@ -109,9 +114,9 @@ static int INET6_setroute(int action, int options, char **args) ...@@ -109,9 +114,9 @@ static int INET6_setroute(int action, int options, char **args)
if (!strcmp(*args, "gw") || !strcmp(*args, "gateway")) { if (!strcmp(*args, "gw") || !strcmp(*args, "gateway")) {
args++; args++;
if (!*args) if (!*args)
return (usage()); return usage(E_OPTERR);
if (rt.rtmsg_flags & RTF_GATEWAY) if (rt.rtmsg_flags & RTF_GATEWAY)
return (usage()); return usage(E_OPTERR);
safe_strncpy(gateway, *args, sizeof(gateway)); safe_strncpy(gateway, *args, sizeof(gateway));
if (inet6_aftype.input(1, gateway, if (inet6_aftype.input(1, gateway,
(struct sockaddr *) &sa6) < 0) { (struct sockaddr *) &sa6) < 0) {
...@@ -137,9 +142,9 @@ static int INET6_setroute(int action, int options, char **args) ...@@ -137,9 +142,9 @@ static int INET6_setroute(int action, int options, char **args)
if (!strcmp(*args, "device") || !strcmp(*args, "dev")) { if (!strcmp(*args, "device") || !strcmp(*args, "dev")) {
args++; args++;
if (!*args) if (!*args)
return (usage()); return usage(E_OPTERR);
} else if (args[1]) } else if (args[1])
return (usage()); return usage(E_OPTERR);
devname = *args; devname = *args;
args++; args++;
...@@ -186,10 +191,10 @@ int INET6_rinput(int action, int options, char **args) ...@@ -186,10 +191,10 @@ int INET6_rinput(int action, int options, char **args)
{ {
if (action == RTACTION_FLUSH) { if (action == RTACTION_FLUSH) {
fprintf(stderr, _("Flushing `inet6' routing table not supported\n")); fprintf(stderr, _("Flushing `inet6' routing table not supported\n"));
return (usage()); return usage(E_OPTERR);
} }
if ((*args == NULL) || (action == RTACTION_HELP)) if (action == RTACTION_HELP)
return (usage()); return usage(E_USAGE);
return (INET6_setroute(action, options, args)); return (INET6_setroute(action, options, args));
} }
......
/* /*
Modifications: * inet_sr.c This files contains INET4 related route manipulation methods.
1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets *
1999-10-07 - Kurt Garloff - for -host and gws: prefer host names * Part of net-tools, the Linux base networking tools
over networks (or even reject) *
2003-10-11 - Maik Broemme - gcc 3.x warnign fixes (default: break;) * This program is free software; you can redistribute it and/or modif
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License.
*/ */
#include "config.h" #include "config.h"
...@@ -46,7 +48,7 @@ extern struct aftype inet_aftype; ...@@ -46,7 +48,7 @@ extern struct aftype inet_aftype;
static int skfd = -1; static int skfd = -1;
static int usage(void) static int usage(const int rc)
{ {
fprintf(stderr, _("Usage: inet_route [-vF] del {-host|-net} Target[/prefix] [gw Gw] [metric M] [[dev] If]\n")); fprintf(stderr, _("Usage: inet_route [-vF] del {-host|-net} Target[/prefix] [gw Gw] [metric M] [[dev] If]\n"));
fprintf(stderr, _(" inet_route [-vF] add {-host|-net} Target[/prefix] [gw Gw] [metric M]\n")); fprintf(stderr, _(" inet_route [-vF] add {-host|-net} Target[/prefix] [gw Gw] [metric M]\n"));
...@@ -54,7 +56,7 @@ static int usage(void) ...@@ -54,7 +56,7 @@ static int usage(void)
fprintf(stderr, _(" [mod] [dyn] [reinstate] [[dev] If]\n")); fprintf(stderr, _(" [mod] [dyn] [reinstate] [[dev] If]\n"));
fprintf(stderr, _(" inet_route [-vF] add {-host|-net} Target[/prefix] [metric M] reject\n")); fprintf(stderr, _(" inet_route [-vF] add {-host|-net} Target[/prefix] [metric M] reject\n"));
fprintf(stderr, _(" inet_route [-FC] flush NOT supported\n")); fprintf(stderr, _(" inet_route [-FC] flush NOT supported\n"));
return (E_USAGE); return (rc);
} }
static int INET_setroute(int action, int options, char **args) static int INET_setroute(int action, int options, char **args)
...@@ -73,7 +75,7 @@ static int INET_setroute(int action, int options, char **args) ...@@ -73,7 +75,7 @@ static int INET_setroute(int action, int options, char **args)
args++; args++;
} }
if (*args == NULL) if (*args == NULL)
return (usage()); return usage(E_OPTERR);
safe_strncpy(target, *args++, (sizeof target)); safe_strncpy(target, *args++, (sizeof target));
...@@ -90,7 +92,7 @@ static int INET_setroute(int action, int options, char **args) ...@@ -90,7 +92,7 @@ static int INET_setroute(int action, int options, char **args)
n = inet_aftype.getmask(target, &mask.d, netmask); n = inet_aftype.getmask(target, &mask.d, netmask);
if (n < 0) if (n < 0)
return usage(); return usage(E_OPTERR);
else if (n) else if (n)
rt.rt_genmask = full_mask(mask.d); rt.rt_genmask = full_mask(mask.d);
} }
...@@ -98,7 +100,7 @@ static int INET_setroute(int action, int options, char **args) ...@@ -98,7 +100,7 @@ static int INET_setroute(int action, int options, char **args)
/* Prefer hostname lookup is -host flag was given */ /* Prefer hostname lookup is -host flag was given */
if ((isnet = inet_aftype.input((xflag!=2? 0: 256), target, &rt.rt_dst)) < 0) { if ((isnet = inet_aftype.input((xflag!=2? 0: 256), target, &rt.rt_dst)) < 0) {
inet_aftype.herror(target); inet_aftype.herror(target);
return (1); return (E_LOOKUP);
} }
switch (xflag) { switch (xflag) {
case 1: case 1:
...@@ -118,7 +120,7 @@ static int INET_setroute(int action, int options, char **args) ...@@ -118,7 +120,7 @@ static int INET_setroute(int action, int options, char **args)
args++; args++;
if (!*args || !isdigit(**args)) if (!*args || !isdigit(**args))
return (usage()); return usage(E_OPTERR);
metric = atoi(*args); metric = atoi(*args);
#if HAVE_NEW_ADDRT #if HAVE_NEW_ADDRT
rt.rt_metric = metric + 1; rt.rt_metric = metric + 1;
...@@ -133,7 +135,7 @@ static int INET_setroute(int action, int options, char **args) ...@@ -133,7 +135,7 @@ static int INET_setroute(int action, int options, char **args)
args++; args++;
if (!*args || mask_in_addr(rt)) if (!*args || mask_in_addr(rt))
return (usage()); return usage(E_OPTERR);
safe_strncpy(netmask, *args, (sizeof netmask)); safe_strncpy(netmask, *args, (sizeof netmask));
if ((isnet = inet_aftype.input(0, netmask, &mask)) < 0) { if ((isnet = inet_aftype.input(0, netmask, &mask)) < 0) {
inet_aftype.herror(netmask); inet_aftype.herror(netmask);
...@@ -146,9 +148,9 @@ static int INET_setroute(int action, int options, char **args) ...@@ -146,9 +148,9 @@ static int INET_setroute(int action, int options, char **args)
if (!strcmp(*args, "gw") || !strcmp(*args, "gateway")) { if (!strcmp(*args, "gw") || !strcmp(*args, "gateway")) {
args++; args++;
if (!*args) if (!*args)
return (usage()); return usage(E_OPTERR);
if (rt.rt_flags & RTF_GATEWAY) if (rt.rt_flags & RTF_GATEWAY)
return (usage()); return usage(E_OPTERR);
safe_strncpy(gateway, *args, (sizeof gateway)); safe_strncpy(gateway, *args, (sizeof gateway));
if ((isnet = inet_aftype.input(256, gateway, &rt.rt_gateway)) < 0) { if ((isnet = inet_aftype.input(256, gateway, &rt.rt_gateway)) < 0) {
inet_aftype.herror(gateway); inet_aftype.herror(gateway);
...@@ -157,7 +159,7 @@ static int INET_setroute(int action, int options, char **args) ...@@ -157,7 +159,7 @@ static int INET_setroute(int action, int options, char **args)
if (isnet) { if (isnet) {
fprintf(stderr, _("route: %s: cannot use a NETWORK as gateway!\n"), fprintf(stderr, _("route: %s: cannot use a NETWORK as gateway!\n"),
gateway); gateway);
return (E_OPTERR); return usage(E_OPTERR);
} }
rt.rt_flags |= RTF_GATEWAY; rt.rt_flags |= RTF_GATEWAY;
args++; args++;
...@@ -167,32 +169,32 @@ static int INET_setroute(int action, int options, char **args) ...@@ -167,32 +169,32 @@ static int INET_setroute(int action, int options, char **args)
args++; args++;
rt.rt_flags |= RTF_MSS; rt.rt_flags |= RTF_MSS;
if (!*args) if (!*args)
return (usage()); return usage(E_OPTERR);
rt.rt_mss = atoi(*args); rt.rt_mss = atoi(*args);
args++; args++;
if (rt.rt_mss < 64 || rt.rt_mss > 65536) { if (rt.rt_mss < 64 || rt.rt_mss > 65536) {
fprintf(stderr, _("route: Invalid MSS/MTU.\n")); fprintf(stderr, _("route: Invalid MSS/MTU.\n"));
return (E_OPTERR); return usage(E_OPTERR);
} }
continue; continue;
} }
if (!strcmp(*args, "window")) { if (!strcmp(*args, "window")) {
args++; args++;
if (!*args) if (!*args)
return (usage()); return usage(E_OPTERR);
rt.rt_flags |= RTF_WINDOW; rt.rt_flags |= RTF_WINDOW;
rt.rt_window = atoi(*args); rt.rt_window = atoi(*args);
args++; args++;
if (rt.rt_window < 128) { if (rt.rt_window < 128) {
fprintf(stderr, _("route: Invalid window.\n")); fprintf(stderr, _("route: Invalid window.\n"));
return (E_OPTERR); return usage(E_OPTERR);
} }
continue; continue;
} }
if (!strcmp(*args, "irtt")) { if (!strcmp(*args, "irtt")) {
args++; args++;
if (!*args) if (!*args)
return (usage()); return usage(E_OPTERR);
args++; args++;
#if HAVE_RTF_IRTT #if HAVE_RTF_IRTT
rt.rt_flags |= RTF_IRTT; rt.rt_flags |= RTF_IRTT;
...@@ -201,7 +203,7 @@ static int INET_setroute(int action, int options, char **args) ...@@ -201,7 +203,7 @@ static int INET_setroute(int action, int options, char **args)
#if 0 /* FIXME: do we need to check anything of this? */ #if 0 /* FIXME: do we need to check anything of this? */
if (rt.rt_irtt < 1 || rt.rt_irtt > (120 * HZ)) { if (rt.rt_irtt < 1 || rt.rt_irtt > (120 * HZ)) {
fprintf(stderr, _("route: Invalid initial rtt.\n")); fprintf(stderr, _("route: Invalid initial rtt.\n"));
return (E_OPTERR); return usage(E_OPTERR);
} }
#endif #endif
#else #else
...@@ -236,7 +238,7 @@ static int INET_setroute(int action, int options, char **args) ...@@ -236,7 +238,7 @@ static int INET_setroute(int action, int options, char **args)
if (!strcmp(*args, "device") || !strcmp(*args, "dev")) { if (!strcmp(*args, "device") || !strcmp(*args, "dev")) {
args++; args++;
if (rt.rt_dev || *args == NULL) if (rt.rt_dev || *args == NULL)
return usage(); return usage(E_OPTERR);
rt.rt_dev = *args++; rt.rt_dev = *args++;
continue; continue;
} }
...@@ -244,9 +246,9 @@ static int INET_setroute(int action, int options, char **args) ...@@ -244,9 +246,9 @@ static int INET_setroute(int action, int options, char **args)
if (!rt.rt_dev) { if (!rt.rt_dev) {
rt.rt_dev = *args++; rt.rt_dev = *args++;
if (*args) if (*args)
return usage(); /* must be last to catch typos */ return usage(E_OPTERR); /* must be last to catch typos */
} else } else
return usage(); return usage(E_OPTERR);
} }
#if HAVE_RTF_REJECT #if HAVE_RTF_REJECT
...@@ -259,16 +261,16 @@ static int INET_setroute(int action, int options, char **args) ...@@ -259,16 +261,16 @@ static int INET_setroute(int action, int options, char **args)
__u32 mask = ~ntohl(mask_in_addr(rt)); __u32 mask = ~ntohl(mask_in_addr(rt));
if ((rt.rt_flags & RTF_HOST) && mask != 0xffffffff) { if ((rt.rt_flags & RTF_HOST) && mask != 0xffffffff) {
fprintf(stderr, _("route: netmask %.8x doesn't make sense with host route\n"), mask); fprintf(stderr, _("route: netmask %.8x doesn't make sense with host route\n"), mask);
return (E_OPTERR); return usage(E_OPTERR);
} }
if (mask & (mask + 1)) { if (mask & (mask + 1)) {
fprintf(stderr, _("route: bogus netmask %s\n"), netmask); fprintf(stderr, _("route: bogus netmask %s\n"), netmask);
return (E_OPTERR); return usage(E_OPTERR);
} }
mask = ((struct sockaddr_in *) &rt.rt_dst)->sin_addr.s_addr; mask = ((struct sockaddr_in *) &rt.rt_dst)->sin_addr.s_addr;
if (mask & ~mask_in_addr(rt)) { if (mask & ~mask_in_addr(rt)) {
fprintf(stderr, _("route: netmask doesn't match route address\n")); fprintf(stderr, _("route: netmask doesn't match route address\n"));
return (E_OPTERR); return usage(E_OPTERR);
} }
} }
/* Fill out netmask if still unset */ /* Fill out netmask if still unset */
...@@ -304,14 +306,14 @@ int INET_rinput(int action, int options, char **args) ...@@ -304,14 +306,14 @@ int INET_rinput(int action, int options, char **args)
{ {
if (action == RTACTION_FLUSH) { if (action == RTACTION_FLUSH) {
fprintf(stderr, _("Flushing `inet' routing table not supported\n")); fprintf(stderr, _("Flushing `inet' routing table not supported\n"));
return (usage()); return usage(E_OPTERR);
} }
if (options & FLAG_CACHE) { if (options & FLAG_CACHE) {
fprintf(stderr, _("Modifying `inet' routing cache not supported\n")); fprintf(stderr, _("Modifying `inet' routing cache not supported\n"));
return (usage()); return usage(E_OPTERR);
} }
if ((*args == NULL) || (action == RTACTION_HELP)) if ((*args == NULL) || (action == RTACTION_HELP))
return (usage()); return usage(E_USAGE);
return (INET_setroute(action, options, args)); return (INET_setroute(action, options, args));
} }
......
/*
* ipx_sr.c This files contains IPX related route manipulation methods.
*
* Part of net-tools, the Linux base networking tools
*
* This program is free software; you can redistribute it and/or modif
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License.
*/
#include "config.h" #include "config.h"
#if HAVE_AFIPX #if HAVE_AFIPX
...@@ -31,6 +41,6 @@ int IPX_rinput(int action, int ext, char **args) ...@@ -31,6 +41,6 @@ int IPX_rinput(int action, int ext, char **args)
{ {
fprintf(stderr, _("IPX: this needs to be written\n")); fprintf(stderr, _("IPX: this needs to be written\n"));
return (0); return (E_NOSUPP);
} }
#endif /* HAVE_AFIPX */ #endif /* HAVE_AFIPX */
/*
* netrom_sr.c This files contains NETROM related route manipulation methods.
*
* Part of net-tools, the Linux base networking tools
*
* This program is free software; you can redistribute it and/or modif
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License.
*/
#include "config.h" #include "config.h"
#if HAVE_AFNETROM #if HAVE_AFNETROM
...@@ -27,13 +37,12 @@ extern struct aftype netrom_aftype; ...@@ -27,13 +37,12 @@ extern struct aftype netrom_aftype;
/* static int skfd = -1; */ /* static int skfd = -1; */
/* acme: orphaned... */
#if 0 #if 0
static int usage(void) static int usage(const int rc)
{ {
fprintf(stderr, _("netrom usage\n")); fprintf(stderr, _("netrom usage\n"));
return (E_USAGE); return (rc);
} }
#endif #endif
...@@ -42,6 +51,6 @@ int NETROM_rinput(int action, int ext, char **args) ...@@ -42,6 +51,6 @@ int NETROM_rinput(int action, int ext, char **args)
{ {
fprintf(stderr, _("NET/ROM: this needs to be written\n")); fprintf(stderr, _("NET/ROM: this needs to be written\n"));
return (0); return (E_NOSUPP);
} }
#endif /* HAVE_AFNETROM */ #endif /* HAVE_AFNETROM */
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
* lib/x25_sr.c This file contains an implementation of the "X.25" * lib/x25_sr.c This file contains an implementation of the "X.25"
* route change support functions. * route change support functions.
* *
* Version: @(#)x25_sr.c 1.00 08/15/98
*
* Author: Stephane Fillod, <sfillod@charybde.gyptis.frmug.org> * Author: Stephane Fillod, <sfillod@charybde.gyptis.frmug.org>
* based on inet_sr.c * based on inet_sr.c
* *
...@@ -47,11 +45,11 @@ extern struct aftype x25_aftype; ...@@ -47,11 +45,11 @@ extern struct aftype x25_aftype;
static int skfd = -1; static int skfd = -1;
static int usage(void) static int usage(const int rc)
{ {
fprintf(stderr,"Usage: x25_route [-v] del Target[/mask] [dev] If\n"); fprintf(stderr,"Usage: x25_route [-v] del Target[/mask] [dev] If\n");
fprintf(stderr," x25_route [-v] add Target[/mask] [dev] If\n"); fprintf(stderr," x25_route [-v] add Target[/mask] [dev] If\n");
return(E_USAGE); return(rc);
} }
...@@ -63,7 +61,7 @@ static int X25_setroute(int action, int options, char **args) ...@@ -63,7 +61,7 @@ static int X25_setroute(int action, int options, char **args)
signed int sigdigits; signed int sigdigits;
if (*args == NULL) if (*args == NULL)
return(usage()); return usage(E_OPTERR);
safe_strncpy(target, *args++, sizeof(target)); safe_strncpy(target, *args++, sizeof(target));
...@@ -73,7 +71,7 @@ static int X25_setroute(int action, int options, char **args) ...@@ -73,7 +71,7 @@ static int X25_setroute(int action, int options, char **args)
if ((sigdigits = x25_aftype.input(0, target, (struct sockaddr *)&sx25)) < 0) { if ((sigdigits = x25_aftype.input(0, target, (struct sockaddr *)&sx25)) < 0) {
x25_aftype.herror(target); x25_aftype.herror(target);
return (1); return (E_LOOKUP);
} }
rt.sigdigits=sigdigits; rt.sigdigits=sigdigits;
...@@ -84,27 +82,27 @@ static int X25_setroute(int action, int options, char **args) ...@@ -84,27 +82,27 @@ static int X25_setroute(int action, int options, char **args)
if (!strcmp(*args,"device") || !strcmp(*args,"dev")) { if (!strcmp(*args,"device") || !strcmp(*args,"dev")) {
args++; args++;
if (!*args) if (!*args)
return(usage()); return usage(E_OPTERR);
} else } else
if (args[1]) if (args[1])
return(usage()); return usage(E_OPTERR);
if (rt.device[0]) if (rt.device[0])
return(usage()); return usage(E_OPTERR);
safe_strncpy(rt.device, *args, sizeof(rt.device)); safe_strncpy(rt.device, *args, sizeof(rt.device));
args++; args++;
} }
if (rt.device[0]=='\0') if (rt.device[0]=='\0')
return(usage()); return usage(E_OPTERR);
/* sanity checks.. */ /* sanity checks.. */
if (rt.sigdigits > 15) { if (rt.sigdigits > 15) {
fprintf(stderr, _("route: bogus netmask %d\n"), rt.sigdigits); fprintf(stderr, _("route: bogus netmask %d\n"), rt.sigdigits);
return(E_OPTERR); return usage(E_OPTERR);
} }
if (rt.sigdigits > strlen(rt.address.x25_addr)) { if (rt.sigdigits > strlen(rt.address.x25_addr)) {
fprintf(stderr, _("route: netmask doesn't match route address\n")); fprintf(stderr, _("route: netmask doesn't match route address\n"));
return(E_OPTERR); return usage(E_OPTERR);
} }
/* Create a socket to the X25 kernel. */ /* Create a socket to the X25 kernel. */
...@@ -137,14 +135,14 @@ int X25_rinput(int action, int options, char **args) ...@@ -137,14 +135,14 @@ int X25_rinput(int action, int options, char **args)
{ {
if (action == RTACTION_FLUSH) { if (action == RTACTION_FLUSH) {
fprintf(stderr,"Flushing `x25' routing table not supported\n"); fprintf(stderr,"Flushing `x25' routing table not supported\n");
return(usage()); return usage(E_OPTERR);
} }
if (options & FLAG_CACHE) { if (options & FLAG_CACHE) {
fprintf(stderr,"Modifying `x25' routing cache not supported\n"); fprintf(stderr,"Modifying `x25' routing cache not supported\n");
return(usage()); return usage(E_OPTERR);
} }
if ((*args == NULL) || (action == RTACTION_HELP)) if (action == RTACTION_HELP)
return(usage()); return usage(E_USAGE);
return(X25_setroute(action, options, args)); return(X25_setroute(action, options, args));
} }
......
...@@ -76,7 +76,7 @@ int opt_fc = 0; // routing cache/FIB ...@@ -76,7 +76,7 @@ int opt_fc = 0; // routing cache/FIB
int opt_h = 0; // help selected int opt_h = 0; // help selected
struct aftype *ap; // selected address family struct aftype *ap; // selected address family
static void usage(void) static void usage(int rc)
{ {
fprintf(stderr, _("Usage: route [-nNvee] [-FC] [<AF>] List kernel routing tables\n")); fprintf(stderr, _("Usage: route [-nNvee] [-FC] [<AF>] List kernel routing tables\n"));
fprintf(stderr, _(" route [-v] [-FC] {add|del|flush} ... Modify routing table for AF.\n\n")); fprintf(stderr, _(" route [-v] [-FC] {add|del|flush} ... Modify routing table for AF.\n\n"));
...@@ -93,7 +93,7 @@ static void usage(void) ...@@ -93,7 +93,7 @@ static void usage(void)
fprintf(stderr, _(" <AF>=Use -4, -6, '-A <af>' or '--<af>'; default: %s\n"), DFLT_AF); fprintf(stderr, _(" <AF>=Use -4, -6, '-A <af>' or '--<af>'; default: %s\n"), DFLT_AF);
fprintf(stderr, _(" List of possible address families (which support routing):\n")); fprintf(stderr, _(" List of possible address families (which support routing):\n"));
print_aflist(1); /* 1 = routeable */ print_aflist(1); /* 1 = routeable */
exit(E_USAGE); exit(rc);
} }
...@@ -190,7 +190,7 @@ int main(int argc, char **argv) ...@@ -190,7 +190,7 @@ int main(int argc, char **argv)
opt_h++; opt_h++;
break; break;
default: default:
usage(); usage(E_OPTERR);
} }
argv += optind; argv += optind;
...@@ -198,7 +198,7 @@ int main(int argc, char **argv) ...@@ -198,7 +198,7 @@ int main(int argc, char **argv)
if (opt_h) { if (opt_h) {
if (!afname[0]) if (!afname[0])
usage(); usage(E_USAGE);
else else
what = RTACTION_HELP; what = RTACTION_HELP;
} else { } else {
...@@ -217,7 +217,7 @@ int main(int argc, char **argv) ...@@ -217,7 +217,7 @@ int main(int argc, char **argv)
else if (!strcmp(*argv, "flush")) else if (!strcmp(*argv, "flush"))
what = RTACTION_FLUSH; what = RTACTION_FLUSH;
else else
usage(); usage(E_OPTERR);
} }
} }
...@@ -230,8 +230,5 @@ int main(int argc, char **argv) ...@@ -230,8 +230,5 @@ int main(int argc, char **argv)
else else
i = route_edit(what, afname, options, ++argv); i = route_edit(what, afname, options, ++argv);
if (i == E_OPTERR)
usage();
return (i); return (i);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment