2006-07-03 01:17:05 +05:30
|
|
|
/* vi: set sw=4 ts=4: */
|
2002-12-02 04:34:06 +05:30
|
|
|
/*
|
2010-10-29 15:16:52 +05:30
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version
|
|
|
|
* 2 of the License, or (at your option) any later version.
|
2002-12-02 04:34:06 +05:30
|
|
|
*
|
2010-10-29 15:16:52 +05:30
|
|
|
* Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
|
2002-12-02 04:34:06 +05:30
|
|
|
*
|
|
|
|
* Changes:
|
|
|
|
*
|
2010-10-29 15:16:52 +05:30
|
|
|
* Rani Assaf <rani@magic.metawire.com> 980929: resolve addresses
|
2002-12-02 04:34:06 +05:30
|
|
|
*/
|
2007-06-01 04:12:12 +05:30
|
|
|
#include "ip_common.h" /* #include "libbb.h" is inside */
|
2002-12-02 04:34:06 +05:30
|
|
|
#include "utils.h"
|
|
|
|
|
2007-11-19 04:26:25 +05:30
|
|
|
family_t preferred_family = AF_UNSPEC;
|
2007-04-07 06:44:45 +05:30
|
|
|
smallint oneline;
|
|
|
|
char _SL_;
|
2002-12-02 04:34:06 +05:30
|
|
|
|
2010-07-25 02:57:38 +05:30
|
|
|
char** FAST_FUNC ip_parse_common_args(char **argv)
|
2002-12-02 04:34:06 +05:30
|
|
|
{
|
2007-08-13 02:28:27 +05:30
|
|
|
static const char ip_common_commands[] ALIGN1 =
|
2007-11-19 04:26:25 +05:30
|
|
|
"oneline" "\0"
|
|
|
|
"family" "\0"
|
|
|
|
"4" "\0"
|
|
|
|
"6" "\0"
|
|
|
|
"0" "\0"
|
|
|
|
;
|
2007-06-20 18:12:03 +05:30
|
|
|
enum {
|
2007-11-19 04:26:25 +05:30
|
|
|
ARG_oneline,
|
|
|
|
ARG_family,
|
2007-06-20 18:12:03 +05:30
|
|
|
ARG_IPv4,
|
|
|
|
ARG_IPv6,
|
|
|
|
ARG_packet,
|
|
|
|
};
|
2007-11-19 04:26:25 +05:30
|
|
|
static const family_t af_numbers[] = { AF_INET, AF_INET6, AF_PACKET };
|
|
|
|
int arg;
|
2002-12-02 04:34:06 +05:30
|
|
|
|
2007-11-19 04:26:25 +05:30
|
|
|
while (*argv) {
|
|
|
|
char *opt = *argv;
|
2002-12-02 04:34:06 +05:30
|
|
|
|
|
|
|
if (opt[0] != '-')
|
|
|
|
break;
|
2007-11-19 04:26:25 +05:30
|
|
|
opt++;
|
|
|
|
if (opt[0] == '-') {
|
2002-12-02 04:34:06 +05:30
|
|
|
opt++;
|
2007-11-19 04:26:25 +05:30
|
|
|
if (!opt[0]) { /* "--" */
|
|
|
|
argv++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-05-31 13:04:14 +05:30
|
|
|
arg = index_in_substrings(ip_common_commands, opt);
|
2007-11-19 04:26:25 +05:30
|
|
|
if (arg < 0)
|
|
|
|
bb_show_usage();
|
|
|
|
if (arg == ARG_oneline) {
|
|
|
|
oneline = 1;
|
|
|
|
argv++;
|
|
|
|
continue;
|
|
|
|
}
|
2007-06-20 18:12:03 +05:30
|
|
|
if (arg == ARG_family) {
|
2007-11-19 04:26:25 +05:30
|
|
|
static const char families[] ALIGN1 =
|
|
|
|
"inet" "\0" "inet6" "\0" "link" "\0";
|
2002-12-02 04:34:06 +05:30
|
|
|
argv++;
|
2007-11-19 04:26:25 +05:30
|
|
|
if (!*argv)
|
2006-10-04 01:26:34 +05:30
|
|
|
bb_show_usage();
|
2007-11-19 04:26:25 +05:30
|
|
|
arg = index_in_strings(families, *argv);
|
|
|
|
if (arg < 0)
|
2015-10-14 16:51:01 +05:30
|
|
|
invarg_1_to_2(*argv, "family");
|
2007-11-19 04:26:25 +05:30
|
|
|
/* now arg == 0, 1 or 2 */
|
2002-12-02 04:34:06 +05:30
|
|
|
} else {
|
2007-11-19 04:26:25 +05:30
|
|
|
arg -= ARG_IPv4;
|
|
|
|
/* now arg == 0, 1 or 2 */
|
2002-12-02 04:34:06 +05:30
|
|
|
}
|
2007-11-19 04:26:25 +05:30
|
|
|
preferred_family = af_numbers[arg];
|
2007-01-02 22:02:16 +05:30
|
|
|
argv++;
|
2002-12-02 04:34:06 +05:30
|
|
|
}
|
2007-07-21 20:38:09 +05:30
|
|
|
_SL_ = oneline ? '\\' : '\n';
|
2007-11-19 04:26:25 +05:30
|
|
|
return argv;
|
2002-12-02 04:34:06 +05:30
|
|
|
}
|