*
* displayroute() code added by Vladimir N. Oleynik <dzo@simtreas.ru>
* adjustments by Larry Doolittle <LRDoolittle@lbl.gov>
*
* displayroute() code added by Vladimir N. Oleynik <dzo@simtreas.ru>
* adjustments by Larry Doolittle <LRDoolittle@lbl.gov>
/* For the various tbl_*[] arrays, the 1st byte is the offset to
* the next entry and the 2nd byte is return value. */
/* For the various tbl_*[] arrays, the 1st byte is the offset to
* the next entry and the 2nd byte is return value. */
-#define KW_IPVx_METRIC 020
-#define KW_IPVx_NETMASK 021
-#define KW_IPVx_GATEWAY 022
-#define KW_IPVx_MSS 023
-#define KW_IPVx_WINDOW 024
-#define KW_IPVx_IRTT 025
-#define KW_IPVx_DEVICE 026
+#define KW_IPVx_METRIC 020
+#define KW_IPVx_NETMASK 021
+#define KW_IPVx_GATEWAY 022
+#define KW_IPVx_MSS 023
+#define KW_IPVx_WINDOW 024
+#define KW_IPVx_IRTT 025
+#define KW_IPVx_DEVICE 026
-#define KW_IPVx_FLAG_ONLY 040
-#define KW_IPVx_REJECT 040
-#define KW_IPVx_MOD 041
-#define KW_IPVx_DYN 042
-#define KW_IPVx_REINSTATE 043
+#define KW_IPVx_FLAG_ONLY 040
+#define KW_IPVx_REJECT 040
+#define KW_IPVx_MOD 041
+#define KW_IPVx_DYN 042
+#define KW_IPVx_REINSTATE 043
/* recognize x.x.x.x/mask format. */
prefix = strchr(target, '/');
/* recognize x.x.x.x/mask format. */
prefix = strchr(target, '/');
}
/* Prefer hostname lookup is -host flag (xflag==1) was given. */
isnet = INET_resolve(target, (struct sockaddr_in *) &rt.rt_dst,
}
/* Prefer hostname lookup is -host flag (xflag==1) was given. */
isnet = INET_resolve(target, (struct sockaddr_in *) &rt.rt_dst,
/* Create a socket to the INET kernel. */
skfd = xsocket(AF_INET, SOCK_DGRAM, 0);
/* Create a socket to the INET kernel. */
skfd = xsocket(AF_INET, SOCK_DGRAM, 0);
- if (ioctl(skfd, ((action==RTACTION_ADD) ? SIOCADDRT : SIOCDELRT), &rt)<0) {
- bb_perror_msg_and_die("SIOC[ADD|DEL]RT");
- }
+ if (action == RTACTION_ADD)
+ xioctl(skfd, SIOCADDRT, &rt);
+ else
+ xioctl(skfd, SIOCDELRT, &rt);
- if ((cp = strchr(target, '/'))) { /* Yes... const to non is ok. */
- *cp = 0;
- prefix_len = xatoul_range(cp+1, 0, 128);
+ cp = strchr(target, '/'); /* Yes... const to non is ok. */
+ if (cp) {
+ *cp = '\0';
+ prefix_len = xatoul_range(cp + 1, 0, 128);
- strcpy(ifr.ifr_name, devname);
-
- if (ioctl(skfd, SIOGIFINDEX, &ifr) < 0) {
- bb_perror_msg_and_die("SIOGIFINDEX");
- }
+ strncpy(ifr.ifr_name, devname, sizeof(ifr.ifr_name));
+ xioctl(skfd, SIOGIFINDEX, &ifr);
- if (ioctl(skfd, ((action==RTACTION_ADD) ? SIOCADDRT : SIOCDELRT), &rt)<0) {
- bb_perror_msg_and_die("SIOC[ADD|DEL]RT");
- }
+ if (action == RTACTION_ADD)
+ xioctl(skfd, SIOCADDRT, &rt);
+ else
+ xioctl(skfd, SIOCDELRT, &rt);
#define IPV4_MASK (RTF_GATEWAY|RTF_HOST|RTF_REINSTATE|RTF_DYNAMIC|RTF_MODIFIED)
#define IPV6_MASK (RTF_GATEWAY|RTF_HOST|RTF_DEFAULT|RTF_ADDRCONF|RTF_CACHE)
#define IPV4_MASK (RTF_GATEWAY|RTF_HOST|RTF_REINSTATE|RTF_DYNAMIC|RTF_MODIFIED)
#define IPV6_MASK (RTF_GATEWAY|RTF_HOST|RTF_DEFAULT|RTF_ADDRCONF|RTF_CACHE)
-void displayroutes(int noresolve, int netstatfmt);
-void displayroutes(int noresolve, int netstatfmt)
+void FAST_FUNC bb_displayroutes(int noresolve, int netstatfmt)
- char devname[64], flags[16], sdest[16], sgw[16];
- unsigned long int d, g, m;
+ char devname[64], flags[16], *sdest, *sgw;
+ unsigned long d, g, m;
int flgs, ref, use, metric, mtu, win, ir;
struct sockaddr_in s_addr;
struct in_addr mask;
int flgs, ref, use, metric, mtu, win, ir;
struct sockaddr_in s_addr;
struct in_addr mask;
FILE *fp = xfopen("/proc/net/route", "r");
printf("Kernel IP routing table\n"
FILE *fp = xfopen("/proc/net/route", "r");
printf("Kernel IP routing table\n"
- "Destination Gateway Genmask"
- " Flags %s Iface\n",
- netstatfmt ? " MSS Window irtt" : "Metric Ref Use");
+ "Destination Gateway Genmask Flags %s Iface\n",
+ netstatfmt ? " MSS Window irtt" : "Metric Ref Use");
if (fscanf(fp, "%*[^\n]\n") < 0) { /* Skip the first line. */
goto ERROR; /* Empty or missing line, or read error. */
if (fscanf(fp, "%*[^\n]\n") < 0) { /* Skip the first line. */
goto ERROR; /* Empty or missing line, or read error. */
memset(&s_addr, 0, sizeof(struct sockaddr_in));
s_addr.sin_family = AF_INET;
s_addr.sin_addr.s_addr = d;
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 *. */
-
+ sdest = INET_rresolve(&s_addr, (noresolve | 0x8000), m); /* 'default' instead of '*' */
- INET_rresolve(sgw, sizeof(sgw), &s_addr,
- (noresolve | 0x4000), m); /* Host instead of net. */
-
+ sgw = INET_rresolve(&s_addr, (noresolve | 0x4000), m); /* Host instead of net */
- printf("%-16s%-16s%-16s%-6s", sdest, sgw, inet_ntoa(mask), flags);
+ /* "%15.15s" truncates hostnames, do we really want that? */
+ printf("%-15.15s %-15.15s %-16s%-6s", sdest, sgw, inet_ntoa(mask), flags);
+ free(sdest);
+ free(sgw);
if (netstatfmt) {
printf("%5d %-5d %6d %s\n", mtu, win, ir, devname);
} else {
if (netstatfmt) {
printf("%5d %-5d %6d %s\n", mtu, win, ir, devname);
} else {
/* 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
/* 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
inet_pton(AF_INET6, addr6x + r,
(struct sockaddr *) &snaddr6.sin6_addr);
snaddr6.sin6_family = AF_INET6;
inet_pton(AF_INET6, addr6x + r,
(struct sockaddr *) &snaddr6.sin6_addr);
snaddr6.sin6_family = AF_INET6;
- INET6_rresolve(naddr6, sizeof(naddr6),
- (struct sockaddr_in6 *) &snaddr6,
+ naddr6 = INET6_rresolve((struct sockaddr_in6 *) &snaddr6,
0x0fff /* Apparently, upstream never resolves. */
);
if (!r) { /* 1st pass */
snprintf(addr6, sizeof(addr6), "%s/%d", naddr6, prefix_len);
r += 40;
0x0fff /* Apparently, upstream never resolves. */
);
if (!r) { /* 1st pass */
snprintf(addr6, sizeof(addr6), "%s/%d", naddr6, prefix_len);
r += 40;
- addr6, naddr6, flags, metric, refcnt, use, iface);
+ addr6, naddr6, flags, metric, refcnt, use, iface);
+ free(naddr6);
-#define ROUTE_OPT_A 0x01
-#define ROUTE_OPT_n 0x02
-#define ROUTE_OPT_e 0x04
-#define ROUTE_OPT_INET6 0x08 /* Not an actual option. See below. */
+#define ROUTE_OPT_A 0x01
+#define ROUTE_OPT_n 0x02
+#define ROUTE_OPT_e 0x04
+#define ROUTE_OPT_INET6 0x08 /* Not an actual option. See below. */
-int route_main(int argc, char **argv)
+int route_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int route_main(int argc ATTRIBUTE_UNUSED, char **argv)
if (strcmp(family, "inet6") == 0) {
opt |= ROUTE_OPT_INET6; /* Set flag for ipv6. */
} else
if (strcmp(family, "inet6") == 0) {
opt |= ROUTE_OPT_INET6; /* Set flag for ipv6. */
} else
/* No more args means display the routing table. */
if (!*argv) {
int noresolve = (opt & ROUTE_OPT_n) ? 0x0fff : 0;
/* No more args means display the routing table. */
if (!*argv) {
int noresolve = (opt & ROUTE_OPT_n) ? 0x0fff : 0;
if (opt & ROUTE_OPT_INET6)
INET6_setroute(what, argv);
else
if (opt & ROUTE_OPT_INET6)
INET6_setroute(what, argv);
else