diff options
author | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2001-01-18 04:46:04 +0000 |
---|---|---|
committer | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2001-01-18 04:46:04 +0000 |
commit | 3a0c6f8208253ce8785e819bf4bb9f950d8c0023 (patch) | |
tree | d9855951aab54f1eceeadb7f6e35c4eb91a5b7d8 | |
parent | 3300ce86fbe641003ab7db2b3c0169df64c8bf69 (diff) |
permit prefixlen against inet address, like:
# ifconfig fxp0 10.0.0.1 prefixlen 23
-rw-r--r-- | sbin/ifconfig/ifconfig.8 | 4 | ||||
-rw-r--r-- | sbin/ifconfig/ifconfig.c | 31 |
2 files changed, 30 insertions, 5 deletions
diff --git a/sbin/ifconfig/ifconfig.8 b/sbin/ifconfig/ifconfig.8 index 9a9cea09d45..5606ff75240 100644 --- a/sbin/ifconfig/ifconfig.8 +++ b/sbin/ifconfig/ifconfig.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ifconfig.8,v 1.49 2000/12/30 21:56:43 angelos Exp $ +.\" $OpenBSD: ifconfig.8,v 1.50 2001/01/18 04:46:03 itojun Exp $ .\" $NetBSD: ifconfig.8,v 1.11 1996/01/04 21:27:29 pk Exp $ .\" $FreeBSD: ifconfig.8,v 1.16 1998/02/01 07:03:29 steve Exp $ .\" @@ -375,7 +375,7 @@ Values of 1 or 2 are permitted. (inet6 only) Set preferred lifetime for the address. .It Cm prefixlen Ar n -(inet6 only) +(inet and inet6 only) Effect is similar to .Cm netmask , but you can specify by prefix length by digits. diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index 2299980fc30..220a774d950 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ifconfig.c,v 1.43 2000/12/30 21:56:44 angelos Exp $ */ +/* $OpenBSD: ifconfig.c,v 1.44 2001/01/18 04:46:03 itojun Exp $ */ /* $NetBSD: ifconfig.c,v 1.40 1997/10/01 02:19:43 enami Exp $ */ /* @@ -81,7 +81,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)ifconfig.c 8.2 (Berkeley) 2/16/94"; #else -static char rcsid[] = "$OpenBSD: ifconfig.c,v 1.43 2000/12/30 21:56:44 angelos Exp $"; +static char rcsid[] = "$OpenBSD: ifconfig.c,v 1.44 2001/01/18 04:46:03 itojun Exp $"; #endif #endif /* not lint */ @@ -310,6 +310,7 @@ void init_current_media __P((void)); */ void in_status __P((int)); void in_getaddr __P((char *, int)); +void in_getprefix __P((char *, int)); #ifdef INET6 void in6_fillscopeid __P((struct sockaddr_in6 *sin6)); void in6_alias __P((struct in6_ifreq *)); @@ -340,7 +341,7 @@ const struct afswtch { caddr_t af_addreq; } afs[] = { #define C(x) ((caddr_t) &x) - { "inet", AF_INET, in_status, in_getaddr, NULL, + { "inet", AF_INET, in_status, in_getaddr, in_getprefix, SIOCDIFADDR, SIOCAIFADDR, C(ridreq), C(addreq) }, #ifdef INET6 { "inet6", AF_INET6, in6_status, in6_getaddr, in6_getprefix, @@ -1959,6 +1960,30 @@ in_getaddr(s, which) } } +void +in_getprefix(plen, which) + char *plen; + int which; +{ + register struct sockaddr_in *sin = sintab[which]; + register u_char *cp; + int len = strtol(plen, (char **)NULL, 10); + + if ((len < 0) || (len > 32)) + errx(1, "%s: bad value", plen); + sin->sin_len = sizeof(*sin); + if (which != MASK) + sin->sin_family = AF_INET; + if ((len == 0) || (len == 32)) { + memset(&sin->sin_addr, 0xff, sizeof(struct in_addr)); + return; + } + memset((void *)&sin->sin_addr, 0x00, sizeof(sin->sin_addr)); + for (cp = (u_char *)&sin->sin_addr; len > 7; len -= 8) + *cp++ = 0xff; + *cp = 0xff << (8 - len); +} + /* * Print a value a la the %b format of the kernel's printf */ |