/*
- * Copyright (c) 2008 Apple Inc. All rights reserved.
+ * Copyright (c) 2008-2017 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
{ RTF_BLACKHOLE,'B' },
{ RTF_BROADCAST,'b' },
{ RTF_IFSCOPE, 'I' },
-#ifdef RTF_IFREF
{ RTF_IFREF, 'i' },
-#endif /* RTF_IFREF */
+ { RTF_PROXY, 'Y' },
+ { RTF_ROUTER, 'r' },
{ 0 }
};
u_short u_data[128];
} sa_u;
-static void ntreestuff __P((void));
static void np_rtentry __P((struct rt_msghdr2 *));
static void p_sockaddr __P((struct sockaddr *, struct sockaddr *, int, int));
static void p_flags __P((int, char *));
static uint32_t forgemask __P((uint32_t));
static void domask __P((char *, uint32_t, uint32_t));
-/*
- * Print routing tables.
- */
-void
-routepr(uint32_t rtree)
-{
- printf("Routing tables\n");
-
- if (dflag == 0) {
- ntreestuff();
- } else {
- if (rtree == 0) {
- printf("rt_tables: symbol not in namelist\n");
- return;
- }
- }
- }
-
/*
* Print address family header before a section of the routing table.
*/
if (Aflag)
printf("%-8.8s ","Address");
- if (af == AF_INET || lflag)
- if (lflag)
+ if (af == AF_INET || lflag) {
+ if (lflag > 2)
+ printf("%-*.*s %-*.*s %-10.10s %6.6s %8.8s %6.6s %*.*s %6s "
+ "%10s %10s %8s %8s %8s\n",
+ WID_DST(af), WID_DST(af), "Destination",
+ WID_GW(af), WID_GW(af), "Gateway",
+ "Flags", "Refs", "Use", "Mtu",
+ WID_IF(af), WID_IF(af), "Netif", "Expire",
+ "rtt(ns)", "rttvar(ns)", "recvpipe", "sendpipe", "ssthresh");
+ else if (lflag > 1)
+ printf("%-*.*s %-*.*s %-10.10s %6.6s %8.8s %6.6s %*.*s %6s "
+ "%10s %10s\n",
+ WID_DST(af), WID_DST(af), "Destination",
+ WID_GW(af), WID_GW(af), "Gateway",
+ "Flags", "Refs", "Use", "Mtu",
+ WID_IF(af), WID_IF(af), "Netif", "Expire",
+ "rtt(ns)", "rttvar(ns)");
+ else if (lflag == 1)
printf("%-*.*s %-*.*s %-10.10s %6.6s %8.8s %6.6s %*.*s %6s\n",
WID_DST(af), WID_DST(af), "Destination",
WID_GW(af), WID_GW(af), "Gateway",
WID_GW(af), WID_GW(af), "Gateway",
"Flags", "Refs", "Use",
WID_IF(af), WID_IF(af), "Netif", "Expire");
- else
+ } else {
printf("%-*.*s %-*.*s %-10.10s %8.8s %6s\n",
WID_DST(af), WID_DST(af), "Destination",
WID_GW(af), WID_GW(af), "Gateway",
"Flags", "Netif", "Expire");
}
+}
-static void
-ntreestuff(void)
+/*
+ * Print routing tables.
+ */
+void
+routepr(void)
{
size_t needed;
int mib[6];
char *buf, *next, *lim;
struct rt_msghdr2 *rtm;
+ printf("Routing tables\n");
+
mib[0] = CTL_NET;
mib[1] = PF_ROUTE;
mib[2] = 0;
return;
}
+ if (lflag > 1 && zflag != 0 && rtm->rtm_rmx.rmx_rtt == 0 && rtm->rtm_rmx.rmx_rttvar == 0)
+ return;
fam = sa->sa_family;
if (af != AF_UNSPEC && af != fam)
return;
if ((expire_time =
rtm->rtm_rmx.rmx_expire - time((time_t *)0)) > 0)
printf(" %6d", (int)expire_time);
+ else
+ printf(" %6s", "!");
+ } else {
+ printf(" %6s", "");
+ }
+ if (lflag > 1) {
+ if (rtm->rtm_rmx.rmx_rtt != 0)
+ printf(" %6u.%03u", rtm->rtm_rmx.rmx_rtt / 1000,
+ rtm->rtm_rmx.rmx_rtt % 1000);
+ else
+ printf(" %10s", "");
+ if (rtm->rtm_rmx.rmx_rttvar != 0)
+ printf(" %6u.%03u", rtm->rtm_rmx.rmx_rttvar / 1000,
+ rtm->rtm_rmx.rmx_rttvar % 1000);
+ else
+ printf(" %10s", "");
+ if (lflag > 2) {
+ if (rtm->rtm_rmx.rmx_recvpipe != 0)
+ printf(" %8u", rtm->rtm_rmx.rmx_recvpipe);
+ else
+ printf(" %8s", "");
+ if (rtm->rtm_rmx.rmx_sendpipe != 0)
+ printf(" %8u", rtm->rtm_rmx.rmx_sendpipe);
+ else
+ printf(" %8s", "");
+ if (rtm->rtm_rmx.rmx_ssthresh != 0)
+ printf(" %8u", rtm->rtm_rmx.rmx_ssthresh);
+ else
+ printf(" %8s", "");
+ }
}
putchar('\n');
}
* sin6_scope_id field of SA should be set in the future.
*/
if (IN6_IS_ADDR_LINKLOCAL(in6) ||
+ IN6_IS_ADDR_MC_NODELOCAL(in6) ||
IN6_IS_ADDR_MC_LINKLOCAL(in6)) {
/* XXX: override is ok? */
sa6->sin6_scope_id = (u_int32_t)ntohs(*(u_short *)&in6->s6_addr[2]);
if (sdl->sdl_nlen == 0 && sdl->sdl_alen == 0 &&
sdl->sdl_slen == 0) {
- (void) sprintf(workbuf, "link#%d", sdl->sdl_index);
+ (void) snprintf(workbuf, sizeof(workbuf), "link#%d", sdl->sdl_index);
} else {
switch (sdl->sdl_type) {
cplim = "";
for (i = 0; i < sdl->sdl_alen; i++, lla++) {
- cp += sprintf(cp, "%s%x", cplim, *lla);
+ cp += snprintf(cp, sizeof(workbuf) - (cp - workbuf), "%s%x", cplim, *lla);
cplim = ":";
}
cp = workbuf;
slim = sa->sa_len + (u_char *) sa;
cplim = cp + sizeof(workbuf) - 6;
- cp += sprintf(cp, "(%d)", sa->sa_family);
+ cp += snprintf(cp, sizeof(workbuf) - (cp - workbuf), "(%d)", sa->sa_family);
while (s < slim && cp < cplim) {
- cp += sprintf(cp, " %02x", *s++);
+ cp += snprintf(cp, sizeof(workbuf) - (cp - workbuf), " %02x", *s++);
if (s < slim)
- cp += sprintf(cp, "%02x", *s++);
+ cp += snprintf(cp, sizeof(workbuf) - (cp - workbuf), "%02x", *s++);
}
cp = workbuf;
}
} else {
#define C(x) ((x) & 0xff)
in = ntohl(in);
- sprintf(line, "%u.%u.%u.%u",
+ snprintf(line, sizeof(line), "%u.%u.%u.%u",
C(in >> 24), C(in >> 16), C(in >> 8), C(in));
}
return (line);
break;
}
if (i == -1)
- sprintf(dst, "&0x%x", mask);
+ snprintf(dst, sizeof(dst), "&0x%x", mask);
else
- sprintf(dst, "/%d", 32-i);
+ snprintf(dst, sizeof(dst), "/%d", 32-i);
}
/*
switch (dmask) {
case IN_CLASSA_NET:
if ((i & IN_CLASSA_HOST) == 0) {
- sprintf(line, "%u", C(i >> 24));
+ snprintf(line, sizeof(line), "%u", C(i >> 24));
break;
}
/* FALLTHROUGH */
case IN_CLASSB_NET:
if ((i & IN_CLASSB_HOST) == 0) {
- sprintf(line, "%u.%u",
+ snprintf(line, sizeof(line), "%u.%u",
C(i >> 24), C(i >> 16));
break;
}
/* FALLTHROUGH */
case IN_CLASSC_NET:
if ((i & IN_CLASSC_HOST) == 0) {
- sprintf(line, "%u.%u.%u",
+ snprintf(line, sizeof(line), "%u.%u.%u",
C(i >> 24), C(i >> 16), C(i >> 8));
break;
}
/* FALLTHROUGH */
default:
- sprintf(line, "%u.%u.%u.%u",
+ snprintf(line, sizeof(line), "%u.%u.%u.%u",
C(i >> 24), C(i >> 16), C(i >> 8), C(i));
break;
}
NULL, 0, flag);
if (nflag)
- sprintf(&line[strlen(line)], "/%d", masklen);
+ snprintf(&line[strlen(line)], sizeof(line) - strlen(line), "/%d", masklen);
return line;
}
p(rts_newgateway, "\t%u new gateway%s due to redirects\n");
p(rts_unreach, "\t%u destination%s found unreachable\n");
p(rts_wildcard, "\t%u use%s of a wildcard route\n");
+ p(rts_badrtgwroute, "\t%u lookup%s returned indirect "
+ "routes pointing to indirect gateway route\n");
#undef p
if (rttrash || sflag <= 1)