aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManuel Novoa III <mjn3@codepoet.org>2001-03-12 09:57:59 +0000
committerManuel Novoa III <mjn3@codepoet.org>2001-03-12 09:57:59 +0000
commit68ea1d032561b9bd47c0b0877ec58ddd1288b594 (patch)
treeda374e2e60360979e05c36541a88b99b41b08190
parent1365bb786155439041b7777d31bcfadb5276e824 (diff)
downloadbusybox-w32-68ea1d032561b9bd47c0b0877ec58ddd1288b594.tar.gz
busybox-w32-68ea1d032561b9bd47c0b0877ec58ddd1288b594.tar.bz2
busybox-w32-68ea1d032561b9bd47c0b0877ec58ddd1288b594.zip
Reduced code size of interface. Support ifconfig -a and ifconfig interface
display. Change %llu to %Lu in ifconfig for hacked unsigned long long support in uClibc scanf.
-rw-r--r--ifconfig.c33
-rw-r--r--interface.c282
-rw-r--r--networking/ifconfig.c33
3 files changed, 208 insertions, 140 deletions
diff --git a/ifconfig.c b/ifconfig.c
index 95dda3bce..75bcf38e8 100644
--- a/ifconfig.c
+++ b/ifconfig.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: ifconfig.c,v 1.7 2001/03/10 02:00:54 mjn3 Exp $ 18 * $Id: ifconfig.c,v 1.8 2001/03/12 09:57:59 mjn3 Exp $
19 * 19 *
20 */ 20 */
21 21
@@ -26,7 +26,7 @@
26 * converting to a table-driven approach. Added several (optional) 26 * converting to a table-driven approach. Added several (optional)
27 * args missing from initial port. 27 * args missing from initial port.
28 * 28 *
29 * Still missing: media. 29 * Still missing: media, tunnel.
30 */ 30 */
31 31
32#include <stdio.h> 32#include <stdio.h>
@@ -234,7 +234,8 @@ static int in_ether(char *bufp, struct sockaddr *sap);
234#endif 234#endif
235 235
236#ifdef BB_FEATURE_IFCONFIG_STATUS 236#ifdef BB_FEATURE_IFCONFIG_STATUS
237extern int display_interfaces(int display_all); 237extern int interface_opt_a;
238extern int display_interfaces(char *ifname);
238#endif 239#endif
239 240
240/* 241/*
@@ -261,24 +262,26 @@ int ifconfig_main(int argc, char **argv)
261 goterr = 0; 262 goterr = 0;
262 did_flags = 0; 263 did_flags = 0;
263 264
264 if(argc < 2) {
265#ifdef BB_FEATURE_IFCONFIG_STATUS
266 return(display_interfaces(0));
267#else
268 show_usage();
269#endif
270 }
271
272 /* skip argv[0] */ 265 /* skip argv[0] */
273 argc--; 266 ++argv;
274 argv++; 267 --argc;
275 268
276#ifdef BB_FEATURE_IFCONFIG_STATUS 269#ifdef BB_FEATURE_IFCONFIG_STATUS
277 if ((argc == 1) && (strcmp(*argv, "-a") == 0)) { 270 if ((argc > 0) && (strcmp(*argv,"-a") == 0)) {
278 return(display_interfaces(1)); 271 interface_opt_a = 1;
272 --argc;
273 ++argv;
279 } 274 }
280#endif 275#endif
281 276
277 if(argc <= 1) {
278#ifdef BB_FEATURE_IFCONFIG_STATUS
279 return display_interfaces(argc ? *argv : NULL);
280#else
281 show_usage();
282#endif
283 }
284
282 /* Create a channel to the NET kernel. */ 285 /* Create a channel to the NET kernel. */
283 if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { 286 if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
284 perror_msg_and_die("socket"); 287 perror_msg_and_die("socket");
diff --git a/interface.c b/interface.c
index 648888bf5..b6478746a 100644
--- a/interface.c
+++ b/interface.c
@@ -3,7 +3,7 @@
3 * that either displays or sets the characteristics of 3 * that either displays or sets the characteristics of
4 * one or more of the system's networking interfaces. 4 * one or more of the system's networking interfaces.
5 * 5 *
6 * Version: $Id: interface.c,v 1.3 2001/03/10 02:00:54 mjn3 Exp $ 6 * Version: $Id: interface.c,v 1.4 2001/03/12 09:57:59 mjn3 Exp $
7 * 7 *
8 * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> 8 * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
9 * and others. Copyright 1993 MicroWalt Corporation 9 * and others. Copyright 1993 MicroWalt Corporation
@@ -26,6 +26,17 @@
26 * Erik Andersen <andersee@debian.org> 26 * Erik Andersen <andersee@debian.org>
27 */ 27 */
28 28
29/*
30 * Heavily modified by Manuel Novoa III Mar 12, 2001
31 *
32 * Pruned unused code using KEEP_UNUSED define.
33 * Added print_bytes_scaled function to reduce code size.
34 * Added some (potentially) missing defines.
35 * Improved display support for -a and for a named interface.
36 */
37
38/* #define KEEP_UNUSED */
39
29#include "busybox.h" 40#include "busybox.h"
30 41
31/* 42/*
@@ -75,7 +86,7 @@
75#define new(p) ((p) = xcalloc(1,sizeof(*(p)))) 86#define new(p) ((p) = xcalloc(1,sizeof(*(p))))
76#define KRELEASE(maj,min,patch) ((maj) * 10000 + (min)*1000 + (patch)) 87#define KRELEASE(maj,min,patch) ((maj) * 10000 + (min)*1000 + (patch))
77 88
78int procnetdev_vsn = 1; 89static int procnetdev_vsn = 1;
79 90
80 91
81/* Ugh. But libc5 doesn't provide POSIX types. */ 92/* Ugh. But libc5 doesn't provide POSIX types. */
@@ -120,10 +131,29 @@ struct in6_ifreq {
120#include "util.h" 131#include "util.h"
121#endif 132#endif
122 133
134/* Defines for glibc2.0 users. */
135#ifndef SIOCSIFTXQLEN
136#define SIOCSIFTXQLEN 0x8943
137#define SIOCGIFTXQLEN 0x8942
138#endif
139
140/* ifr_qlen is ifru_ivalue, but it isn't present in 2.0 kernel headers */
141#ifndef ifr_qlen
142#define ifr_qlen ifr_ifru.ifru_mtu
143#endif
144
145#ifndef HAVE_TXQUEUELEN
146#define HAVE_TXQUEUELEN 1
147#endif
148
149#ifndef IFF_DYNAMIC
150#define IFF_DYNAMIC 0x8000 /* dialup device with changing addresses */
151#endif
152
123/* This structure defines protocol families and their handlers. */ 153/* This structure defines protocol families and their handlers. */
124struct aftype { 154struct aftype {
125 char *name; 155 const char *name;
126 char *title; 156 const char *title;
127 int af; 157 int af;
128 int alen; 158 int alen;
129 char *(*print) (unsigned char *); 159 char *(*print) (unsigned char *);
@@ -140,20 +170,23 @@ struct aftype {
140 char *flag_file; 170 char *flag_file;
141}; 171};
142 172
143extern struct aftype *aftypes[]; 173static struct aftype *aftypes[];
144int flag_unx; 174
145int flag_ipx; 175#ifdef KEEP_UNUSED
146int flag_ax25;
147int flag_ddp;
148int flag_netrom;
149int flag_inet;
150int flag_inet6;
151int flag_econet;
152int flag_x25 = 0;
153int flag_ash;
154 176
177static int flag_unx;
178static int flag_ipx;
179static int flag_ax25;
180static int flag_ddp;
181static int flag_netrom;
182static int flag_inet;
183static int flag_inet6;
184static int flag_econet;
185static int flag_x25 = 0;
186static int flag_ash;
155 187
156struct aftrans_t { 188
189static struct aftrans_t {
157 char *alias; 190 char *alias;
158 char *name; 191 char *name;
159 int *flag; 192 int *flag;
@@ -206,7 +239,8 @@ struct aftrans_t {
206 } 239 }
207}; 240};
208 241
209char afname[256] = ""; 242static char afname[256] = "";
243#endif /* KEEP_UNUSED */
210 244
211#if HAVE_AFUNIX 245#if HAVE_AFUNIX
212 246
@@ -228,9 +262,9 @@ static char *UNIX_sprint(struct sockaddr *sap, int numeric)
228} 262}
229 263
230 264
231struct aftype unix_aftype = 265static struct aftype unix_aftype =
232{ 266{
233 "unix", NULL, /*"UNIX Domain", */ AF_UNIX, 0, 267 "unix", "UNIX Domain", AF_UNIX, 0,
234 UNIX_print, UNIX_sprint, NULL, NULL, 268 UNIX_print, UNIX_sprint, NULL, NULL,
235 NULL, NULL, NULL, 269 NULL, NULL, NULL,
236 -1, 270 -1,
@@ -240,7 +274,9 @@ struct aftype unix_aftype =
240 274
241#if HAVE_AFINET 275#if HAVE_AFINET
242 276
277#if 0
243extern int h_errno; /* some netdb.h versions don't export this */ 278extern int h_errno; /* some netdb.h versions don't export this */
279#endif
244 280
245/* cache */ 281/* cache */
246struct addr { 282struct addr {
@@ -252,6 +288,7 @@ struct addr {
252 288
253static struct addr *INET_nn = NULL; /* addr-to-name cache */ 289static struct addr *INET_nn = NULL; /* addr-to-name cache */
254 290
291#ifdef KEEP_UNUSED
255static int INET_resolve(char *name, struct sockaddr_in *sin, int hostfirst) 292static int INET_resolve(char *name, struct sockaddr_in *sin, int hostfirst)
256{ 293{
257 struct hostent *hp; 294 struct hostent *hp;
@@ -310,7 +347,7 @@ static int INET_resolve(char *name, struct sockaddr_in *sin, int hostfirst)
310 347
311 return 0; 348 return 0;
312} 349}
313 350#endif /* KEEP_UNUSED */
314 351
315/* numeric: & 0x8000: default instead of *, 352/* numeric: & 0x8000: default instead of *,
316 * & 0x4000: host instead of net, 353 * & 0x4000: host instead of net,
@@ -399,19 +436,18 @@ static int INET_rresolve(char *name, size_t len, struct sockaddr_in *sin,
399 return (0); 436 return (0);
400} 437}
401 438
402 439#ifdef KEEP_UNUSED
403static void INET_reserror(char *text) 440static void INET_reserror(char *text)
404{ 441{
405 herror(text); 442 herror(text);
406} 443}
407 444
408
409/* Display an Internet socket address. */ 445/* Display an Internet socket address. */
410static char *INET_print(unsigned char *ptr) 446static char *INET_print(unsigned char *ptr)
411{ 447{
412 return (inet_ntoa((*(struct in_addr *) ptr))); 448 return (inet_ntoa((*(struct in_addr *) ptr)));
413} 449}
414 450#endif /* KEEP_UNUSED */
415 451
416/* Display an Internet socket address. */ 452/* Display an Internet socket address. */
417static char *INET_sprint(struct sockaddr *sap, int numeric) 453static char *INET_sprint(struct sockaddr *sap, int numeric)
@@ -428,7 +464,8 @@ static char *INET_sprint(struct sockaddr *sap, int numeric)
428 return (buff); 464 return (buff);
429} 465}
430 466
431char *INET_sprintmask(struct sockaddr *sap, int numeric, 467#ifdef KEEP_UNUSED
468static char *INET_sprintmask(struct sockaddr *sap, int numeric,
432 unsigned int netmask) 469 unsigned int netmask)
433{ 470{
434 static char buff[128]; 471 static char buff[128];
@@ -441,7 +478,6 @@ char *INET_sprintmask(struct sockaddr *sap, int numeric,
441 return (buff); 478 return (buff);
442} 479}
443 480
444
445static int INET_getsock(char *bufp, struct sockaddr *sap) 481static int INET_getsock(char *bufp, struct sockaddr *sap)
446{ 482{
447 char *sp = bufp, *bp; 483 char *sp = bufp, *bp;
@@ -516,14 +552,15 @@ static int INET_getnetmask(char *adr, struct sockaddr *m, char *name)
516 mask->sin_addr.s_addr = htonl(~(0xffffffffU >> prefix)); 552 mask->sin_addr.s_addr = htonl(~(0xffffffffU >> prefix));
517 return 1; 553 return 1;
518} 554}
555#endif /* KEEP_UNUSED */
519 556
520 557static struct aftype inet_aftype =
521struct aftype inet_aftype =
522{ 558{
523 "inet", NULL, /*"DARPA Internet", */ AF_INET, sizeof(unsigned long), 559 "inet", "DARPA Internet", AF_INET, sizeof(unsigned long),
524 INET_print, INET_sprint, INET_input, INET_reserror, 560 NULL /* UNUSED INET_print */, INET_sprint,
561 NULL /* UNUSED INET_input */, NULL /* UNUSED INET_reserror */,
525 NULL /*INET_rprint */ , NULL /*INET_rinput */ , 562 NULL /*INET_rprint */ , NULL /*INET_rinput */ ,
526 INET_getnetmask, 563 NULL /* UNUSED INET_getnetmask */,
527 -1, 564 -1,
528 NULL 565 NULL
529}; 566};
@@ -555,16 +592,14 @@ static char *UNSPEC_sprint(struct sockaddr *sap, int numeric)
555 return (UNSPEC_print(sap->sa_data)); 592 return (UNSPEC_print(sap->sa_data));
556} 593}
557 594
558struct aftype unspec_aftype = 595static struct aftype unspec_aftype =
559{ 596{
560 "unspec", NULL, /*"UNSPEC", */ AF_UNSPEC, 0, 597 "unspec", "UNSPEC", AF_UNSPEC, 0,
561 UNSPEC_print, UNSPEC_sprint, NULL, NULL, 598 UNSPEC_print, UNSPEC_sprint, NULL, NULL,
562 NULL, 599 NULL,
563}; 600};
564 601
565static short sVafinit = 0; 602static struct aftype *aftypes[] =
566
567struct aftype *aftypes[] =
568{ 603{
569#if HAVE_AFUNIX 604#if HAVE_AFUNIX
570 &unix_aftype, 605 &unix_aftype,
@@ -603,7 +638,10 @@ struct aftype *aftypes[] =
603 NULL 638 NULL
604}; 639};
605 640
606void afinit() 641#ifdef KEEP_UNUSED
642static short sVafinit = 0;
643
644static void afinit()
607{ 645{
608 unspec_aftype.title = _("UNSPEC"); 646 unspec_aftype.title = _("UNSPEC");
609#if HAVE_AFUNIX 647#if HAVE_AFUNIX
@@ -642,7 +680,7 @@ void afinit()
642 sVafinit = 1; 680 sVafinit = 1;
643} 681}
644 682
645int aftrans_opt(const char *arg) 683static int aftrans_opt(const char *arg)
646{ 684{
647 struct aftrans_t *paft; 685 struct aftrans_t *paft;
648 char *tmp1, *tmp2; 686 char *tmp1, *tmp2;
@@ -685,7 +723,7 @@ int aftrans_opt(const char *arg)
685} 723}
686 724
687/* set the default AF list from the program name or a constant value */ 725/* set the default AF list from the program name or a constant value */
688void aftrans_def(char *tool, char *argv0, char *dflt) 726static void aftrans_def(char *tool, char *argv0, char *dflt)
689{ 727{
690 char *tmp; 728 char *tmp;
691 char *buf; 729 char *buf;
@@ -721,14 +759,15 @@ void aftrans_def(char *tool, char *argv0, char *dflt)
721 free(buf); 759 free(buf);
722} 760}
723 761
724
725/* Check our protocol family table for this family. */ 762/* Check our protocol family table for this family. */
726struct aftype *get_aftype(const char *name) 763static struct aftype *get_aftype(const char *name)
727{ 764{
728 struct aftype **afp; 765 struct aftype **afp;
729 766
767#ifdef KEEP_UNUSED
730 if (!sVafinit) 768 if (!sVafinit)
731 afinit(); 769 afinit();
770#endif /* KEEP_UNUSED */
732 771
733 afp = aftypes; 772 afp = aftypes;
734 while (*afp != NULL) { 773 while (*afp != NULL) {
@@ -740,15 +779,17 @@ struct aftype *get_aftype(const char *name)
740 fprintf(stderr, _("Please don't supply more than one address family.\n")); 779 fprintf(stderr, _("Please don't supply more than one address family.\n"));
741 return (NULL); 780 return (NULL);
742} 781}
743 782#endif /* KEEP_UNUSED */
744 783
745/* Check our protocol family table for this family. */ 784/* Check our protocol family table for this family. */
746struct aftype *get_afntype(int af) 785static struct aftype *get_afntype(int af)
747{ 786{
748 struct aftype **afp; 787 struct aftype **afp;
749 788
789#ifdef KEEP_UNUSED
750 if (!sVafinit) 790 if (!sVafinit)
751 afinit(); 791 afinit();
792#endif /* KEEP_UNUSED */
752 793
753 afp = aftypes; 794 afp = aftypes;
754 while (*afp != NULL) { 795 while (*afp != NULL) {
@@ -760,12 +801,14 @@ struct aftype *get_afntype(int af)
760} 801}
761 802
762/* Check our protocol family table for this family and return its socket */ 803/* Check our protocol family table for this family and return its socket */
763int get_socket_for_af(int af) 804static int get_socket_for_af(int af)
764{ 805{
765 struct aftype **afp; 806 struct aftype **afp;
766 807
808#ifdef KEEP_UNUSED
767 if (!sVafinit) 809 if (!sVafinit)
768 afinit(); 810 afinit();
811#endif /* KEEP_UNUSED */
769 812
770 afp = aftypes; 813 afp = aftypes;
771 while (*afp != NULL) { 814 while (*afp != NULL) {
@@ -776,14 +819,17 @@ int get_socket_for_af(int af)
776 return -1; 819 return -1;
777} 820}
778 821
822#ifdef KEEP_UNUSED
779/* type: 0=all, 1=getroute */ 823/* type: 0=all, 1=getroute */
780void print_aflist(int type) { 824static void print_aflist(int type) {
781 int count = 0; 825 int count = 0;
782 char * txt; 826 char * txt;
783 struct aftype **afp; 827 struct aftype **afp;
784 828
829#ifdef KEEP_UNUSED
785 if (!sVafinit) 830 if (!sVafinit)
786 afinit(); 831 afinit();
832#endif /* KEEP_UNUSED */
787 833
788 afp = aftypes; 834 afp = aftypes;
789 while (*afp != NULL) { 835 while (*afp != NULL) {
@@ -792,12 +838,13 @@ void print_aflist(int type) {
792 } 838 }
793 if ((count % 3) == 0) fprintf(stderr,count?"\n ":" "); 839 if ((count % 3) == 0) fprintf(stderr,count?"\n ":" ");
794 txt = (*afp)->name; if (!txt) txt = ".."; 840 txt = (*afp)->name; if (!txt) txt = "..";
795 fprintf(stderr,"%s (%s) ",txt,(*afp)->title); 841 fprintf(stderr,"%s (%s) ",txt,_((*afp)->title));
796 count++; 842 count++;
797 afp++; 843 afp++;
798 } 844 }
799 fprintf(stderr,"\n"); 845 fprintf(stderr,"\n");
800} 846}
847#endif /* KEEP_UNUSED */
801 848
802struct user_net_device_stats { 849struct user_net_device_stats {
803 unsigned long long rx_packets; /* total packets received */ 850 unsigned long long rx_packets; /* total packets received */
@@ -863,16 +910,20 @@ struct interface {
863}; 910};
864 911
865 912
866int opt_a = 0; /* show all interfaces */ 913int interface_opt_a = 0; /* show all interfaces */
867int opt_i = 0; /* show the statistics */ 914
868int opt_v = 0; /* debugging output flag */ 915#ifdef KEEP_UNUSED
916static int opt_i = 0; /* show the statistics */
917static int opt_v = 0; /* debugging output flag */
918
919static int addr_family = 0; /* currently selected AF */
920#endif /* KEEP_UNUSED */
869 921
870int addr_family = 0; /* currently selected AF */
871static struct interface *int_list, *int_last; 922static struct interface *int_list, *int_last;
872int skfd = -1; /* generic raw socket desc. */ 923static int skfd = -1; /* generic raw socket desc. */
873 924
874 925
875int sockets_open(int family) 926static int sockets_open(int family)
876{ 927{
877 struct aftype **aft; 928 struct aftype **aft;
878 int sfd = -1; 929 int sfd = -1;
@@ -919,7 +970,7 @@ int sockets_open(int family)
919} 970}
920 971
921/* like strcmp(), but knows about numbers */ 972/* like strcmp(), but knows about numbers */
922int nstrcmp(const char *astr, const char *b) 973static int nstrcmp(const char *astr, const char *b)
923{ 974{
924 const char *a = astr; 975 const char *a = astr;
925 976
@@ -1053,7 +1104,7 @@ static int get_dev_fields(char *bp, struct interface *ife)
1053 switch (procnetdev_vsn) { 1104 switch (procnetdev_vsn) {
1054 case 3: 1105 case 3:
1055 sscanf(bp, 1106 sscanf(bp,
1056 "%llu %llu %lu %lu %lu %lu %lu %lu %llu %llu %lu %lu %lu %lu %lu %lu", 1107 "%Lu %Lu %lu %lu %lu %lu %lu %lu %Lu %Lu %lu %lu %lu %lu %lu %lu",
1057 &ife->stats.rx_bytes, 1108 &ife->stats.rx_bytes,
1058 &ife->stats.rx_packets, 1109 &ife->stats.rx_packets,
1059 &ife->stats.rx_errors, 1110 &ife->stats.rx_errors,
@@ -1073,7 +1124,7 @@ static int get_dev_fields(char *bp, struct interface *ife)
1073 &ife->stats.tx_compressed); 1124 &ife->stats.tx_compressed);
1074 break; 1125 break;
1075 case 2: 1126 case 2:
1076 sscanf(bp, "%llu %llu %lu %lu %lu %lu %llu %llu %lu %lu %lu %lu %lu", 1127 sscanf(bp, "%Lu %Lu %lu %lu %lu %lu %Lu %Lu %lu %lu %lu %lu %lu",
1077 &ife->stats.rx_bytes, 1128 &ife->stats.rx_bytes,
1078 &ife->stats.rx_packets, 1129 &ife->stats.rx_packets,
1079 &ife->stats.rx_errors, 1130 &ife->stats.rx_errors,
@@ -1091,7 +1142,7 @@ static int get_dev_fields(char *bp, struct interface *ife)
1091 ife->stats.rx_multicast = 0; 1142 ife->stats.rx_multicast = 0;
1092 break; 1143 break;
1093 case 1: 1144 case 1:
1094 sscanf(bp, "%llu %lu %lu %lu %lu %llu %lu %lu %lu %lu %lu", 1145 sscanf(bp, "%Lu %lu %lu %lu %lu %Lu %lu %lu %lu %lu %lu",
1095 &ife->stats.rx_packets, 1146 &ife->stats.rx_packets,
1096 &ife->stats.rx_errors, 1147 &ife->stats.rx_errors,
1097 &ife->stats.rx_dropped, 1148 &ife->stats.rx_dropped,
@@ -1112,7 +1163,7 @@ static int get_dev_fields(char *bp, struct interface *ife)
1112 return 0; 1163 return 0;
1113} 1164}
1114 1165
1115static int procnetdev_version(char *buf) 1166static inline int procnetdev_version(char *buf)
1116{ 1167{
1117 if (strstr(buf, "compressed")) 1168 if (strstr(buf, "compressed"))
1118 return 3; 1169 return 3;
@@ -1192,7 +1243,7 @@ static int if_readlist_proc(char *target)
1192 return err; 1243 return err;
1193} 1244}
1194 1245
1195int if_readlist(void) 1246static int if_readlist(void)
1196{ 1247{
1197 int err = if_readlist_proc(NULL); 1248 int err = if_readlist_proc(NULL);
1198 if (!err) 1249 if (!err)
@@ -1200,7 +1251,7 @@ int if_readlist(void)
1200 return err; 1251 return err;
1201} 1252}
1202 1253
1203int for_all_interfaces(int (*doit) (struct interface *, void *), void *cookie) 1254static int for_all_interfaces(int (*doit) (struct interface *, void *), void *cookie)
1204{ 1255{
1205 struct interface *ife; 1256 struct interface *ife;
1206 1257
@@ -1226,7 +1277,7 @@ static int ipx_getaddr(int sock, int ft, struct ifreq *ifr)
1226 1277
1227 1278
1228/* Fetch the interface configuration from the kernel. */ 1279/* Fetch the interface configuration from the kernel. */
1229int if_fetch(struct interface *ife) 1280static int if_fetch(struct interface *ife)
1230{ 1281{
1231 struct ifreq ifr; 1282 struct ifreq ifr;
1232 int fd; 1283 int fd;
@@ -1386,7 +1437,7 @@ int if_fetch(struct interface *ife)
1386} 1437}
1387 1438
1388 1439
1389int do_if_fetch(struct interface *ife) 1440static int do_if_fetch(struct interface *ife)
1390{ 1441{
1391 if (if_fetch(ife) < 0) { 1442 if (if_fetch(ife) < 0) {
1392 char *errmsg; 1443 char *errmsg;
@@ -1405,8 +1456,8 @@ int do_if_fetch(struct interface *ife)
1405 1456
1406/* This structure defines hardware protocols and their handlers. */ 1457/* This structure defines hardware protocols and their handlers. */
1407struct hwtype { 1458struct hwtype {
1408 char *name; 1459 const char *name;
1409 char *title; 1460 const char *title;
1410 int type; 1461 int type;
1411 int alen; 1462 int alen;
1412 char *(*print) (unsigned char *); 1463 char *(*print) (unsigned char *);
@@ -1430,15 +1481,15 @@ static char *pr_unspec(unsigned char *ptr)
1430 return (buff); 1481 return (buff);
1431} 1482}
1432 1483
1433struct hwtype unspec_hwtype = 1484static struct hwtype unspec_hwtype =
1434{ 1485{
1435 "unspec", NULL, /*"UNSPEC", */ -1, 0, 1486 "unspec", "UNSPEC", -1, 0,
1436 pr_unspec, NULL, NULL 1487 pr_unspec, NULL, NULL
1437}; 1488};
1438 1489
1439struct hwtype loop_hwtype = 1490static struct hwtype loop_hwtype =
1440{ 1491{
1441 "loop", NULL, /*"Local Loopback", */ ARPHRD_LOOPBACK, 0, 1492 "loop", "Local Loopback", ARPHRD_LOOPBACK, 0,
1442 NULL, NULL, NULL 1493 NULL, NULL, NULL
1443}; 1494};
1444 1495
@@ -1446,7 +1497,7 @@ struct hwtype loop_hwtype =
1446#include <net/if_arp.h> 1497#include <net/if_arp.h>
1447#include <linux/if_ether.h> 1498#include <linux/if_ether.h>
1448 1499
1449extern struct hwtype ether_hwtype; 1500static struct hwtype ether_hwtype;
1450 1501
1451/* Display an Ethernet address in readable format. */ 1502/* Display an Ethernet address in readable format. */
1452static char *pr_ether(unsigned char *ptr) 1503static char *pr_ether(unsigned char *ptr)
@@ -1460,7 +1511,7 @@ static char *pr_ether(unsigned char *ptr)
1460 return (buff); 1511 return (buff);
1461} 1512}
1462 1513
1463 1514#ifdef KEEP_UNUSED
1464/* Input an Ethernet address and convert to binary. */ 1515/* Input an Ethernet address and convert to binary. */
1465static int in_ether(char *bufp, struct sockaddr *sap) 1516static int in_ether(char *bufp, struct sockaddr *sap)
1466{ 1517{
@@ -1539,12 +1590,13 @@ static int in_ether(char *bufp, struct sockaddr *sap)
1539 1590
1540 return (0); 1591 return (0);
1541} 1592}
1593#endif /* KEEP_UNUSED */
1542 1594
1543 1595
1544struct hwtype ether_hwtype = 1596static struct hwtype ether_hwtype =
1545{ 1597{
1546 "ether", NULL, /*"10Mbps Ethernet", */ ARPHRD_ETHER, ETH_ALEN, 1598 "ether", "Ethernet", ARPHRD_ETHER, ETH_ALEN,
1547 pr_ether, in_ether, NULL 1599 pr_ether, NULL /* UNUSED in_ether */, NULL
1548}; 1600};
1549 1601
1550 1602
@@ -1555,18 +1607,19 @@ struct hwtype ether_hwtype =
1555 1607
1556#include <net/if_arp.h> 1608#include <net/if_arp.h>
1557 1609
1610#ifdef KEEP_UNUSED
1558/* Start the PPP encapsulation on the file descriptor. */ 1611/* Start the PPP encapsulation on the file descriptor. */
1559static int do_ppp(int fd) 1612static int do_ppp(int fd)
1560{ 1613{
1561 fprintf(stderr, _("You cannot start PPP with this program.\n")); 1614 fprintf(stderr, _("You cannot start PPP with this program.\n"));
1562 return -1; 1615 return -1;
1563} 1616}
1617#endif /* KEEP_UNUSED */
1564 1618
1565 1619static struct hwtype ppp_hwtype =
1566struct hwtype ppp_hwtype =
1567{ 1620{
1568 "ppp", NULL, /*"Point-Point Protocol", */ ARPHRD_PPP, 0, 1621 "ppp", "Point-Point Protocol", ARPHRD_PPP, 0,
1569 NULL, NULL, do_ppp, 0 1622 NULL, NULL, NULL /* UNUSED do_ppp */, 0
1570}; 1623};
1571 1624
1572 1625
@@ -1647,9 +1700,10 @@ static struct hwtype *hwtypes[] =
1647 NULL 1700 NULL
1648}; 1701};
1649 1702
1703#ifdef KEEP_UNUSED
1650static short sVhwinit = 0; 1704static short sVhwinit = 0;
1651 1705
1652void hwinit() 1706static void hwinit()
1653{ 1707{
1654 loop_hwtype.title = _("Local Loopback"); 1708 loop_hwtype.title = _("Local Loopback");
1655 unspec_hwtype.title = _("UNSPEC"); 1709 unspec_hwtype.title = _("UNSPEC");
@@ -1718,9 +1772,10 @@ void hwinit()
1718#endif 1772#endif
1719 sVhwinit = 1; 1773 sVhwinit = 1;
1720} 1774}
1775#endif /* KEEP_UNUSED */
1721 1776
1722#ifdef IFF_PORTSEL 1777#ifdef IFF_PORTSEL
1723const char *if_port_text[][4] = 1778static const char *if_port_text[][4] =
1724{ 1779{
1725 /* Keep in step with <linux/netdevice.h> */ 1780 /* Keep in step with <linux/netdevice.h> */
1726 {"unknown", NULL, NULL, NULL}, 1781 {"unknown", NULL, NULL, NULL},
@@ -1735,12 +1790,14 @@ const char *if_port_text[][4] =
1735#endif 1790#endif
1736 1791
1737/* Check our hardware type table for this type. */ 1792/* Check our hardware type table for this type. */
1738struct hwtype *get_hwntype(int type) 1793static struct hwtype *get_hwntype(int type)
1739{ 1794{
1740 struct hwtype **hwp; 1795 struct hwtype **hwp;
1741 1796
1797#ifdef KEEP_UNUSED
1742 if (!sVhwinit) 1798 if (!sVhwinit)
1743 hwinit(); 1799 hwinit();
1800#endif /* KEEP_UNUSED */
1744 1801
1745 hwp = hwtypes; 1802 hwp = hwtypes;
1746 while (*hwp != NULL) { 1803 while (*hwp != NULL) {
@@ -1752,7 +1809,7 @@ struct hwtype *get_hwntype(int type)
1752} 1809}
1753 1810
1754/* return 1 if address is all zeros */ 1811/* return 1 if address is all zeros */
1755int hw_null_address(struct hwtype *hw, void *ap) 1812static int hw_null_address(struct hwtype *hw, void *ap)
1756{ 1813{
1757 unsigned int i; 1814 unsigned int i;
1758 unsigned char *address = (unsigned char *)ap; 1815 unsigned char *address = (unsigned char *)ap;
@@ -1762,15 +1819,35 @@ int hw_null_address(struct hwtype *hw, void *ap)
1762 return 1; 1819 return 1;
1763} 1820}
1764 1821
1765void ife_print(struct interface *ptr) 1822static const char TRext[] = "\0\0k\0M";
1823
1824static void print_bytes_scaled(unsigned long long ull, const char *end)
1825{
1826 unsigned long long int_part;
1827 unsigned long frac_part;
1828 const char *ext;
1829 int i;
1830
1831 frac_part = 0;
1832 ext = TRext;
1833 int_part = ull;
1834 for (i=0 ; i<2 ; i++) {
1835 if (int_part >= 1024) {
1836 frac_part = ((int_part % 1024) * 10) / 1024;
1837 int_part /= 1024;
1838 ext += 2; /* Kb, Mb */
1839 }
1840 }
1841
1842 printf("X bytes:%Lu (%Lu.%lu %sb)%s", ull, int_part, frac_part, ext, end);
1843}
1844
1845static void ife_print(struct interface *ptr)
1766{ 1846{
1767 struct aftype *ap; 1847 struct aftype *ap;
1768 struct hwtype *hw; 1848 struct hwtype *hw;
1769 int hf; 1849 int hf;
1770 int can_compress = 0; 1850 int can_compress = 0;
1771 unsigned long long rx, tx, short_rx, short_tx;
1772 char Rext[5]="b";
1773 char Text[5]="b";
1774 1851
1775#if HAVE_AFIPX 1852#if HAVE_AFIPX
1776 static struct aftype *ipxtype = NULL; 1853 static struct aftype *ipxtype = NULL;
@@ -1803,7 +1880,7 @@ void ife_print(struct interface *ptr)
1803 if (hw == NULL) 1880 if (hw == NULL)
1804 hw = get_hwntype(-1); 1881 hw = get_hwntype(-1);
1805 1882
1806 printf(_("%-9.9s Link encap:%s "), ptr->name, hw->title); 1883 printf(_("%-9.9s Link encap:%s "), ptr->name, _(hw->title));
1807 /* For some hardware types (eg Ash, ATM) we don't print the 1884 /* For some hardware types (eg Ash, ATM) we don't print the
1808 hardware address if it's null. */ 1885 hardware address if it's null. */
1809 if (hw->print != NULL && (! (hw_null_address(hw, ptr->hwaddr) && 1886 if (hw->print != NULL && (! (hw_null_address(hw, ptr->hwaddr) &&
@@ -1965,24 +2042,14 @@ void ife_print(struct interface *ptr)
1965 */ 2042 */
1966 printf(" "); 2043 printf(" ");
1967 2044
1968 printf(_("RX packets:%llu errors:%lu dropped:%lu overruns:%lu frame:%lu\n"), 2045 printf(_("RX packets:%Lu errors:%lu dropped:%lu overruns:%lu frame:%lu\n"),
1969 ptr->stats.rx_packets, ptr->stats.rx_errors, 2046 ptr->stats.rx_packets, ptr->stats.rx_errors,
1970 ptr->stats.rx_dropped, ptr->stats.rx_fifo_errors, 2047 ptr->stats.rx_dropped, ptr->stats.rx_fifo_errors,
1971 ptr->stats.rx_frame_errors); 2048 ptr->stats.rx_frame_errors);
1972 if (can_compress) 2049 if (can_compress)
1973 printf(_(" compressed:%lu\n"), ptr->stats.rx_compressed); 2050 printf(_(" compressed:%lu\n"), ptr->stats.rx_compressed);
1974
1975 rx = ptr->stats.rx_bytes;
1976 tx = ptr->stats.tx_bytes;
1977 short_rx = rx * 10;
1978 short_tx = tx * 10;
1979 if (rx > 1048576) { short_rx /= 1048576; strcpy(Rext, "Mb"); }
1980 else if (rx > 1024) { short_rx /= 1024; strcpy(Rext, "Kb"); }
1981 if (tx > 1048576) { short_tx /= 1048576; strcpy(Text, "Mb"); }
1982 else if (tx > 1024) { short_tx /= 1024; strcpy(Text, "Kb"); }
1983
1984 printf(" "); 2051 printf(" ");
1985 printf(_("TX packets:%llu errors:%lu dropped:%lu overruns:%lu carrier:%lu\n"), 2052 printf(_("TX packets:%Lu errors:%lu dropped:%lu overruns:%lu carrier:%lu\n"),
1986 ptr->stats.tx_packets, ptr->stats.tx_errors, 2053 ptr->stats.tx_packets, ptr->stats.tx_errors,
1987 ptr->stats.tx_dropped, ptr->stats.tx_fifo_errors, 2054 ptr->stats.tx_dropped, ptr->stats.tx_fifo_errors,
1988 ptr->stats.tx_carrier_errors); 2055 ptr->stats.tx_carrier_errors);
@@ -1991,12 +2058,10 @@ void ife_print(struct interface *ptr)
1991 printf(_("compressed:%lu "), ptr->stats.tx_compressed); 2058 printf(_("compressed:%lu "), ptr->stats.tx_compressed);
1992 if (ptr->tx_queue_len != -1) 2059 if (ptr->tx_queue_len != -1)
1993 printf(_("txqueuelen:%d "), ptr->tx_queue_len); 2060 printf(_("txqueuelen:%d "), ptr->tx_queue_len);
1994 printf("\n "); 2061 printf("\n R");
1995 printf(_("RX bytes:%llu (%lu.%lu %s) TX bytes:%llu (%lu.%lu %s)\n"), 2062 print_bytes_scaled(ptr->stats.rx_bytes, " T");
1996 rx, (unsigned long)(short_rx / 10), 2063 print_bytes_scaled(ptr->stats.rx_bytes, "\n");
1997 (unsigned long)(short_rx % 10), Rext, 2064
1998 tx, (unsigned long)(short_tx / 10),
1999 (unsigned long)(short_tx % 10), Text);
2000 } 2065 }
2001 2066
2002 if ((ptr->map.irq || ptr->map.mem_start || ptr->map.dma || 2067 if ((ptr->map.irq || ptr->map.mem_start || ptr->map.dma ||
@@ -2018,7 +2083,7 @@ void ife_print(struct interface *ptr)
2018} 2083}
2019 2084
2020 2085
2021int do_if_print(struct interface *ife, void *cookie) 2086static int do_if_print(struct interface *ife, void *cookie)
2022{ 2087{
2023 int *opt_a = (int *) cookie; 2088 int *opt_a = (int *) cookie;
2024 int res; 2089 int res;
@@ -2031,7 +2096,7 @@ int do_if_print(struct interface *ife, void *cookie)
2031 return res; 2096 return res;
2032} 2097}
2033 2098
2034struct interface *lookup_interface(char *name) 2099static struct interface *lookup_interface(char *name)
2035{ 2100{
2036 struct interface *ife = NULL; 2101 struct interface *ife = NULL;
2037 2102
@@ -2047,7 +2112,7 @@ static int if_print(char *ifname)
2047 int res; 2112 int res;
2048 2113
2049 if (!ifname) { 2114 if (!ifname) {
2050 res = for_all_interfaces(do_if_print, &opt_a); 2115 res = for_all_interfaces(do_if_print, &interface_opt_a);
2051 } else { 2116 } else {
2052 struct interface *ife; 2117 struct interface *ife;
2053 2118
@@ -2059,20 +2124,17 @@ static int if_print(char *ifname)
2059 return res; 2124 return res;
2060} 2125}
2061 2126
2062int display_interfaces(int opt_all) 2127int display_interfaces(char *ifname)
2063{ 2128{
2064 int status; 2129 int status;
2065 2130
2066 opt_a = opt_all;
2067
2068 /* Create a channel to the NET kernel. */ 2131 /* Create a channel to the NET kernel. */
2069 if ((skfd = sockets_open(0)) < 0) { 2132 if ((skfd = sockets_open(0)) < 0) {
2070 perror_msg_and_die("socket"); 2133 perror_msg_and_die("socket");
2071 } 2134 }
2072 2135
2073 /* Do we have to show the current setup? */ 2136 /* Do we have to show the current setup? */
2074 status = if_print((char *) NULL); 2137 status = if_print(ifname);
2075 close(skfd); 2138 close(skfd);
2076 exit(status < 0); 2139 exit(status < 0);
2077} 2140}
2078
diff --git a/networking/ifconfig.c b/networking/ifconfig.c
index 95dda3bce..75bcf38e8 100644
--- a/networking/ifconfig.c
+++ b/networking/ifconfig.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: ifconfig.c,v 1.7 2001/03/10 02:00:54 mjn3 Exp $ 18 * $Id: ifconfig.c,v 1.8 2001/03/12 09:57:59 mjn3 Exp $
19 * 19 *
20 */ 20 */
21 21
@@ -26,7 +26,7 @@
26 * converting to a table-driven approach. Added several (optional) 26 * converting to a table-driven approach. Added several (optional)
27 * args missing from initial port. 27 * args missing from initial port.
28 * 28 *
29 * Still missing: media. 29 * Still missing: media, tunnel.
30 */ 30 */
31 31
32#include <stdio.h> 32#include <stdio.h>
@@ -234,7 +234,8 @@ static int in_ether(char *bufp, struct sockaddr *sap);
234#endif 234#endif
235 235
236#ifdef BB_FEATURE_IFCONFIG_STATUS 236#ifdef BB_FEATURE_IFCONFIG_STATUS
237extern int display_interfaces(int display_all); 237extern int interface_opt_a;
238extern int display_interfaces(char *ifname);
238#endif 239#endif
239 240
240/* 241/*
@@ -261,24 +262,26 @@ int ifconfig_main(int argc, char **argv)
261 goterr = 0; 262 goterr = 0;
262 did_flags = 0; 263 did_flags = 0;
263 264
264 if(argc < 2) {
265#ifdef BB_FEATURE_IFCONFIG_STATUS
266 return(display_interfaces(0));
267#else
268 show_usage();
269#endif
270 }
271
272 /* skip argv[0] */ 265 /* skip argv[0] */
273 argc--; 266 ++argv;
274 argv++; 267 --argc;
275 268
276#ifdef BB_FEATURE_IFCONFIG_STATUS 269#ifdef BB_FEATURE_IFCONFIG_STATUS
277 if ((argc == 1) && (strcmp(*argv, "-a") == 0)) { 270 if ((argc > 0) && (strcmp(*argv,"-a") == 0)) {
278 return(display_interfaces(1)); 271 interface_opt_a = 1;
272 --argc;
273 ++argv;
279 } 274 }
280#endif 275#endif
281 276
277 if(argc <= 1) {
278#ifdef BB_FEATURE_IFCONFIG_STATUS
279 return display_interfaces(argc ? *argv : NULL);
280#else
281 show_usage();
282#endif
283 }
284
282 /* Create a channel to the NET kernel. */ 285 /* Create a channel to the NET kernel. */
283 if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { 286 if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
284 perror_msg_and_die("socket"); 287 perror_msg_and_die("socket");