summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1997-04-10 10:09:03 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1997-04-10 10:09:03 +0000
commit254e7024d309a03672e32dedd92a4555eaa8d0f4 (patch)
treea8cb57aea59a39bcff464dd496a64c0db161cd29 /sbin
parenta38cc9a81b647016b67cba99019e797a2d474538 (diff)
allow syntax of the form "route add -net 192.168.64.0/20 <destaddr>";
phk@freebsd, man page changes done by me 'cause i'm a bit bored
Diffstat (limited to 'sbin')
-rw-r--r--sbin/route/route.86
-rw-r--r--sbin/route/route.c34
2 files changed, 31 insertions, 9 deletions
diff --git a/sbin/route/route.8 b/sbin/route/route.8
index ef3fe83fcd0..d8776a4379c 100644
--- a/sbin/route/route.8
+++ b/sbin/route/route.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: route.8,v 1.4 1996/12/14 17:23:53 deraadt Exp $
+.\" $OpenBSD: route.8,v 1.5 1997/04/10 10:09:01 deraadt Exp $
.\" $NetBSD: route.8,v 1.6 1995/03/18 15:00:13 cgd Exp $
.\"
.\" Copyright (c) 1983, 1991, 1993
@@ -174,6 +174,10 @@ and
.Fl net Li 128.32.130
is interpreted as
.Li 128.32.130.0 .
+A more detailed syntax is also available, for example
+.Li net 192.168.64.0/20
+is interpreted to specify that the high 20 bits of the address
+192.168.64.0 are the requested network.
.Pp
If the destination is directly reachable
via an interface requiring
diff --git a/sbin/route/route.c b/sbin/route/route.c
index 52d2755bfb5..ab0e40e5204 100644
--- a/sbin/route/route.c
+++ b/sbin/route/route.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: route.c,v 1.17 1997/01/15 23:41:40 millert Exp $ */
+/* $OpenBSD: route.c,v 1.18 1997/04/10 10:09:02 deraadt Exp $ */
/* $NetBSD: route.c,v 1.16 1996/04/15 18:27:05 cgd Exp $ */
/*
@@ -44,7 +44,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)route.c 8.3 (Berkeley) 3/19/94";
#else
-static char rcsid[] = "$OpenBSD: route.c,v 1.17 1997/01/15 23:41:40 millert Exp $";
+static char rcsid[] = "$OpenBSD: route.c,v 1.18 1997/04/10 10:09:02 deraadt Exp $";
#endif
#endif /* not lint */
@@ -325,9 +325,9 @@ any_ntoa(sa)
*out++ = 'Q';
do {
- *out++ = hexlist[(*in >> 4) & 15];
- *out++ = hexlist[(*in++) & 15];
- *out++ = '.';
+ *out++ = hexlist[(*in >> 4) & 15];
+ *out++ = hexlist[(*in++) & 15];
+ *out++ = '.';
} while (--len > 0 && (out + 3) < &obuf[sizeof obuf-1]);
out[-1] = '\0';
return (obuf);
@@ -733,9 +733,10 @@ newroute(argc, argv)
}
void
-inet_makenetandmask(net, sin)
+inet_makenetandmask(net, sin, bits)
u_int32_t net;
register struct sockaddr_in *sin;
+ int bits;
{
u_int32_t addr, mask = 0;
register char *cp;
@@ -743,7 +744,10 @@ inet_makenetandmask(net, sin)
rtm_addrs |= RTA_NETMASK;
if (net == 0)
mask = addr = 0;
- else if (net < 128) {
+ else if (bits) {
+ addr = net;
+ mask = 0xffffffff << (32 - bits);
+ } else if (net < 128) {
addr = net << IN_CLASSA_NSHIFT;
mask = IN_CLASSA_NET;
} else if (net < 65536) {
@@ -792,6 +796,7 @@ getaddr(which, s, hpp)
struct hostent *hp;
struct netent *np;
u_long val;
+ char *q, qs;
if (af == 0) {
af = AF_INET;
@@ -898,6 +903,19 @@ getaddr(which, s, hpp)
if (hpp == NULL)
hpp = &hp;
*hpp = NULL;
+
+ q = strchr(s,'/');
+ if (q && which == RTA_DST) {
+ qs = *q;
+ *q = '\0';
+ val = inet_addr(s);
+ if (val != INADDR_NONE) {
+ inet_makenetandmask(htonl(val), &su->sin,
+ strtoul(q+1, 0, 0));
+ return (0);
+ }
+ *q =qs;
+ }
if (((val = inet_addr(s)) != INADDR_NONE) &&
(which != RTA_DST || forcenet == 0)) {
su->sin.sin_addr.s_addr = val;
@@ -913,7 +931,7 @@ getaddr(which, s, hpp)
(val = np->n_net) != 0)) {
netdone:
if (which == RTA_DST)
- inet_makenetandmask(val, &su->sin);
+ inet_makenetandmask(val, &su->sin, 0);
return (0);
}
hp = gethostbyname(s);