1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- #include "ip_common.h"
- #include "utils.h"
- family_t preferred_family = AF_UNSPEC;
- smallint oneline;
- char _SL_;
- char** FAST_FUNC ip_parse_common_args(char **argv)
- {
- static const char ip_common_commands[] ALIGN1 =
- "oneline" "\0"
- "family" "\0"
- "4" "\0"
- "6" "\0"
- "0" "\0"
- ;
- enum {
- ARG_oneline,
- ARG_family,
- ARG_IPv4,
- ARG_IPv6,
- ARG_packet,
- };
- static const family_t af_numbers[] = { AF_INET, AF_INET6, AF_PACKET };
- int arg;
- while (*argv) {
- char *opt = *argv;
- if (opt[0] != '-')
- break;
- opt++;
- if (opt[0] == '-') {
- opt++;
- if (!opt[0]) {
- argv++;
- break;
- }
- }
- arg = index_in_substrings(ip_common_commands, opt);
- if (arg < 0)
- bb_show_usage();
- if (arg == ARG_oneline) {
- oneline = 1;
- argv++;
- continue;
- }
- if (arg == ARG_family) {
- static const char families[] ALIGN1 =
- "inet" "\0" "inet6" "\0" "link" "\0";
- argv++;
- if (!*argv)
- bb_show_usage();
- arg = index_in_strings(families, *argv);
- if (arg < 0)
- invarg_1_to_2(*argv, "family");
-
- } else {
- arg -= ARG_IPv4;
-
- }
- preferred_family = af_numbers[arg];
- argv++;
- }
- _SL_ = oneline ? '\\' : '\n';
- return argv;
- }
|