working commit
This commit is contained in:
+5
-5
@@ -58,10 +58,10 @@ std::expected<std::string, std::string> network(const std::string network) {
|
||||
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> 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;
|
||||
if (inet_pton(AF_INET, network.data(), &(sa.sin_addr)) == 1) {
|
||||
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));
|
||||
}
|
||||
|
||||
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;
|
||||
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<std::string, std::string> nethost6(std::string network, uint prefi
|
||||
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;
|
||||
if (inet_pton(AF_INET, network.data(), &inaddr) != 1) {
|
||||
return std::unexpected(std::format("Invalid network address {}", network));
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
#include <expected>
|
||||
#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<std::string, std::string> network(const std::string network);
|
||||
|
||||
|
||||
@@ -37,6 +37,13 @@ std::expected<void, std::string> 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 {};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user