From 4bdd82ddb9c952d6bc03a22648998a255bf91514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9E=D0=BB=D0=B5=D0=B3=20=D0=91=D0=BE=D1=80=D0=BE=D0=B4?= =?UTF-8?q?=D0=B8=D0=BD?= Date: Wed, 20 May 2026 18:04:31 +0200 Subject: [PATCH] working commit --- networkaux.cpp | 10 +++++----- networkaux.hpp | 2 +- tservice.cpp | 7 +++++++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/networkaux.cpp b/networkaux.cpp index 0065fdc..56d35f4 100644 --- a/networkaux.cpp +++ b/networkaux.cpp @@ -58,10 +58,10 @@ std::expected network(const std::string network) { return hostprefix[0]; } -std::expected nethost6(std::string network, uint prefix, uint32_t num); +std::expected nethost6(std::string network, uint prefix, uint64_t num); std::expected nethost4(std::string network, uint prefix, uint32_t num); -std::expected nethost(std::string network, uint prefix, uint num) { +std::expected nethost(std::string network, uint prefix, uint64_t num) { struct sockaddr_in sa; if (inet_pton(AF_INET, network.data(), &(sa.sin_addr)) == 1) { return nethost4(network, prefix, num); @@ -71,13 +71,13 @@ std::expected nethost(std::string network, uint prefix return std::unexpected(std::format("Unknown network address {}", network)); } -std::expected nethost6(std::string network, uint prefix, uint32_t num) { +std::expected nethost6(std::string network, uint prefix, uint64_t num) { struct in6_addr addr; unsigned char mask[16] = {0}; if (inet_pton(AF_INET6, network.data(), &addr) != 1) { 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))); } for (int i = 0; i < 16; i++) { @@ -95,7 +95,7 @@ std::expected nethost6(std::string network, uint prefi return std::string(buffer); } -std::expected nethost4(std::string network, uint prefix, uint num) { +std::expected nethost4(std::string network, uint prefix, uint32_t num) { struct in_addr inaddr; if (inet_pton(AF_INET, network.data(), &inaddr) != 1) { return std::unexpected(std::format("Invalid network address {}", network)); diff --git a/networkaux.hpp b/networkaux.hpp index 8946a7b..488aee8 100644 --- a/networkaux.hpp +++ b/networkaux.hpp @@ -4,7 +4,7 @@ #include #include -std::expected nethost(std::string network, uint prefix, uint num); +std::expected nethost(std::string network, uint prefix, uint64_t num); std::expected netprefix(const std::string network); std::expected network(const std::string network); diff --git a/tservice.cpp b/tservice.cpp index bf8ff84..0ece1fd 100644 --- a/tservice.cpp +++ b/tservice.cpp @@ -37,6 +37,13 @@ std::expected TunService::Init(void) { }; auto totalNets = totalHostsRes.value() / 4; 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 {}; }