diff options
author | jesper <jesper@FreeBSD.org> | 2001-05-04 18:45:36 +0000 |
---|---|---|
committer | jesper <jesper@FreeBSD.org> | 2001-05-04 18:45:36 +0000 |
commit | 814b5baeb7dc8c25c9cdaed60143c2d40939131a (patch) | |
tree | 708e1b521e72baad967b3fbc48a84ea6ebd214b5 /sbin | |
parent | 389d1c1b278f2660c04eb7f18cdf6ebc96fc020d (diff) | |
download | FreeBSD-src-814b5baeb7dc8c25c9cdaed60143c2d40939131a.zip FreeBSD-src-814b5baeb7dc8c25c9cdaed60143c2d40939131a.tar.gz |
Implement slash/CIDR notation for IPv4 and IPv6 addresses.
MFC after: 1 week
Reviewed by: phk
Obtained from: NetBSD
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/ifconfig/ifconfig.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index 6a2454f..699c433 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -1292,6 +1292,26 @@ in_getaddr(s, which) if (which != MASK) sin->sin_family = AF_INET; + if (which == ADDR) { + char *p = NULL; + + if((p = strrchr(s, '/')) != NULL) { + /* address is `name/masklen' */ + int masklen; + int ret; + struct sockaddr_in *min = sintab[MASK]; + *p = '\0'; + ret = sscanf(p+1, "%u", &masklen); + if(ret != 1 || (masklen < 0 || masklen > 32)) { + *p = '/'; + errx(1, "%s: bad value", s); + } + min->sin_len = sizeof(*min); + min->sin_addr.s_addr = htonl(~((1LL << (32 - masklen)) - 1) & + 0xffffffff); + } + } + if (inet_aton(s, &sin->sin_addr)) return; if ((hp = gethostbyname(s)) != 0) @@ -1324,6 +1344,15 @@ in6_getaddr(s, which) if (which != MASK) sin->sin6_family = AF_INET6; + if (which == ADDR) { + char *p = NULL; + if((p = strrchr(s, '/')) != NULL) { + *p = '\0'; + in6_getprefix(p + 1, MASK); + explicit_prefix = 1; + } + } + if (sin->sin6_family == AF_INET6) { bzero(&hints, sizeof(struct addrinfo)); hints.ai_family = AF_INET6; |