From 2c2eeb27011aea22fb1d03eec98e997b9a83b30f Mon Sep 17 00:00:00 2001 From: deraadt Date: Thu, 10 Apr 1997 10:09:01 +0000 Subject: [PATCH] allow syntax of the form "route add -net 192.168.64.0/20 "; phk@freebsd, man page changes done by me 'cause i'm a bit bored --- sbin/route/route.8 | 6 +++++- sbin/route/route.c | 34 ++++++++++++++++++++++++++-------- 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); -- 2.20.1