Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/networking/libiproute/ip_parse_common_args.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/networking/libiproute/ip_parse_common_args.c
r1765 r2725 1 1 /* vi: set sw=4 ts=4: */ 2 2 /* 3 * ip.c "ip" utility frontend. 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. 4 7 * 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 * 8 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> 12 9 * 13 10 * Changes: 14 11 * 15 * Rani Assaf <rani@magic.metawire.com> 980929: 12 * Rani Assaf <rani@magic.metawire.com> 980929: resolve addresses 16 13 */ 17 14 … … 19 16 #include "utils.h" 20 17 21 int preferred_family = AF_UNSPEC;18 family_t preferred_family = AF_UNSPEC; 22 19 smallint oneline; 23 20 char _SL_; 24 21 25 void ip_parse_common_args(int *argcp, char ***argvp)22 char** FAST_FUNC ip_parse_common_args(char **argv) 26 23 { 27 int argc = *argcp;28 char **argv = *argvp;29 24 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"; 25 "oneline" "\0" 26 "family" "\0" 27 "4" "\0" 28 "6" "\0" 29 "0" "\0" 30 ; 32 31 enum { 33 ARG_family = 1, 34 ARG_inet, 35 ARG_inet6, 36 ARG_link, 32 ARG_oneline, 33 ARG_family, 37 34 ARG_IPv4, 38 35 ARG_IPv6, 39 36 ARG_packet, 40 ARG_oneline41 37 }; 42 smalluint arg; 38 static const family_t af_numbers[] = { AF_INET, AF_INET6, AF_PACKET }; 39 int arg; 43 40 44 while ( argc > 1) {45 char *opt = argv[1];41 while (*argv) { 42 char *opt = *argv; 46 43 47 if (strcmp(opt,"--") == 0) {48 argc--;49 argv++;50 break;51 }52 44 if (opt[0] != '-') 53 45 break; 54 if (opt[1] == '-') 46 opt++; 47 if (opt[0] == '-') { 55 48 opt++; 56 arg = index_in_strings(ip_common_commands, opt) + 1; 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 } 57 62 if (arg == ARG_family) { 58 argc--; 63 static const char families[] ALIGN1 = 64 "inet" "\0" "inet6" "\0" "link" "\0"; 59 65 argv++; 60 if (! argv[1])66 if (!*argv) 61 67 bb_show_usage(); 62 arg = index_in_strings(ip_common_commands, argv[1]) + 1; 63 if (arg == ARG_inet) 64 preferred_family = AF_INET; 65 else if (arg == ARG_inet6) 66 preferred_family = AF_INET6; 67 else if (arg == ARG_link) 68 preferred_family = AF_PACKET; 69 else 70 invarg(argv[1], "protocol family"); 71 } else if (arg == ARG_IPv4) { 72 preferred_family = AF_INET; 73 } else if (arg == ARG_IPv6) { 74 preferred_family = AF_INET6; 75 } else if (arg == ARG_packet) { 76 preferred_family = AF_PACKET; 77 } else if (arg == ARG_oneline) { 78 ++oneline; 68 arg = index_in_strings(families, *argv); 69 if (arg < 0) 70 invarg(*argv, "protocol family"); 71 /* now arg == 0, 1 or 2 */ 79 72 } else { 80 bb_show_usage(); 73 arg -= ARG_IPv4; 74 /* now arg == 0, 1 or 2 */ 81 75 } 82 argc--;76 preferred_family = af_numbers[arg]; 83 77 argv++; 84 78 } 85 79 _SL_ = oneline ? '\\' : '\n'; 86 *argcp = argc; 87 *argvp = argv; 80 return argv; 88 81 }
Note:
See TracChangeset
for help on using the changeset viewer.