Allow prefix/prefixlen syntax for IPv6 to have consistency

with IPv4.
This commit is contained in:
ume 2002-05-21 18:11:31 +00:00
parent df03dac700
commit a491c6f95a

View File

@ -114,7 +114,7 @@ const char *routename(), *netname();
void flushroutes(), newroute(), monitor(), sockaddr(), sodump(), bprintf();
void print_getmsg(), print_rtmsg(), pmsg_common(), pmsg_addrs(), mask_addr();
#ifdef INET6
static int inet6_makenetandmask(struct sockaddr_in6 *);
static int inet6_makenetandmask(struct sockaddr_in6 *, char *);
#endif
int getaddr(), rtmsg(), x25_makemask();
int prefixlen();
@ -867,23 +867,25 @@ inet_makenetandmask(net, sin, bits)
* XXX the function may need more improvement...
*/
static int
inet6_makenetandmask(sin6)
inet6_makenetandmask(sin6, plen)
struct sockaddr_in6 *sin6;
{
char *plen;
{
struct in6_addr in6;
plen = NULL;
if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr) &&
sin6->sin6_scope_id == 0) {
plen = "0";
} else if ((sin6->sin6_addr.s6_addr[0] & 0xe0) == 0x20) {
/* aggregatable global unicast - RFC2374 */
memset(&in6, 0, sizeof(in6));
if (!memcmp(&sin6->sin6_addr.s6_addr[8], &in6.s6_addr[8], 8))
plen = "64";
else
plen = "128";
if (!plen) {
if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr) &&
sin6->sin6_scope_id == 0) {
plen = "0";
} else if ((sin6->sin6_addr.s6_addr[0] & 0xe0) == 0x20) {
/* aggregatable global unicast - RFC2374 */
memset(&in6, 0, sizeof(in6));
if (!memcmp(&sin6->sin6_addr.s6_addr[8],
&in6.s6_addr[8], 8))
plen = "64";
else
plen = "128";
}
}
if (plen) {
@ -995,6 +997,9 @@ getaddr(which, s, hpp)
{
struct addrinfo hints, *res;
q = NULL;
if (which == RTA_DST && (q = strchr(s, '/')) != NULL)
*q = '\0';
memset(&hints, 0, sizeof(hints));
hints.ai_family = afamily; /*AF_INET6*/
hints.ai_flags = AI_NUMERICHOST;
@ -1016,8 +1021,10 @@ getaddr(which, s, hpp)
}
#endif
freeaddrinfo(res);
if (q != NULL)
*q++ = '/';
if (which == RTA_DST)
if (inet6_makenetandmask(&su->sin6) == -1)
if (inet6_makenetandmask(&su->sin6, q) == -1)
return (1);
return (0);
}