Implement slash/CIDR notation for IPv4 and IPv6 addresses.
MFC after: 1 week Reviewed by: phk Obtained from: NetBSD
This commit is contained in:
parent
1766b2e5fa
commit
e1387e5d19
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=76276
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user