summaryrefslogtreecommitdiff
path: root/networking/route.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-06-19 11:12:46 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-06-19 11:12:46 +0000
commit6d9ea24611090f06b74e0e5b038b6c5b4bbe1063 (patch)
tree7fbefb532c3412b0264a9faf7d0ad3f42254b86e /networking/route.c
parent1b16bdaebf7d0e543e048dfec9f34f06e983336c (diff)
downloadbusybox-w32-6d9ea24611090f06b74e0e5b038b6c5b4bbe1063.tar.gz
busybox-w32-6d9ea24611090f06b74e0e5b038b6c5b4bbe1063.tar.bz2
busybox-w32-6d9ea24611090f06b74e0e5b038b6c5b4bbe1063.zip
networking/interface.c: huke remaining big statics; use malloc for INET[6]_rresolve
return value. Went thru callers and adjusted them - code got smaller too. function old new delta ip_port_str - 126 +126 INET6_rresolve 165 182 +17 static.cache 20 24 +4 route_main 2092 2091 -1 INET_sprint 61 59 -2 INET_nn 4 - -4 INET6_sprint 59 53 -6 udp_do_one 518 508 -10 tcp_do_one 433 423 -10 raw_do_one 494 484 -10 traceroute_main 4117 4105 -12 INET_rresolve 334 321 -13 bb_displayroutes 494 456 -38 snprint_ip_port 244 - -244 static.buff 264 16 -248 ------------------------------------------------------------------------------ (add/remove: 1/2 grow/shrink: 2/10 up/down: 147/-598) Total: -451 bytes size busybox_old busybox_unstripped text data bss dec hex filename 751073 3048 14688 768809 bbb29 busybox_old 750873 3048 14440 768361 bb969 busybox_unstripped
Diffstat (limited to 'networking/route.c')
-rw-r--r--networking/route.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/networking/route.c b/networking/route.c
index 881332b9f..b5490ddd8 100644
--- a/networking/route.c
+++ b/networking/route.c
@@ -478,7 +478,7 @@ static void set_flags(char *flagstr, int flags)
478/* also used in netstat */ 478/* also used in netstat */
479void bb_displayroutes(int noresolve, int netstatfmt) 479void bb_displayroutes(int noresolve, int netstatfmt)
480{ 480{
481 char devname[64], flags[16], sdest[16], sgw[16]; 481 char devname[64], flags[16], *sdest, *sgw;
482 unsigned long d, g, m; 482 unsigned long d, g, m;
483 int flgs, ref, use, metric, mtu, win, ir; 483 int flgs, ref, use, metric, mtu, win, ir;
484 struct sockaddr_in s_addr; 484 struct sockaddr_in s_addr;
@@ -520,15 +520,14 @@ void bb_displayroutes(int noresolve, int netstatfmt)
520 memset(&s_addr, 0, sizeof(struct sockaddr_in)); 520 memset(&s_addr, 0, sizeof(struct sockaddr_in));
521 s_addr.sin_family = AF_INET; 521 s_addr.sin_family = AF_INET;
522 s_addr.sin_addr.s_addr = d; 522 s_addr.sin_addr.s_addr = d;
523 INET_rresolve(sdest, sizeof(sdest), &s_addr, 523 sdest = INET_rresolve(&s_addr, (noresolve | 0x8000), m); /* 'default' instead of '*' */
524 (noresolve | 0x8000), m); /* Default instead of *. */
525
526 s_addr.sin_addr.s_addr = g; 524 s_addr.sin_addr.s_addr = g;
527 INET_rresolve(sgw, sizeof(sgw), &s_addr, 525 sgw = INET_rresolve(&s_addr, (noresolve | 0x4000), m); /* Host instead of net */
528 (noresolve | 0x4000), m); /* Host instead of net. */
529
530 mask.s_addr = m; 526 mask.s_addr = m;
531 printf("%-16s%-16s%-16s%-6s", sdest, sgw, inet_ntoa(mask), flags); 527 /* "%15.15s" truncates hostnames, do we really want that? */
528 printf("%-15.15s %-15.15s %-16s%-6s", sdest, sgw, inet_ntoa(mask), flags);
529 free(sdest);
530 free(sgw);
532 if (netstatfmt) { 531 if (netstatfmt) {
533 printf("%5d %-5d %6d %s\n", mtu, win, ir, devname); 532 printf("%5d %-5d %6d %s\n", mtu, win, ir, devname);
534 } else { 533 } else {
@@ -541,7 +540,7 @@ void bb_displayroutes(int noresolve, int netstatfmt)
541 540
542static void INET6_displayroutes(int noresolve) 541static void INET6_displayroutes(int noresolve)
543{ 542{
544 char addr6[128], naddr6[128]; 543 char addr6[128], *naddr6;
545 /* In addr6x, we store both 40-byte ':'-delimited ipv6 addresses. 544 /* In addr6x, we store both 40-byte ':'-delimited ipv6 addresses.
546 * We read the non-delimited strings into the tail of the buffer 545 * We read the non-delimited strings into the tail of the buffer
547 * using fscanf and then modify the buffer by shifting forward 546 * using fscanf and then modify the buffer by shifting forward
@@ -581,7 +580,7 @@ static void INET6_displayroutes(int noresolve)
581 580
582 do { 581 do {
583 if (!*p) { 582 if (!*p) {
584 if (i==40) { /* nul terminator for 1st address? */ 583 if (i == 40) { /* nul terminator for 1st address? */
585 addr6x[39] = 0; /* Fixup... need 0 instead of ':'. */ 584 addr6x[39] = 0; /* Fixup... need 0 instead of ':'. */
586 ++p; /* Skip and continue. */ 585 ++p; /* Skip and continue. */
587 continue; 586 continue;
@@ -606,18 +605,19 @@ static void INET6_displayroutes(int noresolve)
606 inet_pton(AF_INET6, addr6x + r, 605 inet_pton(AF_INET6, addr6x + r,
607 (struct sockaddr *) &snaddr6.sin6_addr); 606 (struct sockaddr *) &snaddr6.sin6_addr);
608 snaddr6.sin6_family = AF_INET6; 607 snaddr6.sin6_family = AF_INET6;
609 INET6_rresolve(naddr6, sizeof(naddr6), 608 naddr6 = INET6_rresolve((struct sockaddr_in6 *) &snaddr6,
610 (struct sockaddr_in6 *) &snaddr6,
611 0x0fff /* Apparently, upstream never resolves. */ 609 0x0fff /* Apparently, upstream never resolves. */
612 ); 610 );
613 611
614 if (!r) { /* 1st pass */ 612 if (!r) { /* 1st pass */
615 snprintf(addr6, sizeof(addr6), "%s/%d", naddr6, prefix_len); 613 snprintf(addr6, sizeof(addr6), "%s/%d", naddr6, prefix_len);
616 r += 40; 614 r += 40;
615 free(naddr6);
617 } else { /* 2nd pass */ 616 } else { /* 2nd pass */
618 /* Print the info. */ 617 /* Print the info. */
619 printf("%-43s %-39s %-5s %-6d %-2d %7d %-8s\n", 618 printf("%-43s %-39s %-5s %-6d %-2d %7d %-8s\n",
620 addr6, naddr6, flags, metric, refcnt, use, iface); 619 addr6, naddr6, flags, metric, refcnt, use, iface);
620 free(naddr6);
621 break; 621 break;
622 } 622 }
623 } while (1); 623 } while (1);