- while( fgets(buff, sizeof(buff), fp) != NULL ) {
- if(nl) {
- int ifl = 0;
- while(buff[ifl]!=' ' && buff[ifl]!='\t' && buff[ifl]!='\0')
- ifl++;
- buff[ifl]=0; /* interface */
- if(sscanf(buff+ifl+1, "%lx%lx%X%d%d%d%lx",
- &d, &g, &flgs, &ref, &use, &metric, &m)!=7) {
- error_msg_and_die( "Unsuported kernel route format\n");
+ if (!(flgs & RTF_UP)) { /* Skip interfaces that are down. */
+ continue;
+ }
+
+ set_flags(flags, (flgs & IPV4_MASK));
+#ifdef RTF_REJECT
+ if (flgs & RTF_REJECT) {
+ flags[0] = '!';
+ }
+#endif
+
+ memset(&s_addr, 0, sizeof(struct sockaddr_in));
+ s_addr.sin_family = AF_INET;
+ s_addr.sin_addr.s_addr = d;
+ INET_rresolve(sdest, sizeof(sdest), &s_addr,
+ (noresolve | 0x8000), m); /* Default instead of *. */
+
+ s_addr.sin_addr.s_addr = g;
+ INET_rresolve(sgw, sizeof(sgw), &s_addr,
+ (noresolve | 0x4000), m); /* Host instead of net. */
+
+ mask.s_addr = m;
+ bb_printf("%-16s%-16s%-16s%-6s", sdest, sgw, inet_ntoa(mask), flags);
+ if (netstatfmt) {
+ bb_printf("%5d %-5d %6d %s\n", mtu, win, ir, devname);
+ } else {
+ bb_printf("%-6d %-2d %7d %s\n", metric, ref, use, devname);
+ }
+ }
+}
+
+#ifdef CONFIG_FEATURE_IPV6
+
+static void INET6_displayroutes(int noresolve)
+{
+ char addr6[128], naddr6[128];
+ /* In addr6x, we store both 40-byte ':'-delimited ipv6 addresses.
+ * We read the non-delimited strings into the tail of the buffer
+ * using fscanf and then modify the buffer by shifting forward
+ * while inserting ':'s and the nul terminator for the first string.
+ * Hence the strings are at addr6x and addr6x+40. This generates
+ * _much_ less code than the previous (upstream) approach. */
+ char addr6x[80];
+ char iface[16], flags[16];
+ int iflags, metric, refcnt, use, prefix_len, slen;
+ struct sockaddr_in6 snaddr6;
+
+ FILE *fp = bb_xfopen("/proc/net/ipv6_route", "r");
+
+ bb_printf("Kernel IPv6 routing table\n%-44s%-40s"
+ "Flags Metric Ref Use Iface\n",
+ "Destination", "Next Hop");
+
+ while (1) {
+ int r;
+ r = fscanf(fp, "%32s%x%*s%x%32s%x%x%x%x%s\n",
+ addr6x+14, &prefix_len, &slen, addr6x+40+7,
+ &metric, &use, &refcnt, &iflags, iface);
+ if (r != 9) {
+ if ((r < 0) && feof(fp)) { /* EOF with no (nonspace) chars read. */
+ break;