Save a few more bytes

This commit is contained in:
Glenn L McGrath 2002-12-02 00:54:10 +00:00
parent c82f2324bd
commit 18eae0031a

View File

@ -534,6 +534,7 @@ static int iproute_get(int argc, char **argv)
char *odev = NULL; char *odev = NULL;
int connected = 0; int connected = 0;
int from_ok = 0; int from_ok = 0;
const char *options[] = { "from", "iif", "oif", "dev", "notify", "connected", "to", 0 };
memset(&req, 0, sizeof(req)); memset(&req, 0, sizeof(req));
@ -552,41 +553,54 @@ static int iproute_get(int argc, char **argv)
req.r.rtm_tos = 0; req.r.rtm_tos = 0;
while (argc > 0) { while (argc > 0) {
if (matches(*argv, "from") == 0) { switch (compare_string_array(options, *argv)) {
case 0: /* from */
{
inet_prefix addr; inet_prefix addr;
NEXT_ARG(); NEXT_ARG();
from_ok = 1; from_ok = 1;
get_prefix(&addr, *argv, req.r.rtm_family); get_prefix(&addr, *argv, req.r.rtm_family);
if (req.r.rtm_family == AF_UNSPEC) if (req.r.rtm_family == AF_UNSPEC) {
req.r.rtm_family = addr.family; req.r.rtm_family = addr.family;
if (addr.bytelen) }
if (addr.bytelen) {
addattr_l(&req.n, sizeof(req), RTA_SRC, &addr.data, addr.bytelen); addattr_l(&req.n, sizeof(req), RTA_SRC, &addr.data, addr.bytelen);
}
req.r.rtm_src_len = addr.bitlen; req.r.rtm_src_len = addr.bitlen;
} else if (matches(*argv, "iif") == 0) { break;
}
case 1: /* iif */
NEXT_ARG(); NEXT_ARG();
idev = *argv; idev = *argv;
} else if (matches(*argv, "oif") == 0 || break;
strcmp(*argv, "dev") == 0) { case 2: /* oif */
case 3: /* dev */
NEXT_ARG(); NEXT_ARG();
odev = *argv; odev = *argv;
} else if (matches(*argv, "notify") == 0) { break;
case 4: /* notify */
req.r.rtm_flags |= RTM_F_NOTIFY; req.r.rtm_flags |= RTM_F_NOTIFY;
} else if (matches(*argv, "connected") == 0) { break;
case 5: /* connected */
connected = 1; connected = 1;
} else { break;
inet_prefix addr; case 6: /* to */
if (strcmp(*argv, "to") == 0) {
NEXT_ARG(); NEXT_ARG();
} default:
{
inet_prefix addr;
get_prefix(&addr, *argv, req.r.rtm_family); get_prefix(&addr, *argv, req.r.rtm_family);
if (req.r.rtm_family == AF_UNSPEC) if (req.r.rtm_family == AF_UNSPEC) {
req.r.rtm_family = addr.family; req.r.rtm_family = addr.family;
if (addr.bytelen) }
if (addr.bytelen) {
addattr_l(&req.n, sizeof(req), RTA_DST, &addr.data, addr.bytelen); addattr_l(&req.n, sizeof(req), RTA_DST, &addr.data, addr.bytelen);
}
req.r.rtm_dst_len = addr.bitlen; req.r.rtm_dst_len = addr.bitlen;
} }
argc--; argv++; argc--; argv++;
} }
}
if (req.r.rtm_dst_len == 0) { if (req.r.rtm_dst_len == 0) {
error_msg_and_die("need at least destination address"); error_msg_and_die("need at least destination address");