1 | /*
|
---|
2 | * ip.c "ip" utility frontend.
|
---|
3 | *
|
---|
4 | * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
|
---|
5 | *
|
---|
6 | * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
|
---|
7 | *
|
---|
8 | *
|
---|
9 | * Changes:
|
---|
10 | *
|
---|
11 | * Rani Assaf <rani@magic.metawire.com> 980929: resolve addresses
|
---|
12 | */
|
---|
13 |
|
---|
14 | #include <stdio.h>
|
---|
15 | #include <stdlib.h>
|
---|
16 | #include <unistd.h>
|
---|
17 | #include <syslog.h>
|
---|
18 | #include <fcntl.h>
|
---|
19 | #include <sys/socket.h>
|
---|
20 | #include <netinet/in.h>
|
---|
21 | #include <string.h>
|
---|
22 |
|
---|
23 | #include "libiproute/utils.h"
|
---|
24 | #include "libiproute/ip_common.h"
|
---|
25 |
|
---|
26 | #include "busybox.h"
|
---|
27 |
|
---|
28 | #if 0
|
---|
29 | int preferred_family = AF_UNSPEC;
|
---|
30 | int oneline = 0;
|
---|
31 | char * _SL_ = NULL;
|
---|
32 |
|
---|
33 | void ip_parse_common_args(int *argcp, char ***argvp)
|
---|
34 | {
|
---|
35 | int argc = *argcp;
|
---|
36 | char **argv = *argvp;
|
---|
37 |
|
---|
38 | while (argc > 1) {
|
---|
39 | char *opt = argv[1];
|
---|
40 |
|
---|
41 | if (strcmp(opt,"--") == 0) {
|
---|
42 | argc--; argv++;
|
---|
43 | break;
|
---|
44 | }
|
---|
45 |
|
---|
46 | if (opt[0] != '-')
|
---|
47 | break;
|
---|
48 |
|
---|
49 | if (opt[1] == '-')
|
---|
50 | opt++;
|
---|
51 |
|
---|
52 | if (matches(opt, "-family") == 0) {
|
---|
53 | argc--;
|
---|
54 | argv++;
|
---|
55 | if (strcmp(argv[1], "inet") == 0)
|
---|
56 | preferred_family = AF_INET;
|
---|
57 | else if (strcmp(argv[1], "inet6") == 0)
|
---|
58 | preferred_family = AF_INET6;
|
---|
59 | else if (strcmp(argv[1], "link") == 0)
|
---|
60 | preferred_family = AF_PACKET;
|
---|
61 | else
|
---|
62 | invarg(bb_msg_invalid_arg, argv[1], "-family");
|
---|
63 | } else if (strcmp(opt, "-4") == 0) {
|
---|
64 | preferred_family = AF_INET;
|
---|
65 | } else if (strcmp(opt, "-6") == 0) {
|
---|
66 | preferred_family = AF_INET6;
|
---|
67 | } else if (strcmp(opt, "-0") == 0) {
|
---|
68 | preferred_family = AF_PACKET;
|
---|
69 | } else if (matches(opt, "-oneline") == 0) {
|
---|
70 | ++oneline;
|
---|
71 | } else {
|
---|
72 | bb_show_usage();
|
---|
73 | }
|
---|
74 | argc--; argv++;
|
---|
75 | }
|
---|
76 | _SL_ = oneline ? "\\" : "\n" ;
|
---|
77 | }
|
---|
78 | #endif
|
---|
79 |
|
---|
80 | int ip_main(int argc, char **argv)
|
---|
81 | {
|
---|
82 | int ret = EXIT_FAILURE;
|
---|
83 |
|
---|
84 | ip_parse_common_args(&argc, &argv);
|
---|
85 |
|
---|
86 | if (argc > 1) {
|
---|
87 | #ifdef CONFIG_FEATURE_IP_ADDRESS
|
---|
88 | if (matches(argv[1], "address") == 0) {
|
---|
89 | ret = do_ipaddr(argc-2, argv+2);
|
---|
90 | }
|
---|
91 | #endif
|
---|
92 | #ifdef CONFIG_FEATURE_IP_ROUTE
|
---|
93 | if (matches(argv[1], "route") == 0) {
|
---|
94 | ret = do_iproute(argc-2, argv+2);
|
---|
95 | }
|
---|
96 | #endif
|
---|
97 | #ifdef CONFIG_FEATURE_IP_LINK
|
---|
98 | if (matches(argv[1], "link") == 0) {
|
---|
99 | ret = do_iplink(argc-2, argv+2);
|
---|
100 | }
|
---|
101 | #endif
|
---|
102 | #ifdef CONFIG_FEATURE_IP_TUNNEL
|
---|
103 | if (matches(argv[1], "tunnel") == 0 || strcmp(argv[1], "tunl") == 0) {
|
---|
104 | ret = do_iptunnel(argc-2, argv+2);
|
---|
105 | }
|
---|
106 | #endif
|
---|
107 | }
|
---|
108 | if (ret) {
|
---|
109 | bb_show_usage();
|
---|
110 | }
|
---|
111 | return(EXIT_SUCCESS);
|
---|
112 | }
|
---|