[1765] | 1 | /* vi: set sw=4 ts=4: */
|
---|
[821] | 2 | /*
|
---|
| 3 | * ip.c "ip" utility frontend.
|
---|
| 4 | *
|
---|
| 5 | * This program is free software; you can redistribute it and/or
|
---|
| 6 | * modify it under the terms of the GNU General Public License
|
---|
| 7 | * as published by the Free Software Foundation; either version
|
---|
| 8 | * 2 of the License, or (at your option) any later version.
|
---|
| 9 | *
|
---|
| 10 | * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
|
---|
| 11 | *
|
---|
| 12 | *
|
---|
| 13 | * Changes:
|
---|
| 14 | *
|
---|
| 15 | * Rani Assaf <rani@magic.metawire.com> 980929: resolve addresses
|
---|
| 16 | */
|
---|
| 17 |
|
---|
[1765] | 18 | #include "ip_common.h" /* #include "libbb.h" is inside */
|
---|
[821] | 19 | #include "utils.h"
|
---|
| 20 |
|
---|
| 21 | int preferred_family = AF_UNSPEC;
|
---|
[1765] | 22 | smallint oneline;
|
---|
| 23 | char _SL_;
|
---|
[821] | 24 |
|
---|
| 25 | void ip_parse_common_args(int *argcp, char ***argvp)
|
---|
| 26 | {
|
---|
| 27 | int argc = *argcp;
|
---|
| 28 | char **argv = *argvp;
|
---|
[1765] | 29 | static const char ip_common_commands[] ALIGN1 =
|
---|
| 30 | "-family\0""inet\0""inet6\0""link\0"
|
---|
| 31 | "-4\0""-6\0""-0\0""-oneline\0";
|
---|
| 32 | enum {
|
---|
| 33 | ARG_family = 1,
|
---|
| 34 | ARG_inet,
|
---|
| 35 | ARG_inet6,
|
---|
| 36 | ARG_link,
|
---|
| 37 | ARG_IPv4,
|
---|
| 38 | ARG_IPv6,
|
---|
| 39 | ARG_packet,
|
---|
| 40 | ARG_oneline
|
---|
| 41 | };
|
---|
| 42 | smalluint arg;
|
---|
[821] | 43 |
|
---|
| 44 | while (argc > 1) {
|
---|
| 45 | char *opt = argv[1];
|
---|
| 46 |
|
---|
| 47 | if (strcmp(opt,"--") == 0) {
|
---|
[1765] | 48 | argc--;
|
---|
| 49 | argv++;
|
---|
[821] | 50 | break;
|
---|
| 51 | }
|
---|
| 52 | if (opt[0] != '-')
|
---|
| 53 | break;
|
---|
| 54 | if (opt[1] == '-')
|
---|
| 55 | opt++;
|
---|
[1765] | 56 | arg = index_in_strings(ip_common_commands, opt) + 1;
|
---|
| 57 | if (arg == ARG_family) {
|
---|
[821] | 58 | argc--;
|
---|
| 59 | argv++;
|
---|
[1765] | 60 | if (!argv[1])
|
---|
| 61 | bb_show_usage();
|
---|
| 62 | arg = index_in_strings(ip_common_commands, argv[1]) + 1;
|
---|
| 63 | if (arg == ARG_inet)
|
---|
[821] | 64 | preferred_family = AF_INET;
|
---|
[1765] | 65 | else if (arg == ARG_inet6)
|
---|
[821] | 66 | preferred_family = AF_INET6;
|
---|
[1765] | 67 | else if (arg == ARG_link)
|
---|
[821] | 68 | preferred_family = AF_PACKET;
|
---|
| 69 | else
|
---|
| 70 | invarg(argv[1], "protocol family");
|
---|
[1765] | 71 | } else if (arg == ARG_IPv4) {
|
---|
[821] | 72 | preferred_family = AF_INET;
|
---|
[1765] | 73 | } else if (arg == ARG_IPv6) {
|
---|
[821] | 74 | preferred_family = AF_INET6;
|
---|
[1765] | 75 | } else if (arg == ARG_packet) {
|
---|
[821] | 76 | preferred_family = AF_PACKET;
|
---|
[1765] | 77 | } else if (arg == ARG_oneline) {
|
---|
[821] | 78 | ++oneline;
|
---|
| 79 | } else {
|
---|
| 80 | bb_show_usage();
|
---|
| 81 | }
|
---|
[1765] | 82 | argc--;
|
---|
| 83 | argv++;
|
---|
[821] | 84 | }
|
---|
[1765] | 85 | _SL_ = oneline ? '\\' : '\n';
|
---|
[821] | 86 | *argcp = argc;
|
---|
| 87 | *argvp = argv;
|
---|
| 88 | }
|
---|