From c1eea903d4acc5860aa5b3e80b2d71c9a0d92358 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Ritschard Date: Tue, 19 Jun 2007 06:24:29 +0000 Subject: Allow IPv6 addresses to use the CIDR notation too, no need for separate prefixlen specification when using this form. man page bits by jmc. ok henning@, ``looks sane'' djm@. --- sbin/ifconfig/ifconfig.8 | 23 ++++++++--------------- sbin/ifconfig/ifconfig.c | 14 +++++++++++++- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/sbin/ifconfig/ifconfig.8 b/sbin/ifconfig/ifconfig.8 index 702038683d6..66e19b0be60 100644 --- a/sbin/ifconfig/ifconfig.8 +++ b/sbin/ifconfig/ifconfig.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ifconfig.8,v 1.145 2007/06/14 18:31:50 reyk Exp $ +.\" $OpenBSD: ifconfig.8,v 1.146 2007/06/19 06:24:28 pyr 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 $ .\" @@ -31,7 +31,7 @@ .\" .\" @(#)ifconfig.8 8.4 (Berkeley) 6/1/94 .\" -.Dd $Mdocdate: June 14 2007 $ +.Dd $Mdocdate: June 19 2007 $ .Dt IFCONFIG 8 .Os .Sh NAME @@ -124,22 +124,15 @@ supported are and .Dq atalk . .It Ar address -For the DARPA Internet family, -the address is either a host name present in the host name database, -.Xr hosts 5 -or a DARPA -Internet address expressed in the Internet standard +Internet version 4 and 6 addresses +take the form of +a host name present in the host name database, +.Xr hosts 5 ; .Dq dot +notation (IPv4); +colon separated (IPv6); or CIDR notation. .Pp -Internet version 6 addresses are either a host name present -in the host name database, -.Xr hosts 5 , -or an Internet version 6 address in standard colon separated form, as -described in the -.Xr inet 3 -manual page. -.Pp AppleTalk (LLAP) addresses are specified as .Dq nn.na .Pq Dq Network Number.Node Address . diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index 8f13ea8b423..eca72a745db 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ifconfig.c,v 1.181 2007/06/14 18:31:50 reyk Exp $ */ +/* $OpenBSD: ifconfig.c,v 1.182 2007/06/19 06:24:28 pyr Exp $ */ /* $NetBSD: ifconfig.c,v 1.40 1997/10/01 02:19:43 enami Exp $ */ /* @@ -3720,11 +3720,23 @@ in6_getaddr(const char *s, int which) { struct sockaddr_in6 *sin6 = sin6tab[which]; struct addrinfo hints, *res; + char buf[MAXHOSTNAMELEN+sizeof("/128")], *pfxlen; int error; memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_INET6; hints.ai_socktype = SOCK_DGRAM; /*dummy*/ + + if (which == ADDR && strchr(s, '/') != NULL) { + if (strlcpy(buf, s, sizeof(buf)) >= sizeof(buf)) + errx(1, "%s: bad value", s); + pfxlen = strchr(buf, '/'); + *pfxlen++ = '\0'; + s = buf; + in6_getprefix(pfxlen, MASK); + explicit_prefix = 1; + } + error = getaddrinfo(s, "0", &hints, &res); if (error) errx(1, "%s: %s", s, gai_strerror(error)); -- cgit v1.2.3