diff options
| author | luigi1111 <luigi1111w@gmail.com> | 2019-07-24 13:47:41 -0500 |
|---|---|---|
| committer | luigi1111 <luigi1111w@gmail.com> | 2019-07-24 13:47:41 -0500 |
| commit | 1880c1a58290cde589fe6db1062284ddba294483 (patch) | |
| tree | 896c03bef52795675c79bbd421b8f47c5fab869e /src/net/parse.cpp | |
| parent | 97ffc6dabdcd12be221d1f710d346d99f55f8ea8 (diff) | |
| parent | 65c40049633f0c5db3c24af8716bb683520f368c (diff) | |
| download | monzero-core-1880c1a58290cde589fe6db1062284ddba294483.tar.gz monzero-core-1880c1a58290cde589fe6db1062284ddba294483.tar.xz monzero-core-1880c1a58290cde589fe6db1062284ddba294483.zip | |
Merge pull request #5363
515ac29 p2p: store network address directly in blocked host list (moneromooo-monero)
65c4004 allow blocking whole subnets (moneromooo-monero)
Diffstat (limited to 'src/net/parse.cpp')
| -rw-r--r-- | src/net/parse.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/net/parse.cpp b/src/net/parse.cpp index eaaadb67e..d93d7d352 100644 --- a/src/net/parse.cpp +++ b/src/net/parse.cpp @@ -58,4 +58,27 @@ namespace net return {epee::net_utils::ipv4_network_address{ip, port}}; return make_error_code(net::error::unsupported_address); } + + expect<epee::net_utils::ipv4_network_subnet> + get_ipv4_subnet_address(const boost::string_ref address, bool allow_implicit_32) + { + uint32_t mask = 32; + const boost::string_ref::size_type slash = address.find_first_of('/'); + if (slash != boost::string_ref::npos) + { + if (!epee::string_tools::get_xtype_from_string(mask, std::string{address.substr(slash + 1)})) + return make_error_code(net::error::invalid_mask); + if (mask > 32) + return make_error_code(net::error::invalid_mask); + } + else if (!allow_implicit_32) + return make_error_code(net::error::invalid_mask); + + std::uint32_t ip = 0; + boost::string_ref S(address.data(), slash != boost::string_ref::npos ? slash : address.size()); + if (!epee::string_tools::get_ip_int32_from_string(ip, std::string(S))) + return make_error_code(net::error::invalid_host); + + return {epee::net_utils::ipv4_network_subnet{ip, (uint8_t)mask}}; + } } |
