accidentally applied wrong (old) patch, fixing up...
[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 <string.h>
19
20 #include "libbb.h"
21 #include "utils.h"
22 #include "ip_common.h"
23
24
25 int preferred_family = AF_UNSPEC;
26 int oneline = 0;
27 char * _SL_ = NULL;
28
29 void ip_parse_common_args(int *argcp, char ***argvp)
30 {
31         int argc = *argcp;
32         char **argv = *argvp;
33
34         while (argc > 1) {
35                 char *opt = argv[1];
36
37                 if (strcmp(opt,"--") == 0) {
38                         argc--;
39                         argv++;
40                         break;
41                 }
42
43                 if (opt[0] != '-')
44                         break;
45
46                 if (opt[1] == '-')
47                         opt++;
48
49                 if (matches(opt, "-family") == 0) {
50                         argc--;
51                         argv++;
52                         if (!argv[1])
53                                 bb_show_usage();
54                         if (strcmp(argv[1], "inet") == 0)
55                                 preferred_family = AF_INET;
56                         else if (strcmp(argv[1], "inet6") == 0)
57                                 preferred_family = AF_INET6;
58                         else if (strcmp(argv[1], "link") == 0)
59                                 preferred_family = AF_PACKET;
60                         else
61                                 invarg(argv[1], "protocol family");
62                 } else if (strcmp(opt, "-4") == 0) {
63                         preferred_family = AF_INET;
64                 } else if (strcmp(opt, "-6") == 0) {
65                         preferred_family = AF_INET6;
66                 } else if (strcmp(opt, "-0") == 0) {
67                         preferred_family = AF_PACKET;
68                 } else if (matches(opt, "-oneline") == 0) {
69                         ++oneline;
70                 } else {
71                         bb_show_usage();
72                 }
73                 argc--;
74                 argv++;
75         }
76         _SL_ = oneline ? "\\" : "\n" ;
77         *argcp = argc;
78         *argvp = argv;
79 }