Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

NetBSD 1.5

  • Loading branch information...
commit 9c9ae0c70f59fa327dc2fb919e0dada3743abd45 1 parent 460c869
itojun authored
View
4 netbsd/sbin/route/Makefile
@@ -1,10 +1,12 @@
-# $NetBSD: Makefile,v 1.18 1997/10/10 19:52:22 christos Exp $
+# $NetBSD: Makefile,v 1.20 1999/07/03 06:27:56 itojun Exp $
# @(#)Makefile 8.1 (Berkeley) 6/5/93
PROG= route
MAN= route.8
SRCS= route.c show.c keywords.c ccitt_addr.c
+CPPFLAGS+=-DINET6
+
# The Makefile over in ../../distrib/utils/x_route
# would like keywords.[ch] to always exist here, so
# they are now checked in as sources.
View
4 netbsd/sbin/route/keywords.c
@@ -1,4 +1,4 @@
-/* $NetBSD: keywords.c,v 1.2 1997/04/03 02:35:48 christos Exp $ */
+/* $NetBSD: keywords.c,v 1.3 1999/07/02 15:29:03 itojun Exp $ */
/* WARNING! This file was generated by keywords.sh */
@@ -25,6 +25,7 @@ struct keytab keywords[] = {
{"ifa", K_IFA},
{"ifp", K_IFP},
{"inet", K_INET},
+ {"inet6", K_INET6},
{"iso", K_ISO},
{"link", K_LINK},
{"llinfo", K_LLINFO},
@@ -37,6 +38,7 @@ struct keytab keywords[] = {
{"netmask", K_NETMASK},
{"nostatic", K_NOSTATIC},
{"osi", K_OSI},
+ {"prefixlen", K_PREFIXLEN},
{"proto1", K_PROTO1},
{"proto2", K_PROTO2},
{"recvpipe", K_RECVPIPE},
View
56 netbsd/sbin/route/keywords.h
@@ -1,4 +1,4 @@
-/* $NetBSD: keywords.h,v 1.4 1997/04/03 02:35:49 christos Exp $ */
+/* $NetBSD: keywords.h,v 1.5 1999/07/02 15:29:03 itojun Exp $ */
/* WARNING! This file was generated by keywords.sh */
@@ -27,29 +27,31 @@ extern struct keytab {
#define K_IFA 17
#define K_IFP 18
#define K_INET 19
-#define K_ISO 20
-#define K_LINK 21
-#define K_LLINFO 22
-#define K_LOCK 23
-#define K_LOCKREST 24
-#define K_MASK 25
-#define K_MONITOR 26
-#define K_MTU 27
-#define K_NET 28
-#define K_NETMASK 29
-#define K_NOSTATIC 30
-#define K_OSI 31
-#define K_PROTO1 32
-#define K_PROTO2 33
-#define K_RECVPIPE 34
-#define K_REJECT 35
-#define K_RTT 36
-#define K_RTTVAR 37
-#define K_SA 38
-#define K_SENDPIPE 39
-#define K_SHOW 40
-#define K_SSTHRESH 41
-#define K_STATIC 42
-#define K_X25 43
-#define K_XNS 44
-#define K_XRESOLVE 45
+#define K_INET6 20
+#define K_ISO 21
+#define K_LINK 22
+#define K_LLINFO 23
+#define K_LOCK 24
+#define K_LOCKREST 25
+#define K_MASK 26
+#define K_MONITOR 27
+#define K_MTU 28
+#define K_NET 29
+#define K_NETMASK 30
+#define K_NOSTATIC 31
+#define K_OSI 32
+#define K_PREFIXLEN 33
+#define K_PROTO1 34
+#define K_PROTO2 35
+#define K_RECVPIPE 36
+#define K_REJECT 37
+#define K_RTT 38
+#define K_RTTVAR 39
+#define K_SA 40
+#define K_SENDPIPE 41
+#define K_SHOW 42
+#define K_SSTHRESH 43
+#define K_STATIC 44
+#define K_X25 45
+#define K_XNS 46
+#define K_XRESOLVE 47
View
4 netbsd/sbin/route/keywords.sh
@@ -1,5 +1,5 @@
#!/bin/sh
-# $NetBSD: keywords.sh,v 1.4 1997/04/03 02:35:49 christos Exp $
+# $NetBSD: keywords.sh,v 1.5 1999/07/02 15:29:03 itojun Exp $
# @(#)keywords 8.2 (Berkeley) 3/19/94
#
# WARNING! If you change this file, re-run it!
@@ -27,6 +27,7 @@ interface
ifa
ifp
inet
+inet6
iso
link
llinfo
@@ -39,6 +40,7 @@ net
netmask
nostatic
osi
+prefixlen
proto1
proto2
recvpipe
View
21 netbsd/sbin/route/route.8
@@ -1,4 +1,4 @@
-.\" $NetBSD: route.8,v 1.17 1999/03/24 06:29:21 mycroft Exp $
+.\" $NetBSD: route.8,v 1.19 1999/07/17 06:51:27 itojun Exp $
.\"
.\" Copyright (c) 1983, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -137,8 +137,9 @@ When the address family is specified by any of the
.Fl osi ,
.Fl xns ,
.Fl atalk ,
+.Fl inet ,
or
-.Fl inet
+.Fl inet6
modifiers, only routes having destinations with addresses in the
delineated family will be deleted.
.Pp
@@ -230,6 +231,8 @@ The implicit network mask generated in the
.Dv AF_INET
case
can be overridden by making sure this option follows the destination parameter.
+.Fl prefixlen
+is also available for similar purpose, in IPv6 case.
.Pp
Routes have associated flags which influence operation of the protocols
when sending to destinations matched by the routes.
@@ -347,7 +350,21 @@ The
.Nm
command appeared in
.Bx 4.2 .
+IPv6 support was added by WIDE/KAME project.
.Sh BUGS
The first paragraph may have slightly exaggerated
.Xr routed 8 Ns 's
abilities.
+.Pp
+Some uses of the
+.Fl ifa
+or
+.Fl ifp
+modifiers with the add command will incorrectly fail with a
+.Dq Network is unreachable
+message if there is no default route.
+See case
+.Dv RTM_ADD
+in
+.Pa sys/net/rtsock.c:route_output
+for details.
View
260 netbsd/sbin/route/route.c
@@ -1,4 +1,4 @@
-/* $NetBSD: route.c,v 1.30 1998/10/23 05:36:42 lukem Exp $ */
+/* $NetBSD: route.c,v 1.38.4.1 2000/10/17 20:44:14 tv Exp $ */
/*
* Copyright (c) 1983, 1989, 1991, 1993
@@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1989, 1991, 1993\n\
#if 0
static char sccsid[] = "@(#)route.c 8.6 (Berkeley) 4/28/95";
#else
-__RCSID("$NetBSD: route.c,v 1.30 1998/10/23 05:36:42 lukem Exp $");
+__RCSID("$NetBSD: route.c,v 1.38.4.1 2000/10/17 20:44:14 tv Exp $");
#endif
#endif /* not lint */
@@ -86,9 +86,15 @@ static char *any_ntoa __P((const struct sockaddr *));
static void set_metric __P((char *, int));
static void newroute __P((int, char **));
static void inet_makenetandmask __P((u_int32_t, struct sockaddr_in *));
+#ifdef INET6
+static void inet6_makenetandmask __P((struct sockaddr_in6 *));
+#endif
static int getaddr __P((int, char *, struct hostent **));
static void flushroutes __P((int, char *[]));
#ifndef SMALL
+#ifdef INET6
+static int prefixlen __P((char *));
+#endif
static int x25_makemask __P((void));
static void interfaces __P((void));
static void monitor __P((void));
@@ -108,6 +114,9 @@ struct ortentry route;
union sockunion {
struct sockaddr sa;
struct sockaddr_in sin;
+#ifdef INET6
+ struct sockaddr_in6 sin6;
+#endif
struct sockaddr_at sat;
struct sockaddr_dl sdl;
#ifndef SMALL
@@ -139,7 +148,7 @@ usage(cp)
}
#define ROUNDUP(a) \
- ((a) > 0 ? (1 + (((a) - 1) | (sizeof(int32_t) - 1))) : sizeof(int32_t))
+ ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
int
@@ -253,6 +262,11 @@ flushroutes(argc, argv)
case K_INET:
af = AF_INET;
break;
+#ifdef INET6
+ case K_INET6:
+ af = AF_INET6;
+ break;
+#endif
case K_ATALK:
af = AF_APPLETALK;
break;
@@ -327,7 +341,7 @@ bad: usage(*argv);
struct sockaddr *sa = (struct sockaddr *)(rtm + 1);
(void) printf("%-20.20s ", rtm->rtm_flags & RTF_HOST ?
routename(sa) : netname(sa));
- sa = (struct sockaddr *)(sa->sa_len + (char *)sa);
+ sa = (struct sockaddr *)(ROUNDUP(sa->sa_len) + (char *)sa);
(void) printf("%-20.20s ", routename(sa));
(void) printf("done\n");
}
@@ -413,6 +427,41 @@ routename(sa)
return (link_ntoa((struct sockaddr_dl *)sa));
#ifndef SMALL
+#ifdef INET6
+ case AF_INET6:
+ {
+ struct sockaddr_in6 sin6;
+ int niflags;
+
+#ifdef NI_WITHSCOPEID
+ niflags = NI_WITHSCOPEID;
+#else
+ niflags = 0;
+#endif
+ if (nflag)
+ niflags |= NI_NUMERICHOST;
+ memset(&sin6, 0, sizeof(sin6));
+ memcpy(&sin6, sa, sa->sa_len);
+ sin6.sin6_len = sizeof(struct sockaddr_in6);
+ sin6.sin6_family = AF_INET6;
+#ifdef __KAME__
+ if (sa->sa_len == sizeof(struct sockaddr_in6) &&
+ (IN6_IS_ADDR_LINKLOCAL(&sin6.sin6_addr) ||
+ IN6_IS_ADDR_MC_LINKLOCAL(&sin6.sin6_addr)) &&
+ sin6.sin6_scope_id == 0) {
+ sin6.sin6_scope_id =
+ ntohs(*(u_int16_t *)&sin6.sin6_addr.s6_addr[2]);
+ sin6.sin6_addr.s6_addr[2] = 0;
+ sin6.sin6_addr.s6_addr[3] = 0;
+ }
+#endif
+ if (getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len,
+ line, sizeof(line), NULL, 0, niflags) != 0)
+ strncpy(line, "invalid", sizeof(line));
+ break;
+ }
+#endif
+
case AF_NS:
return (ns_print((struct sockaddr_ns *)sa));
@@ -515,6 +564,41 @@ netname(sa)
return (link_ntoa((struct sockaddr_dl *)sa));
#ifndef SMALL
+#ifdef INET6
+ case AF_INET6:
+ {
+ struct sockaddr_in6 sin6;
+ int niflags;
+
+#ifdef NI_WITHSCOPEID
+ niflags = NI_WITHSCOPEID;
+#else
+ niflags = 0;
+#endif
+ if (nflag)
+ niflags |= NI_NUMERICHOST;
+ memset(&sin6, 0, sizeof(sin6));
+ memcpy(&sin6, sa, sa->sa_len);
+ sin6.sin6_len = sizeof(struct sockaddr_in6);
+ sin6.sin6_family = AF_INET6;
+#ifdef __KAME__
+ if (sa->sa_len == sizeof(struct sockaddr_in6) &&
+ (IN6_IS_ADDR_LINKLOCAL(&sin6.sin6_addr) ||
+ IN6_IS_ADDR_MC_LINKLOCAL(&sin6.sin6_addr)) &&
+ sin6.sin6_scope_id == 0) {
+ sin6.sin6_scope_id =
+ ntohs(*(u_int16_t *)&sin6.sin6_addr.s6_addr[2]);
+ sin6.sin6_addr.s6_addr[2] = 0;
+ sin6.sin6_addr.s6_addr[3] = 0;
+ }
+#endif
+ if (getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len,
+ line, sizeof(line), NULL, 0, niflags) != 0)
+ strncpy(line, "invalid", sizeof(line));
+ break;
+ }
+#endif
+
case AF_NS:
return (ns_print((struct sockaddr_ns *)sa));
@@ -599,6 +683,13 @@ newroute(argc, argv)
aflen = sizeof(struct sockaddr_in);
break;
+#ifdef INET6
+ case K_INET6:
+ af = AF_INET6;
+ aflen = sizeof(struct sockaddr_in6);
+ break;
+#endif
+
case K_LINK:
af = AF_LINK;
aflen = sizeof(struct sockaddr_dl);
@@ -696,6 +787,18 @@ newroute(argc, argv)
case K_NET:
forcenet++;
break;
+#ifdef INET6
+ case K_PREFIXLEN:
+ argc--;
+ if (prefixlen(*++argv) == 128) {
+ forcenet = 0;
+ ishost = 1;
+ } else {
+ forcenet = 1;
+ ishost = 0;
+ }
+ break;
+#endif
case K_MTU:
case K_HOPCOUNT:
case K_EXPIRE:
@@ -841,6 +944,37 @@ inet_makenetandmask(net, sin)
sin->sin_len = 1 + cp - (char *)sin;
}
+#ifdef INET6
+/*
+ * XXX the function may need more improvement...
+ */
+static void
+inet6_makenetandmask(sin6)
+ struct sockaddr_in6 *sin6;
+{
+ char *plen;
+ struct in6_addr in6;
+
+ plen = NULL;
+ if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr) &&
+ sin6->sin6_scope_id == 0) {
+ plen = "0";
+ } else if ((sin6->sin6_addr.s6_addr[0] & 0xe0) == 0x20) {
+ /* aggregatable global unicast - RFC2374 */
+ memset(&in6, 0, sizeof(in6));
+ if (!memcmp(&sin6->sin6_addr.s6_addr[8], &in6.s6_addr[8], 8))
+ plen = "64";
+ else
+ plen = "128";
+ }
+
+ if (plen) {
+ rtm_addrs |= RTA_NETMASK;
+ prefixlen(plen);
+ }
+}
+#endif
+
/*
* Interpret an argument as a network address of some kind,
* returning 1 if a host address, 0 if a network address.
@@ -856,20 +990,20 @@ getaddr(which, s, hpp)
struct netent *np;
u_int32_t val;
char *t;
+ int afamily; /* local copy of af so we can change it */
if (af == 0) {
af = AF_INET;
aflen = sizeof(struct sockaddr_in);
}
+ afamily = af;
rtm_addrs |= which;
switch (which) {
case RTA_DST:
su = &so_dst;
- su->sa.sa_family = af;
break;
case RTA_GATEWAY:
su = &so_gate;
- su->sa.sa_family = af;
break;
case RTA_NETMASK:
su = &so_mask;
@@ -879,7 +1013,7 @@ getaddr(which, s, hpp)
break;
case RTA_IFP:
su = &so_ifp;
- su->sa.sa_family = af;
+ afamily = AF_LINK;
break;
case RTA_IFA:
su = &so_ifa;
@@ -891,6 +1025,7 @@ getaddr(which, s, hpp)
/*NOTREACHED*/
}
su->sa.sa_len = aflen;
+ su->sa.sa_family = afamily; /* cases that don't want it have left already */
if (strcmp(s, "default") == 0) {
switch (which) {
case RTA_DST:
@@ -903,8 +1038,40 @@ getaddr(which, s, hpp)
}
return (0);
}
- switch (af) {
+ switch (afamily) {
#ifndef SMALL
+#ifdef INET6
+ case AF_INET6:
+ {
+ struct addrinfo hints, *res;
+
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = afamily; /*AF_INET6*/
+ hints.ai_flags = AI_NUMERICHOST;
+ hints.ai_socktype = SOCK_DGRAM; /*dummy*/
+ if (getaddrinfo(s, "0", &hints, &res) != 0 ||
+ res->ai_family != AF_INET6 ||
+ res->ai_addrlen != sizeof(su->sin6)) {
+ (void) fprintf(stderr, "%s: bad value\n", s);
+ exit(1);
+ }
+ memcpy(&su->sin6, res->ai_addr, sizeof(su->sin6));
+#ifdef __KAME__
+ if ((IN6_IS_ADDR_LINKLOCAL(&su->sin6.sin6_addr) ||
+ IN6_IS_ADDR_MC_LINKLOCAL(&su->sin6.sin6_addr)) &&
+ su->sin6.sin6_scope_id) {
+ *(u_int16_t *)&su->sin6.sin6_addr.s6_addr[2] =
+ htons(su->sin6.sin6_scope_id);
+ su->sin6.sin6_scope_id = 0;
+ }
+#endif
+ if (which == RTA_DST)
+ inet6_makenetandmask(&su->sin6);
+ freeaddrinfo(res);
+ return 0;
+ }
+#endif
+
case AF_NS:
if (which == RTA_DST) {
extern short ns_bh[3];
@@ -994,6 +1161,33 @@ getaddr(which, s, hpp)
errx(1, "bad value: %s", s);
}
+#ifdef INET6
+int
+prefixlen(s)
+ char *s;
+{
+ int len = atoi(s), q, r;
+
+ rtm_addrs |= RTA_NETMASK;
+ if (len < -1 || len > 129) {
+ (void) fprintf(stderr, "%s: bad value\n", s);
+ exit(1);
+ }
+
+ q = len >> 3;
+ r = len & 7;
+ so_mask.sin6.sin6_family = AF_INET6;
+ so_mask.sin6.sin6_len = sizeof(struct sockaddr_in6);
+ memset((void *)&so_mask.sin6.sin6_addr, 0,
+ sizeof(so_mask.sin6.sin6_addr));
+ if (q > 0)
+ memset((void *)&so_mask.sin6.sin6_addr, 0xff, q);
+ if (r > 0)
+ *((u_char *)&so_mask.sin6.sin6_addr + q) = (0xff00 >> r) & 0xff;
+ return(len);
+}
+#endif
+
#ifndef SMALL
int
x25_makemask()
@@ -1097,8 +1291,10 @@ monitor()
exit(0);
}
for(;;) {
+ time_t now;
n = read(s, msg, 2048);
- (void) printf("got message of size %d\n", n);
+ now = time(NULL);
+ (void) printf("got message of size %d on %s", n, ctime(&now));
print_rtmsg((struct rt_msghdr *)msg, n);
}
}
@@ -1201,6 +1397,9 @@ mask_addr()
return;
switch (so_dst.sa.sa_family) {
case AF_INET:
+#ifdef INET6
+ case AF_INET6:
+#endif
case AF_APPLETALK:
#ifndef SMALL
case AF_NS:
@@ -1246,7 +1445,9 @@ char *msgtypes[] = {
"RTM_RESOLVE: Route created by cloning",
"RTM_NEWADDR: address being added to iface",
"RTM_DELADDR: address being removed from iface",
+ "RTM_OIFINFO: iface status change (pre-1.5)",
"RTM_IFINFO: iface status change",
+ "RTM_IFANNOUNCE: iface arrival/departure",
0,
};
@@ -1266,6 +1467,7 @@ print_rtmsg(rtm, msglen)
{
struct if_msghdr *ifm;
struct ifa_msghdr *ifam;
+ struct if_announcemsghdr *ifan;
if (verbose == 0)
return;
@@ -1274,7 +1476,11 @@ print_rtmsg(rtm, msglen)
rtm->rtm_version);
return;
}
- (void)printf("%s: len %d, ", msgtypes[rtm->rtm_type], rtm->rtm_msglen);
+ if (msgtypes[rtm->rtm_type])
+ (void)printf("%s: ", msgtypes[rtm->rtm_type]);
+ else
+ (void)printf("#%d: ", rtm->rtm_type);
+ (void)printf("len %d, ", rtm->rtm_msglen);
switch (rtm->rtm_type) {
case RTM_IFINFO:
ifm = (struct if_msghdr *)rtm;
@@ -1289,6 +1495,22 @@ print_rtmsg(rtm, msglen)
bprintf(stdout, ifam->ifam_flags, routeflags);
pmsg_addrs((char *)(ifam + 1), ifam->ifam_addrs);
break;
+ case RTM_IFANNOUNCE:
+ ifan = (struct if_announcemsghdr *)rtm;
+ (void) printf("if# %d, what: ", ifan->ifan_index);
+ switch (ifan->ifan_what) {
+ case IFAN_ARRIVAL:
+ printf("arrival");
+ break;
+ case IFAN_DEPARTURE:
+ printf("departure");
+ break;
+ default:
+ printf("#%d", ifan->ifan_what);
+ break;
+ }
+ printf("\n");
+ break;
default:
(void) printf("pid: %d, seq %d, errno %d, flags:",
rtm->rtm_pid, rtm->rtm_seq, rtm->rtm_errno);
@@ -1303,7 +1525,7 @@ print_getmsg(rtm, msglen)
struct rt_msghdr *rtm;
int msglen;
{
- struct sockaddr *dst = NULL, *gate = NULL, *mask = NULL;
+ struct sockaddr *dst = NULL, *gate = NULL, *mask = NULL, *ifa = NULL;
struct sockaddr_dl *ifp = NULL;
struct sockaddr *sa;
char *cp;
@@ -1344,6 +1566,9 @@ print_getmsg(rtm, msglen)
((struct sockaddr_dl *)sa)->sdl_nlen)
ifp = (struct sockaddr_dl *)sa;
break;
+ case RTA_IFA:
+ ifa = sa;
+ break;
}
ADVANCE(cp, sa);
}
@@ -1360,6 +1585,8 @@ print_getmsg(rtm, msglen)
}
if (gate && rtm->rtm_flags & RTF_GATEWAY)
(void)printf(" gateway: %s\n", routename(gate));
+ if (ifa)
+ (void)printf(" local addr: %s\n", routename(ifa));
if (ifp)
(void)printf(" interface: %.*s\n",
ifp->sdl_nlen, ifp->sdl_data);
@@ -1474,6 +1701,10 @@ sodump(su, which)
sup su;
char *which;
{
+#ifdef INET6
+ char ntop_buf[NI_MAXHOST];
+#endif
+
switch (su->sa.sa_family) {
case AF_INET:
(void) printf("%s: inet %s; ",
@@ -1488,6 +1719,13 @@ sodump(su, which)
which, link_ntoa(&su->sdl));
break;
#ifndef SMALL
+#ifdef INET6
+ case AF_INET6:
+ (void) printf("%s: inet6 %s; ",
+ which, inet_ntop(AF_INET6, &su->sin6.sin6_addr,
+ ntop_buf, sizeof(ntop_buf)));
+ break;
+#endif
case AF_ISO:
(void) printf("%s: iso %s; ",
which, iso_ntoa(&su->siso.siso_addr));
View
49 netbsd/sbin/route/show.c
@@ -1,4 +1,4 @@
-/* $NetBSD: show.c,v 1.8 1998/10/23 05:36:43 lukem Exp $ */
+/* $NetBSD: show.c,v 1.14.4.1 2000/10/18 00:39:48 tv Exp $ */
/*
* Copyright (c) 1983, 1988, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "from: @(#)route.c 8.3 (Berkeley) 3/9/94";
#else
-__RCSID("$NetBSD: show.c,v 1.8 1998/10/23 05:36:43 lukem Exp $");
+__RCSID("$NetBSD: show.c,v 1.14.4.1 2000/10/18 00:39:48 tv Exp $");
#endif
#endif /* not lint */
@@ -65,6 +65,10 @@ __RCSID("$NetBSD: show.c,v 1.8 1998/10/23 05:36:43 lukem Exp $");
#include "extern.h"
+#define ROUNDUP(a) \
+ ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
+#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
+
/*
* Definitions for showing gateway flags.
*/
@@ -94,7 +98,7 @@ static void pr_rthdr __P((void));
static void p_rtentry __P((struct rt_msghdr *));
static void pr_family __P((int));
static void p_sockaddr __P((struct sockaddr *, int, int ));
-static void p_flags __P((int, char *));
+static void p_flags __P((int));
/*
* Print routing tables.
@@ -120,7 +124,7 @@ show(argc, argv)
exit(1);
}
if ((buf = malloc(needed)) == 0)
- err(1, "%s", "");
+ err(1, NULL);
if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0)
err(1, "sysctl of routing table");
lim = buf + needed;
@@ -189,15 +193,13 @@ p_rtentry(rtm)
pr_rthdr();
}
if (rtm->rtm_addrs == RTA_DST)
- p_sockaddr(sa, 0, 36);
+ p_sockaddr(sa, 0, WID_DST + 1 + WID_GW + 1);
else {
- p_sockaddr(sa, rtm->rtm_flags, 16);
- if (sa->sa_len == 0)
- sa->sa_len = sizeof(long);
- sa = (struct sockaddr *)(sa->sa_len + (char *)sa);
- p_sockaddr(sa, 0, 18);
+ p_sockaddr(sa, rtm->rtm_flags, WID_DST);
+ sa = (struct sockaddr *)(ROUNDUP(sa->sa_len) + (char *)sa);
+ p_sockaddr(sa, 0, WID_GW);
}
- p_flags(rtm->rtm_flags & interesting, "%-6.6s ");
+ p_flags(rtm->rtm_flags & interesting);
putchar('\n');
}
@@ -216,6 +218,11 @@ pr_family(af)
afname = "Internet";
break;
#ifndef SMALL
+#ifdef INET6
+ case AF_INET6:
+ afname = "Internet6";
+ break;
+#endif /* INET6 */
case AF_NS:
afname = "XNS";
break;
@@ -295,6 +302,21 @@ p_sockaddr(sa, flags, width)
}
#ifndef SMALL
+#ifdef INET6
+ case AF_INET6:
+ {
+ struct sockaddr_in6 *sin = (struct sockaddr_in6 *)sa;
+
+ cp = IN6_IS_ADDR_UNSPECIFIED(&sin->sin6_addr) ? "default" :
+ ((flags & RTF_HOST) ?
+ routename(sa) : netname(sa));
+ /* make sure numeric address is not truncated */
+ if (strchr(cp, ':') != NULL && strlen(cp) > width)
+ width = strlen(cp);
+ break;
+ }
+#endif /* INET6 */
+
case AF_NS:
cp = ns_print((struct sockaddr_ns *)sa);
break;
@@ -326,9 +348,8 @@ p_sockaddr(sa, flags, width)
}
static void
-p_flags(f, format)
+p_flags(f)
int f;
- char *format;
{
char name[33], *flags;
const struct bits *p = bits;
@@ -337,6 +358,6 @@ p_flags(f, format)
if (p->b_mask & f)
*flags++ = p->b_val;
*flags = '\0';
- printf(format, name);
+ printf("%-6.6s ", name);
}
Please sign in to comment.
Something went wrong with that request. Please try again.