aboutsummaryrefslogtreecommitdiff
path: root/networking/interface.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-06-19 11:10:02 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-06-19 11:10:02 +0000
commit1b16bdaebf7d0e543e048dfec9f34f06e983336c (patch)
treef2a121c80e2b34822a6bc5e44c5e17c42423d44b /networking/interface.c
parent91e149a3736ddc357950252c02d758515074447f (diff)
downloadbusybox-w32-1b16bdaebf7d0e543e048dfec9f34f06e983336c.tar.gz
busybox-w32-1b16bdaebf7d0e543e048dfec9f34f06e983336c.tar.bz2
busybox-w32-1b16bdaebf7d0e543e048dfec9f34f06e983336c.zip
networking/interface.c: reduce bss usage
function old new delta .rodata 158918 158950 +32 display_interfaces 133 153 +20 UNSPEC_print 56 68 +12 pr_ether 59 65 +6 static.proc_read 4 1 -3 interface_opt_a 4 1 -3 in_ether 139 136 -3 ifconfig_main 1296 1293 -3 if_readlist_proc 686 680 -6 ife_print 1350 1338 -12 do_if_print 46 - -46 static.buff 369 264 -105 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 4/7 up/down: 70/-181) Total: -111 bytes # size busybox_old busybox_unstripped text data bss dec hex filename 751073 3080 14800 768953 bbbb9 busybox_old 751073 3048 14688 768809 bbb29 busybox_unstripped
Diffstat (limited to 'networking/interface.c')
-rw-r--r--networking/interface.c99
1 files changed, 54 insertions, 45 deletions
diff --git a/networking/interface.c b/networking/interface.c
index 51e3d7487..f8721f409 100644
--- a/networking/interface.c
+++ b/networking/interface.c
@@ -88,11 +88,9 @@ static const char *INET_sprint(struct sockaddr *sap, int numeric)
88 88
89 if (sap->sa_family == 0xFFFF || sap->sa_family == 0) 89 if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
90 return "[NONE SET]"; 90 return "[NONE SET]";
91
92 if (INET_rresolve(buff, sizeof(buff), (struct sockaddr_in *) sap, 91 if (INET_rresolve(buff, sizeof(buff), (struct sockaddr_in *) sap,
93 numeric, 0xffffff00) != 0) 92 numeric, 0xffffff00) != 0)
94 return NULL; 93 return NULL;
95
96 return buff; 94 return buff;
97} 95}
98 96
@@ -221,10 +219,13 @@ static const struct aftype inet6_aftype = {
221/* Display an UNSPEC address. */ 219/* Display an UNSPEC address. */
222static char *UNSPEC_print(unsigned char *ptr) 220static char *UNSPEC_print(unsigned char *ptr)
223{ 221{
224 static char buff[sizeof(struct sockaddr) * 3 + 1]; 222 static char *buff;
223
225 char *pos; 224 char *pos;
226 unsigned int i; 225 unsigned int i;
227 226
227 if (!buff);
228 buff = xmalloc(sizeof(struct sockaddr) * 3 + 1);
228 pos = buff; 229 pos = buff;
229 for (i = 0; i < sizeof(struct sockaddr); i++) { 230 for (i = 0; i < sizeof(struct sockaddr); i++) {
230 /* careful -- not every libc's sprintf returns # bytes written */ 231 /* careful -- not every libc's sprintf returns # bytes written */
@@ -341,7 +342,7 @@ struct interface {
341}; 342};
342 343
343 344
344int interface_opt_a; /* show all interfaces */ 345smallint interface_opt_a; /* show all interfaces */
345 346
346static struct interface *int_list, *int_last; 347static struct interface *int_list, *int_last;
347 348
@@ -522,7 +523,7 @@ static int if_readconf(void)
522 ifc.ifc_buf = xrealloc(ifc.ifc_buf, ifc.ifc_len); 523 ifc.ifc_buf = xrealloc(ifc.ifc_buf, ifc.ifc_len);
523 524
524 if (ioctl(skfd, SIOCGIFCONF, &ifc) < 0) { 525 if (ioctl(skfd, SIOCGIFCONF, &ifc) < 0) {
525 perror("SIOCGIFCONF"); 526 bb_perror_msg("SIOCGIFCONF");
526 goto out; 527 goto out;
527 } 528 }
528 if (ifc.ifc_len == sizeof(struct ifreq) * numreqs) { 529 if (ifc.ifc_len == sizeof(struct ifreq) * numreqs) {
@@ -548,7 +549,8 @@ static int if_readconf(void)
548 549
549static int if_readlist_proc(char *target) 550static int if_readlist_proc(char *target)
550{ 551{
551 static int proc_read; 552 static smallint proc_read;
553
552 FILE *fh; 554 FILE *fh;
553 char buf[512]; 555 char buf[512];
554 struct interface *ife; 556 struct interface *ife;
@@ -581,7 +583,7 @@ static int if_readlist_proc(char *target)
581 break; 583 break;
582 } 584 }
583 if (ferror(fh)) { 585 if (ferror(fh)) {
584 perror(_PATH_PROCNET_DEV); 586 bb_perror_msg(_PATH_PROCNET_DEV);
585 err = -1; 587 err = -1;
586 proc_read = 0; 588 proc_read = 0;
587 } 589 }
@@ -598,22 +600,6 @@ static int if_readlist(void)
598 return err; 600 return err;
599} 601}
600 602
601static int for_all_interfaces(int (*doit) (struct interface *, void *),
602 void *cookie)
603{
604 struct interface *ife;
605
606 if (!int_list && (if_readlist() < 0))
607 return -1;
608 for (ife = int_list; ife; ife = ife->next) {
609 int err = doit(ife, cookie);
610
611 if (err)
612 return err;
613 }
614 return 0;
615}
616
617/* Fetch the interface configuration from the kernel. */ 603/* Fetch the interface configuration from the kernel. */
618static int if_fetch(struct interface *ife) 604static int if_fetch(struct interface *ife)
619{ 605{
@@ -732,9 +718,10 @@ static const struct hwtype loop_hwtype = {
732/* Display an Ethernet address in readable format. */ 718/* Display an Ethernet address in readable format. */
733static char *pr_ether(unsigned char *ptr) 719static char *pr_ether(unsigned char *ptr)
734{ 720{
735 static char buff[64]; 721 static char *buff;
736 722
737 snprintf(buff, sizeof(buff), "%02X:%02X:%02X:%02X:%02X:%02X", 723 free(buff);
724 buff = xasprintf("%02X:%02X:%02X:%02X:%02X:%02X",
738 (ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377), 725 (ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377),
739 (ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377) 726 (ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377)
740 ); 727 );
@@ -743,7 +730,7 @@ static char *pr_ether(unsigned char *ptr)
743 730
744static int in_ether(const char *bufp, struct sockaddr *sap); 731static int in_ether(const char *bufp, struct sockaddr *sap);
745 732
746static struct hwtype ether_hwtype = { 733static const struct hwtype ether_hwtype = {
747 .name = "ether", 734 .name = "ether",
748 .title = "Ethernet", 735 .title = "Ethernet",
749 .type = ARPHRD_ETHER, 736 .type = ARPHRD_ETHER,
@@ -1040,29 +1027,28 @@ static void ife_print(struct interface *ptr)
1040 (struct sockaddr *) &sap.sin6_addr); 1027 (struct sockaddr *) &sap.sin6_addr);
1041 sap.sin6_family = AF_INET6; 1028 sap.sin6_family = AF_INET6;
1042 printf(" inet6 addr: %s/%d", 1029 printf(" inet6 addr: %s/%d",
1043 inet6_aftype.sprint((struct sockaddr *) &sap, 1), 1030 INET6_sprint((struct sockaddr *) &sap, 1),
1044 plen); 1031 plen);
1045 printf(" Scope:"); 1032 printf(" Scope:");
1046 switch (scope & IPV6_ADDR_SCOPE_MASK) { 1033 switch (scope & IPV6_ADDR_SCOPE_MASK) {
1047 case 0: 1034 case 0:
1048 printf("Global"); 1035 puts("Global");
1049 break; 1036 break;
1050 case IPV6_ADDR_LINKLOCAL: 1037 case IPV6_ADDR_LINKLOCAL:
1051 printf("Link"); 1038 puts("Link");
1052 break; 1039 break;
1053 case IPV6_ADDR_SITELOCAL: 1040 case IPV6_ADDR_SITELOCAL:
1054 printf("Site"); 1041 puts("Site");
1055 break; 1042 break;
1056 case IPV6_ADDR_COMPATv4: 1043 case IPV6_ADDR_COMPATv4:
1057 printf("Compat"); 1044 puts("Compat");
1058 break; 1045 break;
1059 case IPV6_ADDR_LOOPBACK: 1046 case IPV6_ADDR_LOOPBACK:
1060 printf("Host"); 1047 puts("Host");
1061 break; 1048 break;
1062 default: 1049 default:
1063 printf("Unknown"); 1050 puts("Unknown");
1064 } 1051 }
1065 puts("");
1066 } 1052 }
1067 } 1053 }
1068 fclose(f); 1054 fclose(f);
@@ -1144,14 +1130,13 @@ static void ife_print(struct interface *ptr)
1144} 1130}
1145 1131
1146 1132
1147static int do_if_print(struct interface *ife, void *cookie) 1133static int do_if_print(struct interface *ife) /*, int *opt_a)*/
1148{ 1134{
1149 int *opt_a = (int *) cookie;
1150 int res; 1135 int res;
1151 1136
1152 res = do_if_fetch(ife); 1137 res = do_if_fetch(ife);
1153 if (res >= 0) { 1138 if (res >= 0) {
1154 if ((ife->flags & IFF_UP) || *opt_a) 1139 if ((ife->flags & IFF_UP) || interface_opt_a)
1155 ife_print(ife); 1140 ife_print(ife);
1156 } 1141 }
1157 return res; 1142 return res;
@@ -1167,21 +1152,45 @@ static struct interface *lookup_interface(char *name)
1167 return ife; 1152 return ife;
1168} 1153}
1169 1154
1155#ifdef UNUSED
1156static int for_all_interfaces(int (*doit) (struct interface *, void *),
1157 void *cookie)
1158{
1159 struct interface *ife;
1160
1161 if (!int_list && (if_readlist() < 0))
1162 return -1;
1163 for (ife = int_list; ife; ife = ife->next) {
1164 int err = doit(ife, cookie);
1165
1166 if (err)
1167 return err;
1168 }
1169 return 0;
1170}
1171#endif
1172
1170/* for ipv4 add/del modes */ 1173/* for ipv4 add/del modes */
1171static int if_print(char *ifname) 1174static int if_print(char *ifname)
1172{ 1175{
1176 struct interface *ife;
1173 int res; 1177 int res;
1174 1178
1175 if (!ifname) { 1179 if (!ifname) {
1176 res = for_all_interfaces(do_if_print, &interface_opt_a); 1180 /*res = for_all_interfaces(do_if_print, &interface_opt_a);*/
1177 } else { 1181 if (!int_list && (if_readlist() < 0))
1178 struct interface *ife; 1182 return -1;
1179 1183 for (ife = int_list; ife; ife = ife->next) {
1180 ife = lookup_interface(ifname); 1184 int err = do_if_print(ife); /*, &interface_opt_a);*/
1181 res = do_if_fetch(ife); 1185 if (err)
1182 if (res >= 0) 1186 return err;
1183 ife_print(ife); 1187 }
1188 return 0;
1184 } 1189 }
1190 ife = lookup_interface(ifname);
1191 res = do_if_fetch(ife);
1192 if (res >= 0)
1193 ife_print(ife);
1185 return res; 1194 return res;
1186} 1195}
1187 1196