pscan: new applet (portscanner). ~1350 bytes. By Tito <farmatito@tiscali.it>
[oweals/busybox.git] / networking / libiproute / ip_parse_common_args.c
1 /* vi: set sw=4 ts=4: */
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
18 #include "ip_common.h"  /* #include "libbb.h" is inside */
19 #include "utils.h"
20
21 int preferred_family = AF_UNSPEC;
22 smallint oneline;
23 char _SL_;
24
25 void ip_parse_common_args(int *argcp, char ***argvp)
26 {
27         int argc = *argcp;
28         char **argv = *argvp;
29
30         while (argc > 1) {
31                 char *opt = argv[1];
32
33                 if (strcmp(opt,"--") == 0) {
34                         argc--;
35                         argv++;
36                         break;
37                 }
38
39                 if (opt[0] != '-')
40                         break;
41
42                 if (opt[1] == '-')
43                         opt++;
44
45                 if (matches(opt, "-family") == 0) {
46                         argc--;
47                         argv++;
48                         if (!argv[1])
49                                 bb_show_usage();
50                         if (strcmp(argv[1], "inet") == 0)
51                                 preferred_family = AF_INET;
52                         else if (strcmp(argv[1], "inet6") == 0)
53                                 preferred_family = AF_INET6;
54                         else if (strcmp(argv[1], "link") == 0)
55                                 preferred_family = AF_PACKET;
56                         else
57                                 invarg(argv[1], "protocol family");
58                 } else if (strcmp(opt, "-4") == 0) {
59                         preferred_family = AF_INET;
60                 } else if (strcmp(opt, "-6") == 0) {
61                         preferred_family = AF_INET6;
62                 } else if (strcmp(opt, "-0") == 0) {
63                         preferred_family = AF_PACKET;
64                 } else if (matches(opt, "-oneline") == 0) {
65                         ++oneline;
66                 } else {
67                         bb_show_usage();
68                 }
69                 argc--;
70                 argv++;
71         }
72         _SL_ = oneline ? '\\' : '\n' ;
73         *argcp = argc;
74         *argvp = argv;
75 }