@@ -1252,12 +1252,12 @@ CSubNet::CSubNet(const std::string &strSubnet, bool fAllowLookup)
1252
1252
std::string strNetmask = strSubnet.substr (slash + 1 );
1253
1253
int32_t n;
1254
1254
// IPv4 addresses start at offset 12, and first 12 bytes must match, so just offset n
1255
- int noffset = network.IsIPv4 () ? ( 12 * 8 ) : 0 ;
1255
+ const int astartofs = network.IsIPv4 () ? 12 : 0 ;
1256
1256
if (ParseInt32 (strNetmask, &n)) // If valid number, assume /24 symtex
1257
1257
{
1258
- if (n >= 0 && n <= (128 - noffset )) // Only valid if in range of bits of address
1258
+ if (n >= 0 && n <= (128 - astartofs* 8 )) // Only valid if in range of bits of address
1259
1259
{
1260
- n += noffset ;
1260
+ n += astartofs* 8 ;
1261
1261
// Clear bits [n..127]
1262
1262
for (; n < 128 ; ++n)
1263
1263
netmask[n>>3 ] &= ~(1 <<(n&7 ));
@@ -1271,12 +1271,10 @@ CSubNet::CSubNet(const std::string &strSubnet, bool fAllowLookup)
1271
1271
{
1272
1272
if (LookupHost (strNetmask.c_str (), vIP, 1 , false )) // Never allow lookup for netmask
1273
1273
{
1274
- // Remember: GetByte returns bytes in reversed order
1275
1274
// Copy only the *last* four bytes in case of IPv4, the rest of the mask should stay 1's as
1276
1275
// we don't want pchIPv4 to be part of the mask.
1277
- int asize = network.IsIPv4 () ? 4 : 16 ;
1278
- for (int x=0 ; x<asize; ++x)
1279
- netmask[15 -x] = vIP[0 ].GetByte (x);
1276
+ for (int x=astartofs; x<16 ; ++x)
1277
+ netmask[x] = vIP[0 ].ip [x];
1280
1278
}
1281
1279
else
1282
1280
{
@@ -1296,7 +1294,7 @@ bool CSubNet::Match(const CNetAddr &addr) const
1296
1294
if (!valid || !addr.IsValid ())
1297
1295
return false ;
1298
1296
for (int x=0 ; x<16 ; ++x)
1299
- if ((addr.GetByte (x) & netmask[15 - x]) != network.GetByte (x) )
1297
+ if ((addr.ip [x] & netmask[x]) != network.ip [x] )
1300
1298
return false ;
1301
1299
return true ;
1302
1300
}
0 commit comments