Standardize on the vi editing directives being on the first line.
[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--; argv++;
39                         break;
40                 }
41
42                 if (opt[0] != '-')
43                         break;
44
45                 if (opt[1] == '-')
46                         opt++;
47
48                 if (matches(opt, "-family") == 0) {
49                         argc--;
50                         argv++;
51                         if (! argv[1])
52                             bb_show_usage();
53                         if (strcmp(argv[1], "inet") == 0)
54                                 preferred_family = AF_INET;
55                         else if (strcmp(argv[1], "inet6") == 0)
56                                 preferred_family = AF_INET6;
57                         else if (strcmp(argv[1], "link") == 0)
58                                 preferred_family = AF_PACKET;
59                         else
60                                 invarg(argv[1], "protocol family");
61                 } else if (strcmp(opt, "-4") == 0) {
62                         preferred_family = AF_INET;
63                 } else if (strcmp(opt, "-6") == 0) {
64                         preferred_family = AF_INET6;
65                 } else if (strcmp(opt, "-0") == 0) {
66                         preferred_family = AF_PACKET;
67                 } else if (matches(opt, "-oneline") == 0) {
68                         ++oneline;
69                 } else {
70                         bb_show_usage();
71                 }
72                 argc--; argv++;
73         }
74         _SL_ = oneline ? "\\" : "\n" ;
75         *argcp = argc;
76         *argvp = argv;
77 }