diff options
author | Henning Brauer <henning@cvs.openbsd.org> | 2007-06-13 06:46:27 +0000 |
---|---|---|
committer | Henning Brauer <henning@cvs.openbsd.org> | 2007-06-13 06:46:27 +0000 |
commit | f889da62b9890f64bb9c3bc12181beae133dc7c5 (patch) | |
tree | 3a1f342788d316c32578f692acab2c5c3a922b38 /sbin/ifconfig/ifconfig.c | |
parent | deceb0ef8c95816511a4806f7754d4ef3c117786 (diff) |
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
Diffstat (limited to 'sbin/ifconfig/ifconfig.c')
-rw-r--r-- | sbin/ifconfig/ifconfig.c | 17 |
1 files changed, 14 insertions, 3 deletions
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))) |