Doesn't seem like that would be a very difficult function to program, though I honestly haven't gone looking through many libraries to see if that does exist. Did you do a Google search for this?
Yes, I did googling for this..
I got few solutions too..But they were too lengthy..
Eventually I've found out my own way to do it. I'd like to write here about it. May be helpful for other people.
e.g. CIDR is 192.168.9.0/24 and IP to check is 192.168.9.34.
step 1: convert 192.168.9.0 to unsigned long int by inet_aton function..Result will be LOWERIP.
step 2. calculate HIGHERIP = LOWERIP + (pow(2,32-mask value)-1)
Here mask value is 24 as per our example.
step 3. Convert your IP(address to check) in unigned long int format. Say it as MYIP
step 4. Now just check for LOWERIP < MYIP < HIGHERIP
If this is the case..then your IP present inside the range.