To convert a subnet mask to an IP address range, you often need to convert the subnet mask to an IP address range for further computation. the conversion principle and Code are as follows: www.2cto.com is used to divide an IP address into a 'subnet number' and a 'host address' mask format [subnet number: 26bit] host address: 6bit 172.16.2.64/26 [10101100 00010000 00000010 000000 01] 10101100 172.16.2.96/26 [00010000 00000010 100000 01] 6bit host address, which can accommodate 63 numbers. then the range of the above two masks is the mask format IP address range 172.16.2.64/26 [172.16.2.64-172.16.2.127] 172.16.2.96/26 [172.16.2.96-172.16.2.127] * Previous subset 2 algorithm www.2cto.com Typedef struct {u_int32_t min; u_int32_t max;} ip_range_t; int str2iprange (ip_range_t * ipr, char * sipr) {char sip [16]; char smask [3]; sscanf (sipr, "% [^/]/% s", sip, smask); ipr-> min = ntohl (inet_addr (sip )); ipr-> max = (ipr-> min &~ (0x1 <(32-atoi (smask)-1) + (0x1 <(32-atoi (smask ))) -1);} test www.2cto.com ip_range_t ipr; str2iprange (& ipr, "172.16.2.94/24"); struct in_addr min = {htonl (ipr. min)}; printf ("% s-", inet_ntoa (min); struct in_addr max = {htonl (ipr. max)}; printf ("% s \ n", inet_ntoa (max); output result: 172.16.2.94-172.16.2.20.end