20 #include <arpa/inet.h> 22 #include "gateway/gateway.h" 23 #include "networkgatewayfunctions.h" 24 #include "networkgateway.h" 29 const std::string gatewayIP,
30 const int32_t containerID)
32 log_debug() <<
"Generating ip-address";
34 uint32_t internetAddress;
42 if (netmask > 31 || netmask < 1) {
47 uint32_t maskBits = (1L << (32 - netmask)) - 1;
49 if ( 1 != inet_pton(AF_INET, gatewayIP.c_str(), &internetAddress)) {
50 throw IPAllocationError(gatewayIP +
" does not represent a valid network address");
52 internetAddress = ntohl(internetAddress);
55 if ((internetAddress | maskBits) < (internetAddress + containerID + 1)) {
60 internetAddress += (containerID + 1);
61 internetAddress = htonl(internetAddress);
62 return internetAddress;
uint32_t generateIP(const uint32_t netmask, const std::string gatewayIP, const int32_t containerID)
Generate IP address for the container.
Developers guide to adding a config item: