working commit
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <cmath>
|
||||
|
||||
extern "C" {
|
||||
#include <arpa/inet.h>
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user