diff options
Diffstat (limited to 'networking/route.c')
-rw-r--r-- | networking/route.c | 70 |
1 files changed, 48 insertions, 22 deletions
diff --git a/networking/route.c b/networking/route.c index 43180296d..af630c68b 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.14 2001/11/10 11:22:43 andersen Exp $ | 18 | * $Id: route.c,v 1.15 2002/05/14 23:03:23 sandman 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> |
@@ -342,14 +342,14 @@ INET_setroute(int action, int options, char **args) | |||
342 | #define RTF_REJECT 0x0200 /* Reject route */ | 342 | #define RTF_REJECT 0x0200 /* Reject route */ |
343 | #endif | 343 | #endif |
344 | 344 | ||
345 | static void displayroutes(int noresolve) | 345 | void displayroutes(int noresolve, int netstatfmt) |
346 | { | 346 | { |
347 | char buff[256]; | 347 | char buff[256]; |
348 | int nl = 0 ; | 348 | int nl = 0 ; |
349 | struct in_addr dest; | 349 | struct in_addr dest; |
350 | struct in_addr gw; | 350 | struct in_addr gw; |
351 | struct in_addr mask; | 351 | struct in_addr mask; |
352 | int flgs, ref, use, metric; | 352 | int flgs, ref, use, metric, mtu, win, ir; |
353 | char flags[64]; | 353 | char flags[64]; |
354 | unsigned long int d,g,m; | 354 | unsigned long int d,g,m; |
355 | 355 | ||
@@ -369,14 +369,17 @@ static void displayroutes(int noresolve) | |||
369 | while(buff[ifl]!=' ' && buff[ifl]!='\t' && buff[ifl]!='\0') | 369 | while(buff[ifl]!=' ' && buff[ifl]!='\t' && buff[ifl]!='\0') |
370 | ifl++; | 370 | ifl++; |
371 | buff[ifl]=0; /* interface */ | 371 | buff[ifl]=0; /* interface */ |
372 | if(sscanf(buff+ifl+1, "%lx%lx%X%d%d%d%lx", | 372 | if(sscanf(buff+ifl+1, "%lx%lx%X%d%d%d%lx%d%d%d", |
373 | &d, &g, &flgs, &ref, &use, &metric, &m)!=7) { | 373 | &d, &g, &flgs, &ref, &use, &metric, &m, &mtu, &win, &ir )!=10) { |
374 | error_msg_and_die( "Unsuported kernel route format\n"); | 374 | error_msg_and_die( "Unsuported kernel route format\n"); |
375 | } | 375 | } |
376 | if(nl==1) | 376 | if(nl==1) { |
377 | printf("Kernel IP routing table\n" | 377 | printf("Kernel IP routing table\n"); |
378 | "Destination Gateway Genmask Flags Metric Ref Use Iface\n"); | 378 | if ( netstatfmt ) |
379 | 379 | printf("Destination Gateway Genmask Flags MSS Window irtt Iface\n"); | |
380 | else | ||
381 | printf("Destination Gateway Genmask Flags Metric Ref Use Iface\n"); | ||
382 | } | ||
380 | ifl = 0; /* parse flags */ | 383 | ifl = 0; /* parse flags */ |
381 | if(flgs&RTF_UP) { | 384 | if(flgs&RTF_UP) { |
382 | if(flgs&RTF_REJECT) | 385 | if(flgs&RTF_REJECT) |
@@ -405,10 +408,18 @@ static void displayroutes(int noresolve) | |||
405 | numeric = noresolve | 0x4000; /* host instead of net */ | 408 | numeric = noresolve | 0x4000; /* host instead of net */ |
406 | s_addr.sin_addr = gw; | 409 | s_addr.sin_addr = gw; |
407 | INET_rresolve(sgw, sizeof(sgw), &s_addr, numeric, m); | 410 | INET_rresolve(sgw, sizeof(sgw), &s_addr, numeric, m); |
408 | printf("%-16s%-16s%-16s%-6s%-6d %-2d %7d %s\n", | 411 | if ( netstatfmt ) { |
409 | sdest, sgw, | 412 | printf("%-16s%-16s%-16s%-6s%5d %-5d %6d %s\n", |
410 | inet_ntoa(mask), | 413 | sdest, sgw, |
411 | flags, metric, ref, use, buff); | 414 | inet_ntoa(mask), |
415 | flags, mtu, win, ir, buff); | ||
416 | } | ||
417 | else { | ||
418 | printf("%-16s%-16s%-16s%-6s%-6d %-2d %7d %s\n", | ||
419 | sdest, sgw, | ||
420 | inet_ntoa(mask), | ||
421 | flags, metric, ref, use, buff); | ||
422 | } | ||
412 | } | 423 | } |
413 | } | 424 | } |
414 | nl++; | 425 | nl++; |
@@ -417,25 +428,40 @@ static void displayroutes(int noresolve) | |||
417 | 428 | ||
418 | int route_main(int argc, char **argv) | 429 | int route_main(int argc, char **argv) |
419 | { | 430 | { |
431 | int opt; | ||
420 | int what = 0; | 432 | int what = 0; |
421 | 433 | ||
422 | argc--; | 434 | if ( !argv [1] || ( argv [1][0] == '-' )) { |
423 | argv++; | 435 | /* check options */ |
424 | 436 | int noresolve = 0; | |
425 | if (*argv == NULL || (*(argv+1)==NULL && strcmp(*argv, "-n")==0)) { | 437 | int extended = 0; |
426 | displayroutes(*argv != NULL); | 438 | |
439 | while ((opt = getopt(argc, argv, "ne")) > 0) { | ||
440 | switch (opt) { | ||
441 | case 'n': | ||
442 | noresolve = 1; | ||
443 | break; | ||
444 | case 'e': | ||
445 | extended = 1; | ||
446 | break; | ||
447 | default: | ||
448 | show_usage ( ); | ||
449 | } | ||
450 | } | ||
451 | |||
452 | displayroutes ( noresolve, extended ); | ||
427 | return EXIT_SUCCESS; | 453 | return EXIT_SUCCESS; |
428 | } else { | 454 | } else { |
429 | /* check verb */ | 455 | /* check verb */ |
430 | if (strcmp(*argv, "add")==0) | 456 | if (strcmp( argv [1], "add")==0) |
431 | what = RTACTION_ADD; | 457 | what = RTACTION_ADD; |
432 | else if (strcmp(*argv, "del")==0 || strcmp(*argv, "delete")==0) | 458 | else if (strcmp( argv [1], "del")==0 || strcmp( argv [1], "delete")==0) |
433 | what = RTACTION_DEL; | 459 | what = RTACTION_DEL; |
434 | else if (strcmp(*argv, "flush")==0) | 460 | else if (strcmp( argv [1], "flush")==0) |
435 | what = RTACTION_FLUSH; | 461 | what = RTACTION_FLUSH; |
436 | else | 462 | else |
437 | show_usage(); | 463 | show_usage(); |
438 | } | 464 | } |
439 | 465 | ||
440 | return INET_setroute(what, 0, ++argv); | 466 | return INET_setroute(what, 0, argv+2 ); |
441 | } | 467 | } |