1 /* vi: set sw=4 ts=4: */
3 * stolen from net-tools-1.59 and stripped down for busybox by
4 * Erik Andersen <andersen@codepoet.org>
6 * Heavily modified by Manuel Novoa III Mar 12, 2001
8 * Added print_bytes_scaled function to reduce code size.
9 * Added some (potentially) missing defines.
10 * Improved display support for -a and for a named interface.
12 * -----------------------------------------------------------
14 * ifconfig This file contains an implementation of the command
15 * that either displays or sets the characteristics of
16 * one or more of the system's networking interfaces.
18 * Version: $Id: interface.c,v 1.25 2004/08/26 21:45:21 andersen Exp $
20 * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
21 * and others. Copyright 1993 MicroWalt Corporation
23 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
25 * Patched to support 'add' and 'del' keywords for INET(4) addresses
26 * by Mrs. Brisby <mrs.brisby@nimh.org>
28 * {1.34} - 19980630 - Arnaldo Carvalho de Melo <acme@conectiva.com.br>
29 * - gettext instead of catgets for i18n
30 * 10/1998 - Andi Kleen. Use interface list primitives.
31 * 20001008 - Bernd Eckenfels, Patch from RH for setting mtu
32 * (default AF was wrong)
35 #include "inet_common.h"
43 #include <sys/ioctl.h>
44 #include <sys/types.h>
46 #include <net/if_arp.h>
49 #ifdef CONFIG_FEATURE_IPV6
50 # define HAVE_AFINET6 1
55 #define _PATH_PROCNET_DEV "/proc/net/dev"
56 #define _PATH_PROCNET_IFINET6 "/proc/net/if_inet6"
62 * This is in linux/include/net/ipv6.h.
66 struct in6_addr ifr6_addr;
67 uint32_t ifr6_prefixlen;
68 unsigned int ifr6_ifindex;
73 #endif /* HAVE_AFINET6 */
75 /* Defines for glibc2.0 users. */
77 #define SIOCSIFTXQLEN 0x8943
78 #define SIOCGIFTXQLEN 0x8942
81 /* ifr_qlen is ifru_ivalue, but it isn't present in 2.0 kernel headers */
83 #define ifr_qlen ifr_ifru.ifru_mtu
86 #ifndef HAVE_TXQUEUELEN
87 #define HAVE_TXQUEUELEN 1
91 #define IFF_DYNAMIC 0x8000 /* dialup device with changing addresses */
94 /* This structure defines protocol families and their handlers. */
100 char *(*print) (unsigned char *);
101 char *(*sprint) (struct sockaddr *, int numeric);
102 int (*input) (int type, char *bufp, struct sockaddr *);
103 void (*herror) (char *text);
104 int (*rprint) (int options);
105 int (*rinput) (int typ, int ext, char **argv);
108 int (*getmask) (char *src, struct sockaddr * mask, char *name);
114 /* Display an Internet socket address. */
115 static char *INET_sprint(struct sockaddr *sap, int numeric)
117 static char buff[128];
119 if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
120 return safe_strncpy(buff, "[NONE SET]", sizeof(buff));
122 if (INET_rresolve(buff, sizeof(buff), (struct sockaddr_in *) sap,
123 numeric, 0xffffff00) != 0)
129 static struct aftype inet_aftype = {
131 .title = "DARPA Internet",
134 .sprint = INET_sprint,
140 /* Display an Internet socket address. */
141 /* dirty! struct sockaddr usually doesn't suffer for inet6 addresses, fst. */
142 static char *INET6_sprint(struct sockaddr *sap, int numeric)
144 static char buff[128];
146 if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
147 return safe_strncpy(buff, "[NONE SET]", sizeof(buff));
149 (buff, sizeof(buff), (struct sockaddr_in6 *) sap, numeric) != 0)
150 return safe_strncpy(buff, "[UNKNOWN]", sizeof(buff));
154 static struct aftype inet6_aftype = {
158 .alen = sizeof(struct in6_addr),
159 .sprint = INET6_sprint,
163 #endif /* HAVE_AFINET6 */
165 /* Display an UNSPEC address. */
166 static char *UNSPEC_print(unsigned char *ptr)
168 static char buff[sizeof(struct sockaddr) * 3 + 1];
173 for (i = 0; i < sizeof(struct sockaddr); i++) {
174 /* careful -- not every libc's sprintf returns # bytes written */
175 sprintf(pos, "%02X-", (*ptr++ & 0377));
178 /* Erase trailing "-". Works as long as sizeof(struct sockaddr) != 0 */
183 /* Display an UNSPEC socket address. */
184 static char *UNSPEC_sprint(struct sockaddr *sap, int numeric)
188 if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
189 return safe_strncpy(buf, "[NONE SET]", sizeof(buf));
190 return UNSPEC_print((unsigned char *)sap->sa_data);
193 static struct aftype unspec_aftype = {
194 "unspec", "UNSPEC", AF_UNSPEC, 0,
195 UNSPEC_print, UNSPEC_sprint, NULL, NULL,
199 static struct aftype * const aftypes[] = {
208 /* Check our protocol family table for this family. */
209 static struct aftype *get_afntype(int af)
211 struct aftype * const *afp;
214 while (*afp != NULL) {
215 if ((*afp)->af == af)
222 /* Check our protocol family table for this family and return its socket */
223 static int get_socket_for_af(int af)
225 struct aftype * const *afp;
228 while (*afp != NULL) {
229 if ((*afp)->af == af)
236 struct user_net_device_stats {
237 unsigned long long rx_packets; /* total packets received */
238 unsigned long long tx_packets; /* total packets transmitted */
239 unsigned long long rx_bytes; /* total bytes received */
240 unsigned long long tx_bytes; /* total bytes transmitted */
241 unsigned long rx_errors; /* bad packets received */
242 unsigned long tx_errors; /* packet transmit problems */
243 unsigned long rx_dropped; /* no space in linux buffers */
244 unsigned long tx_dropped; /* no space available in linux */
245 unsigned long rx_multicast; /* multicast packets received */
246 unsigned long rx_compressed;
247 unsigned long tx_compressed;
248 unsigned long collisions;
250 /* detailed rx_errors: */
251 unsigned long rx_length_errors;
252 unsigned long rx_over_errors; /* receiver ring buff overflow */
253 unsigned long rx_crc_errors; /* recved pkt with crc error */
254 unsigned long rx_frame_errors; /* recv'd frame alignment error */
255 unsigned long rx_fifo_errors; /* recv'r fifo overrun */
256 unsigned long rx_missed_errors; /* receiver missed packet */
257 /* detailed tx_errors */
258 unsigned long tx_aborted_errors;
259 unsigned long tx_carrier_errors;
260 unsigned long tx_fifo_errors;
261 unsigned long tx_heartbeat_errors;
262 unsigned long tx_window_errors;
266 struct interface *next, *prev;
267 char name[IFNAMSIZ]; /* interface name */
268 short type; /* if type */
269 short flags; /* various flags */
270 int metric; /* routing metric */
271 int mtu; /* MTU value */
272 int tx_queue_len; /* transmit queue length */
273 struct ifmap map; /* hardware setup */
274 struct sockaddr addr; /* IP address */
275 struct sockaddr dstaddr; /* P-P IP address */
276 struct sockaddr broadaddr; /* IP broadcast address */
277 struct sockaddr netmask; /* IP network mask */
279 char hwaddr[32]; /* HW address */
280 int statistics_valid;
281 struct user_net_device_stats stats; /* statistics */
282 int keepalive; /* keepalive value for SLIP */
283 int outfill; /* outfill value for SLIP */
287 int interface_opt_a; /* show all interfaces */
289 static struct interface *int_list, *int_last;
290 static int skfd = -1; /* generic raw socket desc. */
293 static int sockets_open(int family)
295 struct aftype * const *aft;
297 static int force = -1;
301 if (get_linux_version_code() < KERNEL_VERSION(2,1,0))
303 if (access("/proc/net", R_OK))
306 for (aft = aftypes; *aft; aft++) {
307 struct aftype *af = *aft;
308 int type = SOCK_DGRAM;
310 if (af->af == AF_UNSPEC)
312 if (family && family != af->af)
318 /* Check some /proc file first to not stress kmod */
319 if (!family && !force && af->flag_file) {
320 if (access(af->flag_file, R_OK))
323 af->fd = socket(af->af, type, 0);
328 bb_error_msg("no usable address families found");
333 #ifdef CONFIG_FEATURE_CLEAN_UP
334 static void sockets_close(void)
336 struct aftype * const *aft;
337 for (aft = aftypes; *aft != NULL; aft++) {
338 struct aftype *af = *aft;
347 /* like strcmp(), but knows about numbers */
348 except that the freshly added calls to xatoul() brf on ethernet aliases with
349 uClibc with e.g.: ife->name='lo' name='eth0:1'
350 static int nstrcmp(const char *a, const char *b)
352 const char *a_ptr = a;
353 const char *b_ptr = b;
359 if (!isdigit(*a) && isdigit(*(a+1))) {
367 if (isdigit(*a) && isdigit(*b)) {
368 return xatoul(a_ptr) > xatoul(b_ptr) ? 1 : -1;
374 static struct interface *add_interface(char *name)
376 struct interface *ife, **nextp, *new;
378 for (ife = int_last; ife; ife = ife->prev) {
379 int n = /*n*/strcmp(ife->name, name);
387 new = xzalloc(sizeof(*new));
388 safe_strncpy(new->name, name, IFNAMSIZ);
389 nextp = ife ? &ife->next : &int_list;
393 new->next->prev = new;
401 static int if_readconf(void)
409 /* SIOCGIFCONF currently seems to only work properly on AF_INET sockets
411 skfd2 = get_socket_for_af(AF_INET);
413 bb_perror_msg(("warning: no inet socket available"));
414 /* Try to soldier on with whatever socket we can get hold of. */
415 skfd2 = sockets_open(0);
422 ifc.ifc_len = sizeof(struct ifreq) * numreqs;
423 ifc.ifc_buf = xrealloc(ifc.ifc_buf, ifc.ifc_len);
425 if (ioctl(skfd2, SIOCGIFCONF, &ifc) < 0) {
426 perror("SIOCGIFCONF");
429 if (ifc.ifc_len == sizeof(struct ifreq) * numreqs) {
430 /* assume it overflowed and try again */
438 for (n = 0; n < ifc.ifc_len; n += sizeof(struct ifreq)) {
439 add_interface(ifr->ifr_name);
449 static char *get_name(char *name, char *p)
451 /* Extract <name> from nul-terminated p where p matches
452 <name>: after leading whitespace.
453 If match is not made, set name empty and return unchanged p */
454 int namestart=0, nameend=0;
455 while (isspace(p[namestart]))
458 while (p[nameend] && p[nameend]!=':' && !isspace(p[nameend]))
460 if (p[nameend]==':') {
461 if ((nameend-namestart)<IFNAMSIZ) {
462 memcpy(name,&p[namestart],nameend-namestart);
463 name[nameend-namestart]='\0';
466 /* Interface name too large */
470 /* trailing ':' not found - return empty */
476 /* If scanf supports size qualifiers for %n conversions, then we can
477 * use a modified fmt that simply stores the position in the fields
478 * having no associated fields in the proc string. Of course, we need
479 * to zero them again when we're done. But that is smaller than the
480 * old approach of multiple scanf occurrences with large numbers of
483 /* static const char * const ss_fmt[] = { */
484 /* "%lln%llu%lu%lu%lu%lu%ln%ln%lln%llu%lu%lu%lu%lu%lu", */
485 /* "%llu%llu%lu%lu%lu%lu%ln%ln%llu%llu%lu%lu%lu%lu%lu", */
486 /* "%llu%llu%lu%lu%lu%lu%lu%lu%llu%llu%lu%lu%lu%lu%lu%lu" */
489 /* Lie about the size of the int pointed to for %n. */
490 #if INT_MAX == LONG_MAX
491 static const char * const ss_fmt[] = {
492 "%n%llu%u%u%u%u%n%n%n%llu%u%u%u%u%u",
493 "%llu%llu%u%u%u%u%n%n%llu%llu%u%u%u%u%u",
494 "%llu%llu%u%u%u%u%u%u%llu%llu%u%u%u%u%u%u"
497 static const char * const ss_fmt[] = {
498 "%n%llu%lu%lu%lu%lu%n%n%n%llu%lu%lu%lu%lu%lu",
499 "%llu%llu%lu%lu%lu%lu%n%n%llu%llu%lu%lu%lu%lu%lu",
500 "%llu%llu%lu%lu%lu%lu%lu%lu%llu%llu%lu%lu%lu%lu%lu%lu"
505 static void get_dev_fields(char *bp, struct interface *ife, int procnetdev_vsn)
507 memset(&ife->stats, 0, sizeof(struct user_net_device_stats));
509 sscanf(bp, ss_fmt[procnetdev_vsn],
510 &ife->stats.rx_bytes, /* missing for 0 */
511 &ife->stats.rx_packets,
512 &ife->stats.rx_errors,
513 &ife->stats.rx_dropped,
514 &ife->stats.rx_fifo_errors,
515 &ife->stats.rx_frame_errors,
516 &ife->stats.rx_compressed, /* missing for <= 1 */
517 &ife->stats.rx_multicast, /* missing for <= 1 */
518 &ife->stats.tx_bytes, /* missing for 0 */
519 &ife->stats.tx_packets,
520 &ife->stats.tx_errors,
521 &ife->stats.tx_dropped,
522 &ife->stats.tx_fifo_errors,
523 &ife->stats.collisions,
524 &ife->stats.tx_carrier_errors,
525 &ife->stats.tx_compressed /* missing for <= 1 */
528 if (procnetdev_vsn <= 1) {
529 if (procnetdev_vsn == 0) {
530 ife->stats.rx_bytes = 0;
531 ife->stats.tx_bytes = 0;
533 ife->stats.rx_multicast = 0;
534 ife->stats.rx_compressed = 0;
535 ife->stats.tx_compressed = 0;
539 static inline int procnetdev_version(char *buf)
541 if (strstr(buf, "compressed"))
543 if (strstr(buf, "bytes"))
548 static int if_readlist_proc(char *target)
550 static int proc_read;
553 struct interface *ife;
554 int err, procnetdev_vsn;
561 fh = fopen(_PATH_PROCNET_DEV, "r");
563 bb_perror_msg("warning: cannot open %s, limiting output", _PATH_PROCNET_DEV);
564 return if_readconf();
566 fgets(buf, sizeof buf, fh); /* eat line */
567 fgets(buf, sizeof buf, fh);
569 procnetdev_vsn = procnetdev_version(buf);
572 while (fgets(buf, sizeof buf, fh)) {
575 s = get_name(name, buf);
576 ife = add_interface(name);
577 get_dev_fields(s, ife, procnetdev_vsn);
578 ife->statistics_valid = 1;
579 if (target && !strcmp(target, name))
583 perror(_PATH_PROCNET_DEV);
591 static int if_readlist(void)
593 int err = if_readlist_proc(NULL);
600 static int for_all_interfaces(int (*doit) (struct interface *, void *),
603 struct interface *ife;
605 if (!int_list && (if_readlist() < 0))
607 for (ife = int_list; ife; ife = ife->next) {
608 int err = doit(ife, cookie);
616 /* Fetch the interface configuration from the kernel. */
617 static int if_fetch(struct interface *ife)
621 char *ifname = ife->name;
623 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
624 if (ioctl(skfd, SIOCGIFFLAGS, &ifr) < 0)
626 ife->flags = ifr.ifr_flags;
628 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
629 if (ioctl(skfd, SIOCGIFHWADDR, &ifr) < 0)
630 memset(ife->hwaddr, 0, 32);
632 memcpy(ife->hwaddr, ifr.ifr_hwaddr.sa_data, 8);
634 ife->type = ifr.ifr_hwaddr.sa_family;
636 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
637 if (ioctl(skfd, SIOCGIFMETRIC, &ifr) < 0)
640 ife->metric = ifr.ifr_metric;
642 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
643 if (ioctl(skfd, SIOCGIFMTU, &ifr) < 0)
646 ife->mtu = ifr.ifr_mtu;
649 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
650 if (ioctl(skfd, SIOCGIFMAP, &ifr) == 0)
651 ife->map = ifr.ifr_map;
654 memset(&ife->map, 0, sizeof(struct ifmap));
656 #ifdef HAVE_TXQUEUELEN
657 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
658 if (ioctl(skfd, SIOCGIFTXQLEN, &ifr) < 0)
659 ife->tx_queue_len = -1; /* unknown value */
661 ife->tx_queue_len = ifr.ifr_qlen;
663 ife->tx_queue_len = -1; /* unknown value */
667 fd = get_socket_for_af(AF_INET);
669 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
670 ifr.ifr_addr.sa_family = AF_INET;
671 if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) {
673 ife->addr = ifr.ifr_addr;
674 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
675 if (ioctl(fd, SIOCGIFDSTADDR, &ifr) < 0)
676 memset(&ife->dstaddr, 0, sizeof(struct sockaddr));
678 ife->dstaddr = ifr.ifr_dstaddr;
680 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
681 if (ioctl(fd, SIOCGIFBRDADDR, &ifr) < 0)
682 memset(&ife->broadaddr, 0, sizeof(struct sockaddr));
684 ife->broadaddr = ifr.ifr_broadaddr;
686 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
687 if (ioctl(fd, SIOCGIFNETMASK, &ifr) < 0)
688 memset(&ife->netmask, 0, sizeof(struct sockaddr));
690 ife->netmask = ifr.ifr_netmask;
692 memset(&ife->addr, 0, sizeof(struct sockaddr));
699 static int do_if_fetch(struct interface *ife)
701 if (if_fetch(ife) < 0) {
704 if (errno == ENODEV) {
705 /* Give better error message for this case. */
706 errmsg = "Device not found";
708 errmsg = strerror(errno);
710 bb_error_msg("%s: error fetching interface information: %s",
717 /* This structure defines hardware protocols and their handlers. */
719 const char * const name;
723 char *(*print) (unsigned char *);
724 int (*input) (char *, struct sockaddr *);
725 int (*activate) (int fd);
726 int suppress_null_addr;
729 static const struct hwtype unspec_hwtype = {
733 .print = UNSPEC_print
736 static const struct hwtype loop_hwtype = {
738 .title = "Local Loopback",
739 .type = ARPHRD_LOOPBACK
742 #include <net/if_arp.h>
744 #if (defined(__GLIBC__) && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1) || defined(_NEWLIB_VERSION)
745 #include <net/ethernet.h>
747 #include <linux/if_ether.h>
750 /* Display an Ethernet address in readable format. */
751 static char *pr_ether(unsigned char *ptr)
753 static char buff[64];
755 snprintf(buff, sizeof(buff), "%02X:%02X:%02X:%02X:%02X:%02X",
756 (ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377),
757 (ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377)
762 static const struct hwtype ether_hwtype = {
765 .type = ARPHRD_ETHER,
770 #include <net/if_arp.h>
772 static const struct hwtype ppp_hwtype = {
774 .title = "Point-to-Point Protocol",
778 #ifdef CONFIG_FEATURE_IPV6
779 static const struct hwtype sit_hwtype = {
781 .title = "IPv6-in-IPv4",
783 .print = UNSPEC_print,
784 .suppress_null_addr = 1
788 static const struct hwtype * const hwtypes[] = {
793 #ifdef CONFIG_FEATURE_IPV6
800 static const char * const if_port_text[] = {
801 /* Keep in step with <linux/netdevice.h> */
813 /* Check our hardware type table for this type. */
814 static const struct hwtype *get_hwntype(int type)
816 const struct hwtype * const *hwp;
819 while (*hwp != NULL) {
820 if ((*hwp)->type == type)
827 /* return 1 if address is all zeros */
828 static int hw_null_address(const struct hwtype *hw, void *ap)
831 unsigned char *address = (unsigned char *) ap;
833 for (i = 0; i < hw->alen; i++)
839 static const char TRext[] = "\0\0\0Ki\0Mi\0Gi\0Ti";
841 static void print_bytes_scaled(unsigned long long ull, const char *end)
843 unsigned long long int_part;
845 unsigned int frac_part;
853 if (int_part >= 1024) {
854 frac_part = ((((unsigned int) int_part) & (1024-1)) * 10) / 1024;
856 ext += 3; /* KiB, MiB, GiB, TiB */
861 printf("X bytes:%llu (%llu.%u %sB)%s", ull, int_part, frac_part, ext, end);
864 static const char * const ife_print_flags_strs[] = {
883 static const unsigned short ife_print_flags_mask[] = {
903 static void ife_print(struct interface *ptr)
906 const struct hwtype *hw;
908 int can_compress = 0;
912 char addr6[40], devname[20];
913 struct sockaddr_in6 sap;
914 int plen, scope, dad_status, if_idx;
918 ap = get_afntype(ptr->addr.sa_family);
924 if (hf == ARPHRD_CSLIP || hf == ARPHRD_CSLIP6)
927 hw = get_hwntype(hf);
929 hw = get_hwntype(-1);
931 printf("%-9.9s Link encap:%s ", ptr->name, hw->title);
932 /* For some hardware types (eg Ash, ATM) we don't print the
933 hardware address if it's null. */
934 if (hw->print != NULL && (!(hw_null_address(hw, ptr->hwaddr) &&
935 hw->suppress_null_addr)))
936 printf("HWaddr %s ", hw->print((unsigned char *)ptr->hwaddr));
938 if (ptr->flags & IFF_PORTSEL) {
939 printf("Media:%s", if_port_text[ptr->map.port] /* [0] */);
940 if (ptr->flags & IFF_AUTOMEDIA)
947 printf(" %s addr:%s ", ap->name,
948 ap->sprint(&ptr->addr, 1));
949 if (ptr->flags & IFF_POINTOPOINT) {
950 printf(" P-t-P:%s ", ap->sprint(&ptr->dstaddr, 1));
952 if (ptr->flags & IFF_BROADCAST) {
953 printf(" Bcast:%s ", ap->sprint(&ptr->broadaddr, 1));
955 printf(" Mask:%s\n", ap->sprint(&ptr->netmask, 1));
960 #define IPV6_ADDR_ANY 0x0000U
962 #define IPV6_ADDR_UNICAST 0x0001U
963 #define IPV6_ADDR_MULTICAST 0x0002U
964 #define IPV6_ADDR_ANYCAST 0x0004U
966 #define IPV6_ADDR_LOOPBACK 0x0010U
967 #define IPV6_ADDR_LINKLOCAL 0x0020U
968 #define IPV6_ADDR_SITELOCAL 0x0040U
970 #define IPV6_ADDR_COMPATv4 0x0080U
972 #define IPV6_ADDR_SCOPE_MASK 0x00f0U
974 #define IPV6_ADDR_MAPPED 0x1000U
975 #define IPV6_ADDR_RESERVED 0x2000U /* reserved address space */
977 if ((f = fopen(_PATH_PROCNET_IFINET6, "r")) != NULL) {
979 (f, "%4s%4s%4s%4s%4s%4s%4s%4s %02x %02x %02x %02x %20s\n",
980 addr6p[0], addr6p[1], addr6p[2], addr6p[3], addr6p[4],
981 addr6p[5], addr6p[6], addr6p[7], &if_idx, &plen, &scope,
982 &dad_status, devname) != EOF) {
983 if (!strcmp(devname, ptr->name)) {
984 sprintf(addr6, "%s:%s:%s:%s:%s:%s:%s:%s",
985 addr6p[0], addr6p[1], addr6p[2], addr6p[3],
986 addr6p[4], addr6p[5], addr6p[6], addr6p[7]);
987 inet_pton(AF_INET6, addr6,
988 (struct sockaddr *) &sap.sin6_addr);
989 sap.sin6_family = AF_INET6;
990 printf(" inet6 addr: %s/%d",
991 inet6_aftype.sprint((struct sockaddr *) &sap, 1),
994 switch (scope & IPV6_ADDR_SCOPE_MASK) {
998 case IPV6_ADDR_LINKLOCAL:
1001 case IPV6_ADDR_SITELOCAL:
1004 case IPV6_ADDR_COMPATv4:
1007 case IPV6_ADDR_LOOPBACK:
1021 /* DONT FORGET TO ADD THE FLAGS IN ife_print_short, too */
1023 if (ptr->flags == 0) {
1024 printf("[NO FLAGS] ");
1028 if (ptr->flags & ife_print_flags_mask[i]) {
1029 printf(ife_print_flags_strs[i]);
1031 } while (ife_print_flags_mask[++i]);
1034 /* DONT FORGET TO ADD THE FLAGS IN ife_print_short */
1035 printf(" MTU:%d Metric:%d", ptr->mtu, ptr->metric ? ptr->metric : 1);
1036 #ifdef SIOCSKEEPALIVE
1037 if (ptr->outfill || ptr->keepalive)
1038 printf(" Outfill:%d Keepalive:%d", ptr->outfill, ptr->keepalive);
1042 /* If needed, display the interface statistics. */
1044 if (ptr->statistics_valid) {
1045 /* XXX: statistics are currently only printed for the primary address,
1046 * not for the aliases, although strictly speaking they're shared
1051 printf("RX packets:%llu errors:%lu dropped:%lu overruns:%lu frame:%lu\n",
1052 ptr->stats.rx_packets, ptr->stats.rx_errors,
1053 ptr->stats.rx_dropped, ptr->stats.rx_fifo_errors,
1054 ptr->stats.rx_frame_errors);
1056 printf(" compressed:%lu\n",
1057 ptr->stats.rx_compressed);
1059 printf("TX packets:%llu errors:%lu dropped:%lu overruns:%lu carrier:%lu\n",
1060 ptr->stats.tx_packets, ptr->stats.tx_errors,
1061 ptr->stats.tx_dropped, ptr->stats.tx_fifo_errors,
1062 ptr->stats.tx_carrier_errors);
1063 printf(" collisions:%lu ", ptr->stats.collisions);
1065 printf("compressed:%lu ", ptr->stats.tx_compressed);
1066 if (ptr->tx_queue_len != -1)
1067 printf("txqueuelen:%d ", ptr->tx_queue_len);
1069 print_bytes_scaled(ptr->stats.rx_bytes, " T");
1070 print_bytes_scaled(ptr->stats.tx_bytes, "\n");
1074 if ((ptr->map.irq || ptr->map.mem_start || ptr->map.dma ||
1075 ptr->map.base_addr)) {
1078 printf("Interrupt:%d ", ptr->map.irq);
1079 if (ptr->map.base_addr >= 0x100) /* Only print devices using it for
1081 printf("Base address:0x%lx ",
1082 (unsigned long) ptr->map.base_addr);
1083 if (ptr->map.mem_start) {
1084 printf("Memory:%lx-%lx ", ptr->map.mem_start,
1088 printf("DMA chan:%x ", ptr->map.dma);
1095 static int do_if_print(struct interface *ife, void *cookie)
1097 int *opt_a = (int *) cookie;
1100 res = do_if_fetch(ife);
1102 if ((ife->flags & IFF_UP) || *opt_a)
1108 static struct interface *lookup_interface(char *name)
1110 struct interface *ife = NULL;
1112 if (if_readlist_proc(name) < 0)
1114 ife = add_interface(name);
1118 /* for ipv4 add/del modes */
1119 static int if_print(char *ifname)
1124 res = for_all_interfaces(do_if_print, &interface_opt_a);
1126 struct interface *ife;
1128 ife = lookup_interface(ifname);
1129 res = do_if_fetch(ife);
1136 int display_interfaces(char *ifname)
1140 /* Create a channel to the NET kernel. */
1141 if ((skfd = sockets_open(0)) < 0) {
1142 bb_perror_msg_and_die("socket");
1145 /* Do we have to show the current setup? */
1146 status = if_print(ifname);
1147 #ifdef CONFIG_FEATURE_CLEAN_UP