459050b11ca2d48f26e358a5c7b2db587ffbd2ca galt Sat Jun 29 13:13:45 2019 -0700 Fixed minor bug found while testing new CIDR-enabled subnet filter for programs that listen for connections and filter clients. diff --git src/lib/internet.c src/lib/internet.c index 81cbc51..2b97abf 100644 --- src/lib/internet.c +++ src/lib/internet.c @@ -171,34 +171,33 @@ // does nothing at all rather than turning it to zeroes. if (bits == 32) end = packedIp; else end = packedIp | (((unsigned int) 0xFFFFFFFF) >> bits); *pStartIp = start; *pEndIp = end; } boolean internetIpInSubnetCidr(unsigned char unpackedIp[4], struct cidr *cidr) /* Return true if unpacked IP address is in subnet cidr. */ { bits32 subnetIp = cidr->ip; -//printf("packed32 bits=%u %08x\n", subnetIp, subnetIp); // DEBUG REMOVE int r = 32 - cidr->subnetLength; -bits32 caremask = subnetIp & (((unsigned int) 0xFFFFFFFF) << r); +bits32 caremask = ((unsigned int) 0xFFFFFFFF) << r; bits32 packedIp = internetPackIp(unpackedIp); if ((subnetIp & caremask) == (packedIp & caremask)) return TRUE; return FALSE; } static void notGoodSubnetCidr(char *sns) /* Complain about subnet format. */ { errAbort("'%s' is not a properly formatted subnet. Subnets must consist of\n" "one to four dot-separated numbers between 0 and 255 \n" "optionally followed by an slash and subnet bit length integer between 1 and 32.\n" "A trailing dot on the subnet IP address is not allowed.", sns);