From 99b4f4586ef6a78405c74623c46bfe8ff0964ea6 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: Tue, 19 May 2026 14:39:27 +0200 Subject: [PATCH] working commit --- works/hostcap.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 works/hostcap.cpp diff --git a/works/hostcap.cpp b/works/hostcap.cpp new file mode 100644 index 0000000..0c8d2a2 --- /dev/null +++ b/works/hostcap.cpp @@ -0,0 +1,36 @@ +#include +#include +#include + +extern "C" { +#include +} + +int netcapa4(const std::string& ipStr, int prefix) { + //uint32_t ipAddress; + //inet_pton(AF_INET, ipStr.data(), &ipAddress); + //ipAddress = ntohl(ipAddress); + + int hostBits = 32 - prefix; + uint64_t totalIPs = std::pow(2, hostBits); + //uint64_t usableHosts = (prefix < 31) ? (totalIPs - 2) : totalIPs; + + //uint32_t subnetMask = (prefix == 0) ? 0 : (~0U << hostBits); + //uint32_t networkAddress = ipAddress & subnetMask; + + //struct in_addr netAddr; + //netAddr.s_addr = htonl(networkAddress); + //char netStr[INET_ADDRSTRLEN]; + //inet_ntop(AF_INET, &netAddr, netStr, INET_ADDRSTRLEN); + + //std::cout << "Total IPs: " << totalIPs << "\n"; + //std::cout << "Usable Hosts: " << usableHosts << "\n"; + return totalIPs; +} + +int main() { + auto capa = netcapa4("192.168.1.10", 24); + std::cout << "Total IPs: " << capa << "\n"; + return 0; +} +