blob: 9250484aab019e343a0eeefd37906263a527d6b1 [file] [log] [blame]
Glenn L McGrath9a2d2722002-11-10 01:33:55 +00001/*
2 * ip.c "ip" utility frontend.
3 *
Bernhard Reutner-Fischerab187822005-10-26 10:47:26 +00004 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
Glenn L McGrath9a2d2722002-11-10 01:33:55 +00005 *
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
Bernhard Reutner-Fischerab187822005-10-26 10:47:26 +000023#include "libiproute/utils.h"
24#include "libiproute/ip_common.h"
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000025
26#include "busybox.h"
27
Glenn L McGrathf112daa2002-12-01 23:04:06 +000028#if 0
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000029int preferred_family = AF_UNSPEC;
30int oneline = 0;
31char * _SL_ = NULL;
32
Glenn L McGrathf112daa2002-12-01 23:04:06 +000033void ip_parse_common_args(int *argcp, char ***argvp)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000034{
Glenn L McGrathf112daa2002-12-01 23:04:06 +000035 int argc = *argcp;
36 char **argv = *argvp;
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000037
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000038 while (argc > 1) {
39 char *opt = argv[1];
Glenn L McGrathf112daa2002-12-01 23:04:06 +000040
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000041 if (strcmp(opt,"--") == 0) {
42 argc--; argv++;
43 break;
44 }
Glenn L McGrathf112daa2002-12-01 23:04:06 +000045
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000046 if (opt[0] != '-')
47 break;
Glenn L McGrathf112daa2002-12-01 23:04:06 +000048
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000049 if (opt[1] == '-')
50 opt++;
Glenn L McGrathf112daa2002-12-01 23:04:06 +000051
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000052 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(argv[1], "invalid protocol 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 {
Manuel Novoa III cad53642003-03-19 09:13:01 +000072 bb_show_usage();
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000073 }
74 argc--; argv++;
75 }
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000076 _SL_ = oneline ? "\\" : "\n" ;
Glenn L McGrathf112daa2002-12-01 23:04:06 +000077}
78#endif
79
80int ip_main(int argc, char **argv)
81{
82 int ret = EXIT_FAILURE;
83
84 ip_parse_common_args(&argc, &argv);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000085
86 if (argc > 1) {
87#ifdef CONFIG_FEATURE_IP_ADDRESS
Glenn L McGrathf112daa2002-12-01 23:04:06 +000088 if (matches(argv[1], "address") == 0) {
89 ret = do_ipaddr(argc-2, argv+2);
90 }
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000091#endif
92#ifdef CONFIG_FEATURE_IP_ROUTE
Glenn L McGrath19efb3d2004-04-12 02:35:44 +000093 if (matches(argv[1], "route") == 0) {
Glenn L McGrathf112daa2002-12-01 23:04:06 +000094 ret = do_iproute(argc-2, argv+2);
95 }
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000096#endif
97#ifdef CONFIG_FEATURE_IP_LINK
Glenn L McGrath19efb3d2004-04-12 02:35:44 +000098 if (matches(argv[1], "link") == 0) {
Glenn L McGrathf112daa2002-12-01 23:04:06 +000099 ret = do_iplink(argc-2, argv+2);
100 }
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000101#endif
102#ifdef CONFIG_FEATURE_IP_TUNNEL
Glenn L McGrath19efb3d2004-04-12 02:35:44 +0000103 if (matches(argv[1], "tunnel") == 0 || strcmp(argv[1], "tunl") == 0) {
Glenn L McGrathf112daa2002-12-01 23:04:06 +0000104 ret = do_iptunnel(argc-2, argv+2);
105 }
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000106#endif
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000107 }
Glenn L McGrathf112daa2002-12-01 23:04:06 +0000108 if (ret) {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000109 bb_show_usage();
Glenn L McGrathf112daa2002-12-01 23:04:06 +0000110 }
111 return(EXIT_SUCCESS);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000112}