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];
}
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));