aboutsummaryrefslogtreecommitdiff
path: root/networking/route.c
diff options
context:
space:
mode:
authormjn3 <mjn3@69ca8d6d-28ef-0310-b511-8ec308f3f277>2003-03-19 09:13:01 +0000
committermjn3 <mjn3@69ca8d6d-28ef-0310-b511-8ec308f3f277>2003-03-19 09:13:01 +0000
commite901c15d890dbbdce4c086963cb1513653fc46b5 (patch)
treea318d0f03aa076c74b576ea45dc543a5669e8e91 /networking/route.c
parent40758c00616c3b2c85d83eb4afdeb04b1f65c9f1 (diff)
downloadbusybox-w32-e901c15d890dbbdce4c086963cb1513653fc46b5.tar.gz
busybox-w32-e901c15d890dbbdce4c086963cb1513653fc46b5.tar.bz2
busybox-w32-e901c15d890dbbdce4c086963cb1513653fc46b5.zip
Major coreutils update.
git-svn-id: svn://busybox.net/trunk/busybox@6751 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'networking/route.c')
-rw-r--r--networking/route.c76
1 files changed, 38 insertions, 38 deletions
diff --git a/networking/route.c b/networking/route.c
index b564c6dcd..083149a3d 100644
--- a/networking/route.c
+++ b/networking/route.c
@@ -15,7 +15,7 @@
15 * Foundation; either version 2 of the License, or (at 15 * Foundation; either version 2 of the License, or (at
16 * your option) any later version. 16 * your option) any later version.
17 * 17 *
18 * $Id: route.c,v 1.21 2002/12/16 22:04:18 sandman Exp $ 18 * $Id: route.c,v 1.22 2003/03/19 09:12:39 mjn3 Exp $
19 * 19 *
20 * displayroute() code added by Vladimir N. Oleynik <dzo@simtreas.ru> 20 * displayroute() code added by Vladimir N. Oleynik <dzo@simtreas.ru>
21 * adjustments by Larry Doolittle <LRDoolittle@lbl.gov> 21 * adjustments by Larry Doolittle <LRDoolittle@lbl.gov>
@@ -88,7 +88,7 @@ static int INET_setroute(int action, int options, char **args)
88 xflag = 0; 88 xflag = 0;
89 89
90 if (*args == NULL) 90 if (*args == NULL)
91 show_usage(); 91 bb_show_usage();
92 if (strcmp(*args, "-net") == 0) { 92 if (strcmp(*args, "-net") == 0) {
93 xflag = 1; 93 xflag = 1;
94 args++; 94 args++;
@@ -97,7 +97,7 @@ static int INET_setroute(int action, int options, char **args)
97 args++; 97 args++;
98 } 98 }
99 if (*args == NULL) 99 if (*args == NULL)
100 show_usage(); 100 bb_show_usage();
101 safe_strncpy(target, *args++, (sizeof target)); 101 safe_strncpy(target, *args++, (sizeof target));
102 102
103 /* Clean out the RTREQ structure. */ 103 /* Clean out the RTREQ structure. */
@@ -107,7 +107,7 @@ static int INET_setroute(int action, int options, char **args)
107 if ((isnet = 107 if ((isnet =
108 INET_resolve(target, (struct sockaddr_in *) &rt.rt_dst, 108 INET_resolve(target, (struct sockaddr_in *) &rt.rt_dst,
109 xflag != 1)) < 0) { 109 xflag != 1)) < 0) {
110 error_msg(_("can't resolve %s"), target); 110 bb_error_msg(_("can't resolve %s"), target);
111 return EXIT_FAILURE; /* XXX change to E_something */ 111 return EXIT_FAILURE; /* XXX change to E_something */
112 } 112 }
113 113
@@ -135,7 +135,7 @@ static int INET_setroute(int action, int options, char **args)
135 135
136 args++; 136 args++;
137 if (!*args || !isdigit(**args)) 137 if (!*args || !isdigit(**args))
138 show_usage(); 138 bb_show_usage();
139 metric = atoi(*args); 139 metric = atoi(*args);
140#if HAVE_NEW_ADDRT 140#if HAVE_NEW_ADDRT
141 rt.rt_metric = metric + 1; 141 rt.rt_metric = metric + 1;
@@ -151,12 +151,12 @@ static int INET_setroute(int action, int options, char **args)
151 151
152 args++; 152 args++;
153 if (!*args || mask_in_addr(rt)) 153 if (!*args || mask_in_addr(rt))
154 show_usage(); 154 bb_show_usage();
155 netmask = *args; 155 netmask = *args;
156 if ((isnet = 156 if ((isnet =
157 INET_resolve(netmask, (struct sockaddr_in *) &mask, 157 INET_resolve(netmask, (struct sockaddr_in *) &mask,
158 0)) < 0) { 158 0)) < 0) {
159 error_msg(_("can't resolve netmask %s"), netmask); 159 bb_error_msg(_("can't resolve netmask %s"), netmask);
160 return E_LOOKUP; 160 return E_LOOKUP;
161 } 161 }
162 rt.rt_genmask = full_mask(mask); 162 rt.rt_genmask = full_mask(mask);
@@ -167,18 +167,18 @@ static int INET_setroute(int action, int options, char **args)
167 if (strcmp(*args, "gw") == 0 || strcmp(*args, "gateway") == 0) { 167 if (strcmp(*args, "gw") == 0 || strcmp(*args, "gateway") == 0) {
168 args++; 168 args++;
169 if (!*args) 169 if (!*args)
170 show_usage(); 170 bb_show_usage();
171 if (rt.rt_flags & RTF_GATEWAY) 171 if (rt.rt_flags & RTF_GATEWAY)
172 show_usage(); 172 bb_show_usage();
173 safe_strncpy(gateway, *args, (sizeof gateway)); 173 safe_strncpy(gateway, *args, (sizeof gateway));
174 if ((isnet = 174 if ((isnet =
175 INET_resolve(gateway, (struct sockaddr_in *) &rt.rt_gateway, 175 INET_resolve(gateway, (struct sockaddr_in *) &rt.rt_gateway,
176 1)) < 0) { 176 1)) < 0) {
177 error_msg(_("can't resolve gw %s"), gateway); 177 bb_error_msg(_("can't resolve gw %s"), gateway);
178 return E_LOOKUP; 178 return E_LOOKUP;
179 } 179 }
180 if (isnet) { 180 if (isnet) {
181 error_msg(_("%s: cannot use a NETWORK as gateway!"), gateway); 181 bb_error_msg(_("%s: cannot use a NETWORK as gateway!"), gateway);
182 return E_OPTERR; 182 return E_OPTERR;
183 } 183 }
184 rt.rt_flags |= RTF_GATEWAY; 184 rt.rt_flags |= RTF_GATEWAY;
@@ -190,11 +190,11 @@ static int INET_setroute(int action, int options, char **args)
190 args++; 190 args++;
191 rt.rt_flags |= RTF_MSS; 191 rt.rt_flags |= RTF_MSS;
192 if (!*args) 192 if (!*args)
193 show_usage(); 193 bb_show_usage();
194 rt.rt_mss = atoi(*args); 194 rt.rt_mss = atoi(*args);
195 args++; 195 args++;
196 if (rt.rt_mss < 64 || rt.rt_mss > 32768) { 196 if (rt.rt_mss < 64 || rt.rt_mss > 32768) {
197 error_msg(_("Invalid MSS.")); 197 bb_error_msg(_("Invalid MSS."));
198 return E_OPTERR; 198 return E_OPTERR;
199 } 199 }
200 continue; 200 continue;
@@ -203,12 +203,12 @@ static int INET_setroute(int action, int options, char **args)
203 if (strcmp(*args, "window") == 0) { 203 if (strcmp(*args, "window") == 0) {
204 args++; 204 args++;
205 if (!*args) 205 if (!*args)
206 show_usage(); 206 bb_show_usage();
207 rt.rt_flags |= RTF_WINDOW; 207 rt.rt_flags |= RTF_WINDOW;
208 rt.rt_window = atoi(*args); 208 rt.rt_window = atoi(*args);
209 args++; 209 args++;
210 if (rt.rt_window < 128) { 210 if (rt.rt_window < 128) {
211 error_msg(_("Invalid window.")); 211 bb_error_msg(_("Invalid window."));
212 return E_OPTERR; 212 return E_OPTERR;
213 } 213 }
214 continue; 214 continue;
@@ -217,7 +217,7 @@ static int INET_setroute(int action, int options, char **args)
217 if (strcmp(*args, "irtt") == 0) { 217 if (strcmp(*args, "irtt") == 0) {
218 args++; 218 args++;
219 if (!*args) 219 if (!*args)
220 show_usage(); 220 bb_show_usage();
221 args++; 221 args++;
222#if HAVE_RTF_IRTT 222#if HAVE_RTF_IRTT
223 rt.rt_flags |= RTF_IRTT; 223 rt.rt_flags |= RTF_IRTT;
@@ -225,7 +225,7 @@ static int INET_setroute(int action, int options, char **args)
225 rt.rt_irtt *= (sysconf(_SC_CLK_TCK) / 100); /* FIXME */ 225 rt.rt_irtt *= (sysconf(_SC_CLK_TCK) / 100); /* FIXME */
226#if 0 /* FIXME: do we need to check anything of this? */ 226#if 0 /* FIXME: do we need to check anything of this? */
227 if (rt.rt_irtt < 1 || rt.rt_irtt > (120 * HZ)) { 227 if (rt.rt_irtt < 1 || rt.rt_irtt > (120 * HZ)) {
228 error_msg(_("Invalid initial rtt.")); 228 bb_error_msg(_("Invalid initial rtt."));
229 return E_OPTERR; 229 return E_OPTERR;
230 } 230 }
231#endif 231#endif
@@ -262,7 +262,7 @@ static int INET_setroute(int action, int options, char **args)
262 if (strcmp(*args, "device") == 0 || strcmp(*args, "dev") == 0) { 262 if (strcmp(*args, "device") == 0 || strcmp(*args, "dev") == 0) {
263 args++; 263 args++;
264 if (rt.rt_dev || *args == NULL) 264 if (rt.rt_dev || *args == NULL)
265 show_usage(); 265 bb_show_usage();
266 rt.rt_dev = *args++; 266 rt.rt_dev = *args++;
267 continue; 267 continue;
268 } 268 }
@@ -270,9 +270,9 @@ static int INET_setroute(int action, int options, char **args)
270 if (!rt.rt_dev) { 270 if (!rt.rt_dev) {
271 rt.rt_dev = *args++; 271 rt.rt_dev = *args++;
272 if (*args) 272 if (*args)
273 show_usage(); /* must be last to catch typos */ 273 bb_show_usage(); /* must be last to catch typos */
274 } else { 274 } else {
275 show_usage(); 275 bb_show_usage();
276 } 276 }
277 } 277 }
278 278
@@ -287,17 +287,17 @@ static int INET_setroute(int action, int options, char **args)
287 287
288 mask = ~ntohl(mask); 288 mask = ~ntohl(mask);
289 if ((rt.rt_flags & RTF_HOST) && mask != 0xffffffff) { 289 if ((rt.rt_flags & RTF_HOST) && mask != 0xffffffff) {
290 error_msg(_("netmask %.8x doesn't make sense with host route"), 290 bb_error_msg(_("netmask %.8x doesn't make sense with host route"),
291 (unsigned int) mask); 291 (unsigned int) mask);
292 return E_OPTERR; 292 return E_OPTERR;
293 } 293 }
294 if (mask & (mask + 1)) { 294 if (mask & (mask + 1)) {
295 error_msg(_("bogus netmask %s"), netmask); 295 bb_error_msg(_("bogus netmask %s"), netmask);
296 return E_OPTERR; 296 return E_OPTERR;
297 } 297 }
298 mask = ((struct sockaddr_in *) &rt.rt_dst)->sin_addr.s_addr; 298 mask = ((struct sockaddr_in *) &rt.rt_dst)->sin_addr.s_addr;
299 if (mask & ~mask_in_addr(rt)) { 299 if (mask & ~mask_in_addr(rt)) {
300 error_msg(_("netmask doesn't match route address")); 300 bb_error_msg(_("netmask doesn't match route address"));
301 return E_OPTERR; 301 return E_OPTERR;
302 } 302 }
303 } 303 }
@@ -343,7 +343,7 @@ static int INET6_setroute(int action, int options, char **args)
343 int skfd; 343 int skfd;
344 344
345 if (*args == NULL) 345 if (*args == NULL)
346 show_usage(); 346 bb_show_usage();
347 347
348 strcpy(target, *args++); 348 strcpy(target, *args++);
349 if (!strcmp(target, "default")) { 349 if (!strcmp(target, "default")) {
@@ -353,13 +353,13 @@ static int INET6_setroute(int action, int options, char **args)
353 if ((cp = strchr(target, '/'))) { 353 if ((cp = strchr(target, '/'))) {
354 prefix_len = atol(cp + 1); 354 prefix_len = atol(cp + 1);
355 if ((prefix_len < 0) || (prefix_len > 128)) 355 if ((prefix_len < 0) || (prefix_len > 128))
356 show_usage(); 356 bb_show_usage();
357 *cp = 0; 357 *cp = 0;
358 } else { 358 } else {
359 prefix_len = 128; 359 prefix_len = 128;
360 } 360 }
361 if (INET6_resolve(target, (struct sockaddr_in6 *) &sa6) < 0) { 361 if (INET6_resolve(target, (struct sockaddr_in6 *) &sa6) < 0) {
362 error_msg(_("can't resolve %s"), target); 362 bb_error_msg(_("can't resolve %s"), target);
363 return EXIT_FAILURE; /* XXX change to E_something */ 363 return EXIT_FAILURE; /* XXX change to E_something */
364 } 364 }
365 } 365 }
@@ -381,7 +381,7 @@ static int INET6_setroute(int action, int options, char **args)
381 381
382 args++; 382 args++;
383 if (!*args || !isdigit(**args)) 383 if (!*args || !isdigit(**args))
384 show_usage(); 384 bb_show_usage();
385 metric = atoi(*args); 385 metric = atoi(*args);
386 rt.rtmsg_metric = metric; 386 rt.rtmsg_metric = metric;
387 args++; 387 args++;
@@ -390,12 +390,12 @@ static int INET6_setroute(int action, int options, char **args)
390 if (!strcmp(*args, "gw") || !strcmp(*args, "gateway")) { 390 if (!strcmp(*args, "gw") || !strcmp(*args, "gateway")) {
391 args++; 391 args++;
392 if (!*args) 392 if (!*args)
393 show_usage(); 393 bb_show_usage();
394 if (rt.rtmsg_flags & RTF_GATEWAY) 394 if (rt.rtmsg_flags & RTF_GATEWAY)
395 show_usage(); 395 bb_show_usage();
396 strcpy(gateway, *args); 396 strcpy(gateway, *args);
397 if (INET6_resolve(gateway, (struct sockaddr_in6 *) &sa6) < 0) { 397 if (INET6_resolve(gateway, (struct sockaddr_in6 *) &sa6) < 0) {
398 error_msg(_("can't resolve gw %s"), gateway); 398 bb_error_msg(_("can't resolve gw %s"), gateway);
399 return (E_LOOKUP); 399 return (E_LOOKUP);
400 } 400 }
401 memcpy(&rt.rtmsg_gateway, sa6.sin6_addr.s6_addr, 401 memcpy(&rt.rtmsg_gateway, sa6.sin6_addr.s6_addr,
@@ -417,9 +417,9 @@ static int INET6_setroute(int action, int options, char **args)
417 if (!strcmp(*args, "device") || !strcmp(*args, "dev")) { 417 if (!strcmp(*args, "device") || !strcmp(*args, "dev")) {
418 args++; 418 args++;
419 if (!*args) 419 if (!*args)
420 show_usage(); 420 bb_show_usage();
421 } else if (args[1]) 421 } else if (args[1])
422 show_usage(); 422 bb_show_usage();
423 423
424 devname = *args; 424 devname = *args;
425 args++; 425 args++;
@@ -493,7 +493,7 @@ void displayroutes(int noresolve, int netstatfmt)
493 493
494 char sdest[16], sgw[16]; 494 char sdest[16], sgw[16];
495 495
496 FILE *fp = xfopen("/proc/net/route", "r"); 496 FILE *fp = bb_xfopen("/proc/net/route", "r");
497 497
498 if (noresolve) 498 if (noresolve)
499 noresolve = 0x0fff; 499 noresolve = 0x0fff;
@@ -515,7 +515,7 @@ void displayroutes(int noresolve, int netstatfmt)
515 if (sscanf(buff + ifl + 1, "%lx%lx%X%d%d%d%lx%d%d%d", 515 if (sscanf(buff + ifl + 1, "%lx%lx%X%d%d%d%lx%d%d%d",
516 &d, &g, &flgs, &ref, &use, &metric, &m, &mtu, &win, 516 &d, &g, &flgs, &ref, &use, &metric, &m, &mtu, &win,
517 &ir) != 10) { 517 &ir) != 10) {
518 error_msg_and_die("Unsuported kernel route format\n"); 518 bb_error_msg_and_die("Unsuported kernel route format\n");
519 } 519 }
520 ifl = 0; /* parse flags */ 520 ifl = 0; /* parse flags */
521 if (flgs & RTF_UP) { 521 if (flgs & RTF_UP) {
@@ -570,7 +570,7 @@ static void INET6_displayroutes(int noresolve)
570 570
571 char addr6p[8][5], saddr6p[8][5], naddr6p[8][5]; 571 char addr6p[8][5], saddr6p[8][5], naddr6p[8][5];
572 572
573 FILE *fp = xfopen("/proc/net/ipv6_route", "r"); 573 FILE *fp = bb_xfopen("/proc/net/ipv6_route", "r");
574 574
575 flags[0] = 'U'; 575 flags[0] = 'U';
576 576
@@ -598,7 +598,7 @@ static void INET6_displayroutes(int noresolve)
598 naddr6p[0], naddr6p[1], naddr6p[2], naddr6p[3], 598 naddr6p[0], naddr6p[1], naddr6p[2], naddr6p[3],
599 naddr6p[4], naddr6p[5], naddr6p[6], naddr6p[7], 599 naddr6p[4], naddr6p[5], naddr6p[6], naddr6p[7],
600 &metric, &use, &refcnt, &iflags, iface) != 31) { 600 &metric, &use, &refcnt, &iflags, iface) != 31) {
601 error_msg_and_die("Unsuported kernel route format\n"); 601 bb_error_msg_and_die("Unsuported kernel route format\n");
602 } 602 }
603 603
604 ifl = 1; /* parse flags */ 604 ifl = 1; /* parse flags */
@@ -673,7 +673,7 @@ int route_main(int argc, char **argv)
673 break; 673 break;
674#endif 674#endif
675 default: 675 default:
676 show_usage(); 676 bb_show_usage();
677 } 677 }
678 } 678 }
679 679
@@ -694,7 +694,7 @@ int route_main(int argc, char **argv)
694 else if (strcmp(argv[1], "flush") == 0) 694 else if (strcmp(argv[1], "flush") == 0)
695 what = RTACTION_FLUSH; 695 what = RTACTION_FLUSH;
696 else 696 else
697 show_usage(); 697 bb_show_usage();
698 } 698 }
699 699
700#ifdef CONFIG_FEATURE_IPV6 700#ifdef CONFIG_FEATURE_IPV6