working commit

This commit is contained in:
Олег Бородин
2026-05-20 18:04:31 +02:00
parent f2c0679255
commit 4bdd82ddb9
3 changed files with 13 additions and 6 deletions
+5 -5
View File
@@ -58,10 +58,10 @@ std::expected<std::string, std::string> network(const std::string network) {
return hostprefix[0]; return hostprefix[0];
} }
std::expected<std::string, std::string> nethost6(std::string network, uint prefix, uint32_t num); std::expected<std::string, std::string> nethost6(std::string network, uint prefix, uint64_t num);
std::expected<std::string, std::string> nethost4(std::string network, uint prefix, uint32_t num); std::expected<std::string, std::string> nethost4(std::string network, uint prefix, uint32_t num);
std::expected<std::string, std::string> nethost(std::string network, uint prefix, uint num) { std::expected<std::string, std::string> nethost(std::string network, uint prefix, uint64_t num) {
struct sockaddr_in sa; struct sockaddr_in sa;
if (inet_pton(AF_INET, network.data(), &(sa.sin_addr)) == 1) { if (inet_pton(AF_INET, network.data(), &(sa.sin_addr)) == 1) {
return nethost4(network, prefix, num); return nethost4(network, prefix, num);
@@ -71,13 +71,13 @@ std::expected<std::string, std::string> nethost(std::string network, uint prefix
return std::unexpected(std::format("Unknown network address {}", network)); return std::unexpected(std::format("Unknown network address {}", network));
} }
std::expected<std::string, std::string> nethost6(std::string network, uint prefix, uint32_t num) { std::expected<std::string, std::string> nethost6(std::string network, uint prefix, uint64_t num) {
struct in6_addr addr; struct in6_addr addr;
unsigned char mask[16] = {0}; unsigned char mask[16] = {0};
if (inet_pton(AF_INET6, network.data(), &addr) != 1) { if (inet_pton(AF_INET6, network.data(), &addr) != 1) {
return std::unexpected(std::format("Invalid network address {}", network)); return std::unexpected(std::format("Invalid network address {}", network));
} }
for (uint i = 0; i < prefix; i++) { for (uint64_t i = 0; i < prefix; i++) {
mask[i / 8] |= (1 << (7 - (i % 8))); mask[i / 8] |= (1 << (7 - (i % 8)));
} }
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
@@ -95,7 +95,7 @@ std::expected<std::string, std::string> nethost6(std::string network, uint prefi
return std::string(buffer); return std::string(buffer);
} }
std::expected<std::string, std::string> nethost4(std::string network, uint prefix, uint num) { std::expected<std::string, std::string> nethost4(std::string network, uint prefix, uint32_t num) {
struct in_addr inaddr; struct in_addr inaddr;
if (inet_pton(AF_INET, network.data(), &inaddr) != 1) { if (inet_pton(AF_INET, network.data(), &inaddr) != 1) {
return std::unexpected(std::format("Invalid network address {}", network)); return std::unexpected(std::format("Invalid network address {}", network));
+1 -1
View File
@@ -4,7 +4,7 @@
#include <expected> #include <expected>
#include <string> #include <string>
std::expected<std::string, std::string> nethost(std::string network, uint prefix, uint num); std::expected<std::string, std::string> nethost(std::string network, uint prefix, uint64_t num);
std::expected<uint, std::string> netprefix(const std::string network); std::expected<uint, std::string> netprefix(const std::string network);
std::expected<std::string, std::string> network(const std::string network); std::expected<std::string, std::string> network(const std::string network);
+7
View File
@@ -37,6 +37,13 @@ std::expected<void, std::string> TunService::Init(void) {
}; };
auto totalNets = totalHostsRes.value() / 4; auto totalNets = totalHostsRes.value() / 4;
uxlogger.Debug(std::format("Total networks: {}", totalNets)); uxlogger.Debug(std::format("Total networks: {}", totalNets));
for (uint64_t i = 0; i < totalNets; i += 4) {
auto laddrRes = nethost(netaddr, prefix, i + 1);
auto raddrRes = nethost(netaddr, prefix, i + 2);
auto laddr = laddrRes.value();
auto raddr = raddrRes.value();
uxlogger.Debug(std::format("Networks: {} {}", laddr, raddr));
}
return {}; return {};
} }