Last change
on this file since 2811 was 2725, checked in by Bruno Cornec, 13 years ago |
- Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
|
File size:
1.6 KB
|
Rev | Line | |
---|
[1765] | 1 | /* vi: set sw=4 ts=4: */
|
---|
[821] | 2 | /*
|
---|
[2725] | 3 | * This program is free software; you can redistribute it and/or
|
---|
| 4 | * modify it under the terms of the GNU General Public License
|
---|
| 5 | * as published by the Free Software Foundation; either version
|
---|
| 6 | * 2 of the License, or (at your option) any later version.
|
---|
[821] | 7 | *
|
---|
[2725] | 8 | * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
|
---|
[821] | 9 | *
|
---|
| 10 | * Changes:
|
---|
| 11 | *
|
---|
[2725] | 12 | * Rani Assaf <rani@magic.metawire.com> 980929: resolve addresses
|
---|
[821] | 13 | */
|
---|
| 14 |
|
---|
[1765] | 15 | #include "ip_common.h" /* #include "libbb.h" is inside */
|
---|
[821] | 16 | #include "utils.h"
|
---|
| 17 |
|
---|
[2725] | 18 | family_t preferred_family = AF_UNSPEC;
|
---|
[1765] | 19 | smallint oneline;
|
---|
| 20 | char _SL_;
|
---|
[821] | 21 |
|
---|
[2725] | 22 | char** FAST_FUNC ip_parse_common_args(char **argv)
|
---|
[821] | 23 | {
|
---|
[1765] | 24 | static const char ip_common_commands[] ALIGN1 =
|
---|
[2725] | 25 | "oneline" "\0"
|
---|
| 26 | "family" "\0"
|
---|
| 27 | "4" "\0"
|
---|
| 28 | "6" "\0"
|
---|
| 29 | "0" "\0"
|
---|
| 30 | ;
|
---|
[1765] | 31 | enum {
|
---|
[2725] | 32 | ARG_oneline,
|
---|
| 33 | ARG_family,
|
---|
[1765] | 34 | ARG_IPv4,
|
---|
| 35 | ARG_IPv6,
|
---|
| 36 | ARG_packet,
|
---|
| 37 | };
|
---|
[2725] | 38 | static const family_t af_numbers[] = { AF_INET, AF_INET6, AF_PACKET };
|
---|
| 39 | int arg;
|
---|
[821] | 40 |
|
---|
[2725] | 41 | while (*argv) {
|
---|
| 42 | char *opt = *argv;
|
---|
[821] | 43 |
|
---|
| 44 | if (opt[0] != '-')
|
---|
| 45 | break;
|
---|
[2725] | 46 | opt++;
|
---|
| 47 | if (opt[0] == '-') {
|
---|
[821] | 48 | opt++;
|
---|
[2725] | 49 | if (!opt[0]) { /* "--" */
|
---|
| 50 | argv++;
|
---|
| 51 | break;
|
---|
| 52 | }
|
---|
| 53 | }
|
---|
| 54 | arg = index_in_substrings(ip_common_commands, opt);
|
---|
| 55 | if (arg < 0)
|
---|
| 56 | bb_show_usage();
|
---|
| 57 | if (arg == ARG_oneline) {
|
---|
| 58 | oneline = 1;
|
---|
| 59 | argv++;
|
---|
| 60 | continue;
|
---|
| 61 | }
|
---|
[1765] | 62 | if (arg == ARG_family) {
|
---|
[2725] | 63 | static const char families[] ALIGN1 =
|
---|
| 64 | "inet" "\0" "inet6" "\0" "link" "\0";
|
---|
[821] | 65 | argv++;
|
---|
[2725] | 66 | if (!*argv)
|
---|
[1765] | 67 | bb_show_usage();
|
---|
[2725] | 68 | arg = index_in_strings(families, *argv);
|
---|
| 69 | if (arg < 0)
|
---|
| 70 | invarg(*argv, "protocol family");
|
---|
| 71 | /* now arg == 0, 1 or 2 */
|
---|
[821] | 72 | } else {
|
---|
[2725] | 73 | arg -= ARG_IPv4;
|
---|
| 74 | /* now arg == 0, 1 or 2 */
|
---|
[821] | 75 | }
|
---|
[2725] | 76 | preferred_family = af_numbers[arg];
|
---|
[1765] | 77 | argv++;
|
---|
[821] | 78 | }
|
---|
[1765] | 79 | _SL_ = oneline ? '\\' : '\n';
|
---|
[2725] | 80 | return argv;
|
---|
[821] | 81 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.