summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenning Brauer <henning@cvs.openbsd.org>2005-06-16 18:48:44 +0000
committerHenning Brauer <henning@cvs.openbsd.org>2005-06-16 18:48:44 +0000
commit336409460f65aa6f70387b5f6ce11b12b0d22ad0 (patch)
tree2c5efac4a7ec1fb22641c56fec2308c9ac765d9c
parentc199f848fd9ee5bdebd8c68028cab2d80a10deff (diff)
use prefixlen2mask which handles zero prefixlens right
-rw-r--r--usr.sbin/ospfctl/parser.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/usr.sbin/ospfctl/parser.c b/usr.sbin/ospfctl/parser.c
index b281f855b6b..68b7b042330 100644
--- a/usr.sbin/ospfctl/parser.c
+++ b/usr.sbin/ospfctl/parser.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.c,v 1.8 2005/05/12 19:10:12 norby Exp $ */
+/* $OpenBSD: parser.c,v 1.9 2005/06/16 18:48:43 henning Exp $ */
/*
* Copyright (c) 2004 Esben Norby <norby@openbsd.org>
@@ -293,7 +293,7 @@ parse_prefix(const char *word, struct in_addr *addr, u_int8_t *prefixlen)
if ((bits = inet_net_pton(AF_INET, word,
&ina, sizeof(ina))) == -1)
return (0);
- addr->s_addr = ina.s_addr & htonl(0xffffffff << (32 - bits));
+ addr->s_addr = ina.s_addr & htonl(prefixlen2mask(bits));
*prefixlen = bits;
return (1);
} else {
@@ -303,3 +303,13 @@ parse_prefix(const char *word, struct in_addr *addr, u_int8_t *prefixlen)
return (0);
}
+
+/* XXX local copy from kroute.c, should go to shared file */
+in_addr_t
+prefixlen2mask(u_int8_t prefixlen)
+{
+ if (prefixlen == 0)
+ return (0);
+
+ return (0xffffffff << (32 - prefixlen));
+}