summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhenning <henning@openbsd.org>2007-06-13 06:46:26 +0000
committerhenning <henning@openbsd.org>2007-06-13 06:46:26 +0000
commitec2398f9a89b9da6f927ca143b35018973be6b50 (patch)
treec75ff51be18bdf04f330e21952f9fe291b8186e4
parentApply some KNF after the recent removal of macros and type definitions. (diff)
downloadwireguard-openbsd-ec2398f9a89b9da6f927ca143b35018973be6b50.tar.xz
wireguard-openbsd-ec2398f9a89b9da6f927ca143b35018973be6b50.zip
allow IPv4 addresses to be specified in CIDR notation, no need for seperate
mask in that case. initially from rivo nurges <rix@estpak.ee>, but changed quite a bit. this has annoyed me so long that I wonder why I hadn't fixed that earlier... input & ok markus deraadt, manpage also jmc
-rw-r--r--sbin/ifconfig/ifconfig.812
-rw-r--r--sbin/ifconfig/ifconfig.c17
2 files changed, 21 insertions, 8 deletions
diff --git a/sbin/ifconfig/ifconfig.8 b/sbin/ifconfig/ifconfig.8
index be5212fb505..d248cf8c5d3 100644
--- a/sbin/ifconfig/ifconfig.8
+++ b/sbin/ifconfig/ifconfig.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: ifconfig.8,v 1.143 2007/06/12 16:36:43 jmc Exp $
+.\" $OpenBSD: ifconfig.8,v 1.144 2007/06/13 06:46:26 henning 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 12 2007 $
+.Dd $Mdocdate: June 13 2007 $
.Dt IFCONFIG 8
.Os
.Sh NAME
@@ -126,9 +126,11 @@ and
.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
-.Dq dot notation .
+.Xr hosts 5
+or a DARPA
+Internet address expressed in the Internet standard
+.Dq dot
+or CIDR notation.
.Pp
Internet version 6 addresses are either a host name present
in the host name database,
diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c
index f1f9e52f3dd..a7eb7ac3d95 100644
--- a/sbin/ifconfig/ifconfig.c
+++ b/sbin/ifconfig/ifconfig.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ifconfig.c,v 1.179 2007/06/05 21:14:07 kurt Exp $ */
+/* $OpenBSD: ifconfig.c,v 1.180 2007/06/13 06:46:26 henning Exp $ */
/* $NetBSD: ifconfig.c,v 1.40 1997/10/01 02:19:43 enami Exp $ */
/*
@@ -3580,15 +3580,26 @@ SIN(in_addreq.ifra_mask), SIN(in_addreq.ifra_broadaddr)};
void
in_getaddr(const char *s, int which)
{
- struct sockaddr_in *sin = sintab[which];
+ struct sockaddr_in *sin = sintab[which], tsin;
struct hostent *hp;
struct netent *np;
+ int bits, l;
+ char p[3];
+ bzero(&tsin, sizeof(tsin));
sin->sin_len = sizeof(*sin);
if (which != MASK)
sin->sin_family = AF_INET;
- if (inet_aton(s, &sin->sin_addr) == 0) {
+ if (which == ADDR && strrchr(s, '/') != NULL &&
+ (bits = inet_net_pton(AF_INET, s, &tsin.sin_addr,
+ sizeof(tsin.sin_addr))) != -1) {
+ l = snprintf(p, sizeof(p), "%i", bits);
+ if (l >= sizeof(p) || l == -1)
+ errx(1, "%i: bad prefixlen", bits);
+ in_getprefix(p, MASK);
+ memcpy(&sin->sin_addr, &tsin.sin_addr, sizeof(sin->sin_addr));
+ } else if (inet_aton(s, &sin->sin_addr) == 0) {
if ((hp = gethostbyname(s)))
memcpy(&sin->sin_addr, hp->h_addr, hp->h_length);
else if ((np = getnetbyname(s)))