@@ -18,8 +18,8 @@ namespace duckdb
1818 size_t slashPos = ipWithMask.find (' /' );
1919 std::string ip = ipWithMask.substr (0 , slashPos);
2020
21- // Default to /32 if no subnet mask is provided
22- int maskBits = 32 ;
21+ // Default to /24 if no subnet mask is provided
22+ int maskBits = 24 ;
2323 if (slashPos != std::string::npos)
2424 {
2525 std::string maskStr = ipWithMask.substr (slashPos + 1 );
@@ -58,18 +58,15 @@ namespace duckdb
5858
5959 if (maskBits != 32 )
6060 {
61- info.network = getNetworkAddress (ip, subnetMask);
61+ info.network = getNetworkAddress (ip, subnetMask, maskBits );
6262 info.broadcast = getBroadcastAddress (info.network , wildcardMask);
6363 info.hostMin = getHostMin (info.network );
6464 info.hostMax = getHostMax (info.broadcast );
6565 }
6666 else
6767 {
68- // For /32, the IP itself is the only host
69- info.network = ip;
70- info.broadcast = ip;
71- info.hostMin = ip;
72- info.hostMax = ip;
68+ // For /32, the IP itself is the only host ( Hostroute )
69+ info.network = ip;
7370 }
7471
7572 return info;
@@ -123,7 +120,7 @@ namespace duckdb
123120 return wildcard;
124121 }
125122
126- std::string IPCalculator::getNetworkAddress (const std::string &ip, const std::string &subnetMask)
123+ std::string IPCalculator::getNetworkAddress (const std::string &ip, const std::string &subnetMask, const int &maskBits )
127124 {
128125 auto ipOctets = parseIP (ip);
129126 auto maskOctets = parseIP (subnetMask);
@@ -132,7 +129,7 @@ namespace duckdb
132129 {
133130 network += std::to_string (ipOctets[i] & maskOctets[i]) + (i < 3 ? " ." : " " );
134131 }
135- return network;
132+ return network + " / " + std::to_string (maskBits) ;
136133 }
137134
138135 std::string IPCalculator::getBroadcastAddress (const std::string &networkAddress, const std::string &wildcardMask)
0 commit comments