summaryrefslogtreecommitdiff
path: root/hscript/network.cc
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2020-02-09 09:00:02 -0600
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2020-02-09 09:00:02 -0600
commit5ef02583ecf0f2a954063eb80375b204f3433058 (patch)
tree6a0ec3e0b76e065deaa5387b37585493f4b247f4 /hscript/network.cc
parent72f84dd3dd00e792083906dbf50828c9b00d0221 (diff)
downloadhorizon-5ef02583ecf0f2a954063eb80375b204f3433058.tar.gz
horizon-5ef02583ecf0f2a954063eb80375b204f3433058.tar.bz2
horizon-5ef02583ecf0f2a954063eb80375b204f3433058.tar.xz
horizon-5ef02583ecf0f2a954063eb80375b204f3433058.zip
hscript: Factor subnet -> CIDR conversion to util function
* Also ensures that the unused function in util/net (is_url_valid) doesn't break the build of network.cc (and vis versa for user.cc).
Diffstat (limited to 'hscript/network.cc')
-rw-r--r--hscript/network.cc12
1 files changed, 3 insertions, 9 deletions
diff --git a/hscript/network.cc b/hscript/network.cc
index 49cebb5..c8bc93e 100644
--- a/hscript/network.cc
+++ b/hscript/network.cc
@@ -24,6 +24,7 @@
# define IFNAMSIZ 16
#endif
#include "network.hh"
+#include "util/net.hh"
#include "util/output.hh"
using namespace Horizon::Keys;
@@ -183,7 +184,8 @@ Key *NetAddress::parseFromData(const std::string &data, int lineno, int *errors,
/* There are two kinds of prefixes for IPv4: prefix length, like IPv6,
* and mask, which is the old style used by i.e. Windows. */
- if(::inet_pton(AF_INET, prefix.c_str(), &addr_buf) != 1) {
+ real_prefix = subnet_mask_to_cidr(prefix.c_str());
+ if(real_prefix < 1) {
try {
real_prefix = std::stoi(prefix);
} catch(const std::exception &) {
@@ -193,14 +195,6 @@ Key *NetAddress::parseFromData(const std::string &data, int lineno, int *errors,
"a network mask or prefix length is required");
return nullptr;
}
- } else {
- uint32_t tmp;
- memcpy(&tmp, addr_buf, 4);
- tmp = ntohl(tmp);
- real_prefix = 1;
- while((tmp <<= 1) & 0x80000000) {
- real_prefix++;
- }
}
if(real_prefix < 1 || real_prefix > 32) {