summaryrefslogtreecommitdiffstats
path: root/toolbox
diff options
context:
space:
mode:
authorChung-yih Wang <>2009-04-18 16:16:21 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2009-04-18 16:16:21 -0700
commitf309f77adcd7e4eda63b9bdeed9df31ab77770b4 (patch)
treef35295a327d463cde093d84aae95a372af29a5ac /toolbox
parentb33d3415b6c63f7b22e0863a2ac594feab9171cf (diff)
downloadsystem_core-f309f77adcd7e4eda63b9bdeed9df31ab77770b4.zip
system_core-f309f77adcd7e4eda63b9bdeed9df31ab77770b4.tar.gz
system_core-f309f77adcd7e4eda63b9bdeed9df31ab77770b4.tar.bz2
AI 146558: am: CL 146260 Add the net-based routing entries.
e.g. route add net 172.16.0.0 mask 255.240.0.0 gw 172.19.248.10 Original author: cywang Automated import of CL 146558
Diffstat (limited to 'toolbox')
-rw-r--r--toolbox/route.c45
1 files changed, 37 insertions, 8 deletions
diff --git a/toolbox/route.c b/toolbox/route.c
index adf5c69..86fc35b 100644
--- a/toolbox/route.c
+++ b/toolbox/route.c
@@ -2,6 +2,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include <stdarg.h>
#include <errno.h>
#include <string.h>
@@ -14,9 +15,14 @@
#include <arpa/inet.h>
#include <linux/route.h>
-static void die(const char *s)
+static void die(const char *fmt, ...)
{
- fprintf(stderr,"error: %s (%s)\n", s, strerror(errno));
+ va_list p;
+
+ va_start(p, fmt);
+ fprintf(stderr,"error(%s): ", strerror(errno));
+ fprintf(stderr, fmt, p);
+ va_end(p);
exit(-1);
}
@@ -36,9 +42,10 @@ static inline void init_sockaddr_in(struct sockaddr_in *sin, const char *addr)
} \
} while(0)
-/* current support two kinds of usage */
+/* current support the following routing entries */
/* route add default dev wlan0 */
/* route add default gw 192.168.20.1 dev wlan0 */
+/* route add net 192.168.1.1 netmask 255.255.255.0 gw 172.24.192.10 */
int route_main(int argc, char *argv[])
{
@@ -68,7 +75,7 @@ int route_main(int argc, char *argv[])
EXPECT_NEXT(argc, argv);
rt.rt_flags = RTF_UP | RTF_HOST;
rt.rt_dev = argv[0];
- if (ioctl(s, SIOCADDRT, &rt) < 0) die("SIOCADDRT");
+ if (ioctl(s, SIOCADDRT, &rt) < 0) die("SIOCADDRT\n");
}else if(!strcmp(argv[0], "gw")) {
EXPECT_NEXT(argc, argv);
rt.rt_flags = RTF_UP | RTF_GATEWAY;
@@ -76,22 +83,44 @@ int route_main(int argc, char *argv[])
if(isdigit(argv[0][0])){
init_sockaddr_in((struct sockaddr_in *)&(rt.rt_gateway), argv[0]);
}else{
- die("expecting an IP address for parameter \"gw\"");
+ die("expecting an IP address for parameter \"gw\"\n");
}
EXPECT_NEXT(argc, argv);
if(!strcmp(argv[0], "dev")) {
EXPECT_NEXT(argc, argv);
rt.rt_dev = argv[0];
if (ioctl(s, SIOCADDRT, &rt) < 0){
- die("SIOCADDRT");
+ die("SIOCADDRT\n");
}
}
}
- }
+ } else {
+ char keywords[3][5] = { "net", "mask", "gw" };
+ struct sockaddr_in *paddr[3] = { &rt.rt_dst, &rt.rt_genmask, &rt.rt_gateway };
+ int k = 0;
+
+ memset((char *) &rt, 0, sizeof(struct rtentry));
+ rt.rt_flags = RTF_UP | RTF_GATEWAY;
+ do {
+ if(!strcmp(argv[0], keywords[k])) {
+ EXPECT_NEXT(argc, argv);
+ if(isdigit(argv[0][0])) {
+ init_sockaddr_in(paddr[k], argv[0]);
+ } else {
+ die("expecting an IP/MASK address for parameter %s\n", keywords[k]);
+ }
+ if(k < 2) EXPECT_NEXT(argc, argv);
+ } else {
+ die("expecting keyword(s)\n");
+ }
+ } while(++k < 3);
+ if(ioctl(s, SIOCADDRT, &rt) < 0) {
+ die("SIOCADDRT\n");
+ }
+ }
}
ADVANCE(argc, argv);
}
return 0;
}
-