550d1ddfe28589c162a84d4c0f2167fb970df67a
[oweals/busybox.git] / networking / libiproute / ip_parse_common_args.c
1 /*
2  * ip.c         "ip" utility frontend.
3  *
4  *              This program is free software; you can redistribute it and/or
5  *              modify it under the terms of the GNU General Public License
6  *              as published by the Free Software Foundation; either version
7  *              2 of the License, or (at your option) any later version.
8  *
9  * Authors:     Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
10  *
11  *
12  * Changes:
13  *
14  * Rani Assaf <rani@magic.metawire.com> 980929: resolve addresses
15  */
16
17 #include "utils.h"
18 #include "ip_common.h"
19
20 #include "busybox.h"
21
22 int preferred_family = AF_UNSPEC;
23 int oneline = 0;
24 char * _SL_ = NULL;
25
26 void ip_parse_common_args(int *argcp, char ***argvp)
27 {
28         int argc = *argcp;
29         char **argv = *argvp;
30
31         while (argc > 1) {
32                 char *opt = argv[1];
33
34                 if (strcmp(opt,"--") == 0) {
35                         argc--; 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 (strcmp(argv[1], "inet") == 0)
49                                 preferred_family = AF_INET;
50                         else if (strcmp(argv[1], "inet6") == 0)
51                                 preferred_family = AF_INET6;
52                         else if (strcmp(argv[1], "link") == 0)
53                                 preferred_family = AF_PACKET;
54                         else
55                                 invarg(argv[1], "invalid protocol family");
56                 } else if (strcmp(opt, "-4") == 0) {
57                         preferred_family = AF_INET;
58                 } else if (strcmp(opt, "-6") == 0) {
59                         preferred_family = AF_INET6;
60                 } else if (strcmp(opt, "-0") == 0) {
61                         preferred_family = AF_PACKET;
62                 } else if (matches(opt, "-oneline") == 0) {
63                         ++oneline;
64                 } else {
65                         show_usage();
66                 }
67                 argc--; argv++;
68         }
69         _SL_ = oneline ? "\\" : "\n" ;
70 }