diff options
author | Eric Andersen <andersen@codepoet.org> | 2001-02-14 19:26:39 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2001-02-14 19:26:39 +0000 |
commit | 68be2ab914e1e20fe666bbd22a89a18714be2789 (patch) | |
tree | bbeb73189b0d4b1d0af7ce9391a0e53ff54f9745 | |
parent | 98e599ca063bbba13e0806d54f8caa9b0d10ba56 (diff) | |
download | busybox-w32-68be2ab914e1e20fe666bbd22a89a18714be2789.tar.gz busybox-w32-68be2ab914e1e20fe666bbd22a89a18714be2789.tar.bz2 busybox-w32-68be2ab914e1e20fe666bbd22a89a18714be2789.zip |
implemented displayroute() based on a patch from Vladimir N. Oleynik,
so now route behaves as expected w/o any arguments.
-rw-r--r-- | networking/route.c | 67 | ||||
-rw-r--r-- | route.c | 67 |
2 files changed, 124 insertions, 10 deletions
diff --git a/networking/route.c b/networking/route.c index 76b2306fd..83a0be2d2 100644 --- a/networking/route.c +++ b/networking/route.c | |||
@@ -15,8 +15,9 @@ | |||
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.1 2001/02/14 08:11:27 andersen Exp $ | 18 | * $Id: route.c,v 1.2 2001/02/14 19:26:39 andersen Exp $ |
19 | * | 19 | * |
20 | * displayroute() code added by Vladimir N. Oleynik <dzo@simtreas.ru> | ||
20 | */ | 21 | */ |
21 | 22 | ||
22 | #include "busybox.h" | 23 | #include "busybox.h" |
@@ -343,6 +344,63 @@ INET_setroute(int action, int options, char **args) | |||
343 | return (0); | 344 | return (0); |
344 | } | 345 | } |
345 | 346 | ||
347 | void displayroutes(void) | ||
348 | { | ||
349 | char buff[256]; | ||
350 | int nl = 0 ; | ||
351 | struct in_addr dest; | ||
352 | struct in_addr gw; | ||
353 | struct in_addr mask; | ||
354 | int flgs, ref, use, metric; | ||
355 | char flags[4]; | ||
356 | unsigned long int d,g,m; | ||
357 | |||
358 | char sdest[16], sgw[16]; | ||
359 | |||
360 | |||
361 | FILE *fp = fopen("/proc/net/route", "r"); | ||
362 | |||
363 | if(fp==0) { | ||
364 | perror_msg_and_die("/proc/net/route"); | ||
365 | } | ||
366 | while( fgets(buff, sizeof(buff), fp) != NULL ) { | ||
367 | if(nl) { | ||
368 | int ifl = 0; | ||
369 | while(buff[ifl]!=' ' && buff[ifl]!='\t' && buff[ifl]!='\0') | ||
370 | ifl++; | ||
371 | buff[ifl]=0; /* interface */ | ||
372 | if(sscanf(buff+ifl+1, "%lx%lx%d%d%d%d%lx", | ||
373 | &d, &g, &flgs, &ref, &use, &metric, &m)!=7) { | ||
374 | error_msg_and_die( "Unsuported kernel route format\n"); | ||
375 | } | ||
376 | dest.s_addr = d; | ||
377 | gw.s_addr = g; | ||
378 | mask.s_addr = m; | ||
379 | if(nl==1) | ||
380 | printf("Kernel IP routing table\n\ | ||
381 | Destination\tGateway\t\tGenmask\t\tFlags Metric Ref Use Iface\n"); | ||
382 | |||
383 | ifl = 0; /* parse flags */ | ||
384 | if(flgs&1) | ||
385 | flags[ifl++]='U'; | ||
386 | if(flgs&2) | ||
387 | flags[ifl++]='G'; | ||
388 | if(flgs&4) | ||
389 | flags[ifl++]='H'; | ||
390 | flags[ifl]=0; | ||
391 | strcpy(sdest, (dest.s_addr==0 ? "default" : | ||
392 | inet_ntoa(dest))); | ||
393 | strcpy(sgw, (gw.s_addr==0 ? "*" : | ||
394 | inet_ntoa(gw))); | ||
395 | printf("%-16s%-16s%-16s%-6s%-7d%-9d%-2d%s\n", | ||
396 | sdest, sgw, | ||
397 | inet_ntoa(mask), | ||
398 | flags, metric, ref, use, buff); | ||
399 | } | ||
400 | nl++; | ||
401 | } | ||
402 | } | ||
403 | |||
346 | int route_main(int argc, char **argv) | 404 | int route_main(int argc, char **argv) |
347 | { | 405 | { |
348 | int what = 0; | 406 | int what = 0; |
@@ -351,9 +409,8 @@ int route_main(int argc, char **argv) | |||
351 | argv++; | 409 | argv++; |
352 | 410 | ||
353 | if (*argv == NULL) { | 411 | if (*argv == NULL) { |
354 | //displayroutes(); | 412 | displayroutes(); |
355 | fprintf(stderr, "print routes is not implemented yet\n"); | 413 | exit(EXIT_SUCCESS); |
356 | usage(route_usage); | ||
357 | } else { | 414 | } else { |
358 | /* check verb */ | 415 | /* check verb */ |
359 | if (!strcmp(*argv, "add")) | 416 | if (!strcmp(*argv, "add")) |
@@ -368,5 +425,5 @@ int route_main(int argc, char **argv) | |||
368 | 425 | ||
369 | INET_setroute(what, 0, ++argv); | 426 | INET_setroute(what, 0, ++argv); |
370 | 427 | ||
371 | exit(0); | 428 | exit(EXIT_SUCCESS); |
372 | } | 429 | } |
@@ -15,8 +15,9 @@ | |||
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.1 2001/02/14 08:11:27 andersen Exp $ | 18 | * $Id: route.c,v 1.2 2001/02/14 19:26:39 andersen Exp $ |
19 | * | 19 | * |
20 | * displayroute() code added by Vladimir N. Oleynik <dzo@simtreas.ru> | ||
20 | */ | 21 | */ |
21 | 22 | ||
22 | #include "busybox.h" | 23 | #include "busybox.h" |
@@ -343,6 +344,63 @@ INET_setroute(int action, int options, char **args) | |||
343 | return (0); | 344 | return (0); |
344 | } | 345 | } |
345 | 346 | ||
347 | void displayroutes(void) | ||
348 | { | ||
349 | char buff[256]; | ||
350 | int nl = 0 ; | ||
351 | struct in_addr dest; | ||
352 | struct in_addr gw; | ||
353 | struct in_addr mask; | ||
354 | int flgs, ref, use, metric; | ||
355 | char flags[4]; | ||
356 | unsigned long int d,g,m; | ||
357 | |||
358 | char sdest[16], sgw[16]; | ||
359 | |||
360 | |||
361 | FILE *fp = fopen("/proc/net/route", "r"); | ||
362 | |||
363 | if(fp==0) { | ||
364 | perror_msg_and_die("/proc/net/route"); | ||
365 | } | ||
366 | while( fgets(buff, sizeof(buff), fp) != NULL ) { | ||
367 | if(nl) { | ||
368 | int ifl = 0; | ||
369 | while(buff[ifl]!=' ' && buff[ifl]!='\t' && buff[ifl]!='\0') | ||
370 | ifl++; | ||
371 | buff[ifl]=0; /* interface */ | ||
372 | if(sscanf(buff+ifl+1, "%lx%lx%d%d%d%d%lx", | ||
373 | &d, &g, &flgs, &ref, &use, &metric, &m)!=7) { | ||
374 | error_msg_and_die( "Unsuported kernel route format\n"); | ||
375 | } | ||
376 | dest.s_addr = d; | ||
377 | gw.s_addr = g; | ||
378 | mask.s_addr = m; | ||
379 | if(nl==1) | ||
380 | printf("Kernel IP routing table\n\ | ||
381 | Destination\tGateway\t\tGenmask\t\tFlags Metric Ref Use Iface\n"); | ||
382 | |||
383 | ifl = 0; /* parse flags */ | ||
384 | if(flgs&1) | ||
385 | flags[ifl++]='U'; | ||
386 | if(flgs&2) | ||
387 | flags[ifl++]='G'; | ||
388 | if(flgs&4) | ||
389 | flags[ifl++]='H'; | ||
390 | flags[ifl]=0; | ||
391 | strcpy(sdest, (dest.s_addr==0 ? "default" : | ||
392 | inet_ntoa(dest))); | ||
393 | strcpy(sgw, (gw.s_addr==0 ? "*" : | ||
394 | inet_ntoa(gw))); | ||
395 | printf("%-16s%-16s%-16s%-6s%-7d%-9d%-2d%s\n", | ||
396 | sdest, sgw, | ||
397 | inet_ntoa(mask), | ||
398 | flags, metric, ref, use, buff); | ||
399 | } | ||
400 | nl++; | ||
401 | } | ||
402 | } | ||
403 | |||
346 | int route_main(int argc, char **argv) | 404 | int route_main(int argc, char **argv) |
347 | { | 405 | { |
348 | int what = 0; | 406 | int what = 0; |
@@ -351,9 +409,8 @@ int route_main(int argc, char **argv) | |||
351 | argv++; | 409 | argv++; |
352 | 410 | ||
353 | if (*argv == NULL) { | 411 | if (*argv == NULL) { |
354 | //displayroutes(); | 412 | displayroutes(); |
355 | fprintf(stderr, "print routes is not implemented yet\n"); | 413 | exit(EXIT_SUCCESS); |
356 | usage(route_usage); | ||
357 | } else { | 414 | } else { |
358 | /* check verb */ | 415 | /* check verb */ |
359 | if (!strcmp(*argv, "add")) | 416 | if (!strcmp(*argv, "add")) |
@@ -368,5 +425,5 @@ int route_main(int argc, char **argv) | |||
368 | 425 | ||
369 | INET_setroute(what, 0, ++argv); | 426 | INET_setroute(what, 0, ++argv); |
370 | 427 | ||
371 | exit(0); | 428 | exit(EXIT_SUCCESS); |
372 | } | 429 | } |