blob: cfdbf8b9690a45bd561dde6aa081507d06cf5aeb [file] [log] [blame]
Glenn L McGrath9a2d2722002-11-10 01:33:55 +00001/*
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 <stdio.h>
18#include <stdlib.h>
19#include <unistd.h>
20#include <syslog.h>
21#include <fcntl.h>
22#include <sys/socket.h>
23#include <netinet/in.h>
24#include <string.h>
25
26#include "./libiproute/utils.h"
27#include "./libiproute/ip_common.h"
28
29#include "busybox.h"
30
Glenn L McGrathf112daa2002-12-01 23:04:06 +000031#if 0
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000032int preferred_family = AF_UNSPEC;
33int oneline = 0;
34char * _SL_ = NULL;
35
Glenn L McGrathf112daa2002-12-01 23:04:06 +000036void ip_parse_common_args(int *argcp, char ***argvp)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000037{
Glenn L McGrathf112daa2002-12-01 23:04:06 +000038 int argc = *argcp;
39 char **argv = *argvp;
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000040
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000041 while (argc > 1) {
42 char *opt = argv[1];
Glenn L McGrathf112daa2002-12-01 23:04:06 +000043
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000044 if (strcmp(opt,"--") == 0) {
45 argc--; argv++;
46 break;
47 }
Glenn L McGrathf112daa2002-12-01 23:04:06 +000048
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000049 if (opt[0] != '-')
50 break;
Glenn L McGrathf112daa2002-12-01 23:04:06 +000051
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000052 if (opt[1] == '-')
53 opt++;
Glenn L McGrathf112daa2002-12-01 23:04:06 +000054
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000055 if (matches(opt, "-family") == 0) {
56 argc--;
57 argv++;
58 if (strcmp(argv[1], "inet") == 0)
59 preferred_family = AF_INET;
60 else if (strcmp(argv[1], "inet6") == 0)
61 preferred_family = AF_INET6;
62 else if (strcmp(argv[1], "link") == 0)
63 preferred_family = AF_PACKET;
64 else
65 invarg(argv[1], "invalid protocol family");
66 } else if (strcmp(opt, "-4") == 0) {
67 preferred_family = AF_INET;
68 } else if (strcmp(opt, "-6") == 0) {
69 preferred_family = AF_INET6;
70 } else if (strcmp(opt, "-0") == 0) {
71 preferred_family = AF_PACKET;
72 } else if (matches(opt, "-oneline") == 0) {
73 ++oneline;
74 } else {
Manuel Novoa III cad53642003-03-19 09:13:01 +000075 bb_show_usage();
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000076 }
77 argc--; argv++;
78 }
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000079 _SL_ = oneline ? "\\" : "\n" ;
Glenn L McGrathf112daa2002-12-01 23:04:06 +000080}
81#endif
82
83int ip_main(int argc, char **argv)
84{
85 int ret = EXIT_FAILURE;
86
87 ip_parse_common_args(&argc, &argv);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000088
89 if (argc > 1) {
90#ifdef CONFIG_FEATURE_IP_ADDRESS
Glenn L McGrathf112daa2002-12-01 23:04:06 +000091 if (matches(argv[1], "address") == 0) {
92 ret = do_ipaddr(argc-2, argv+2);
93 }
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000094#endif
95#ifdef CONFIG_FEATURE_IP_ROUTE
Glenn L McGrath19efb3d2004-04-12 02:35:44 +000096 if (matches(argv[1], "route") == 0) {
Glenn L McGrathf112daa2002-12-01 23:04:06 +000097 ret = do_iproute(argc-2, argv+2);
98 }
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000099#endif
100#ifdef CONFIG_FEATURE_IP_LINK
Glenn L McGrath19efb3d2004-04-12 02:35:44 +0000101 if (matches(argv[1], "link") == 0) {
Glenn L McGrathf112daa2002-12-01 23:04:06 +0000102 ret = do_iplink(argc-2, argv+2);
103 }
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000104#endif
105#ifdef CONFIG_FEATURE_IP_TUNNEL
Glenn L McGrath19efb3d2004-04-12 02:35:44 +0000106 if (matches(argv[1], "tunnel") == 0 || strcmp(argv[1], "tunl") == 0) {
Glenn L McGrathf112daa2002-12-01 23:04:06 +0000107 ret = do_iptunnel(argc-2, argv+2);
108 }
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000109#endif
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000110 }
Glenn L McGrathf112daa2002-12-01 23:04:06 +0000111 if (ret) {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000112 bb_show_usage();
Glenn L McGrathf112daa2002-12-01 23:04:06 +0000113 }
114 return(EXIT_SUCCESS);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000115}