473,402 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Determining whether given IP exist in CIDR IP Range

ashitpro
542 Expert 512MB
I want to check whether given IP exist in CIDR range..

e.g.

IP is 192.168.1.3
CIDR is 192.168.1.0/24

here according to CIDR
lower ip is 192.168.1.1
higher ip is 192.168.1.254

So if I give input as 192.168.1.3 and my cidr. It should return true.
Is there any facility in C/C++
Jan 30 '08 #1
2 6943
sicarie
4,677 Expert Mod 4TB
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?
Jan 30 '08 #2
ashitpro
542 Expert 512MB
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.
Jan 31 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: BigMan | last post by:
Are these two lines equivalent? #ifdef MACRO #if MACRO==0
9
by: Christopher Benson-Manica | last post by:
I have the following situation: Page A opens a window named 'foo'. Page A then reloads itself. Is there a way for the reloaded Page A to determine whether there is an open window named 'foo',...
3
by: Gareth Tonnessen | last post by:
I need to have a clean way to determine whether a query exists without trying to open it and getting an error message. Is there a simple way to determine whether an object exists in a database?...
2
by: Laszlo Szijarto | last post by:
Using reflection, I am iterating through an array of FieldInfo objects and wish to determine whether any given field represents a signed or an unsigned variable (makes a difference in terms of how...
4
by: Claire | last post by:
How do I determine whether Im running in debug or release mode from code please. thanks Claire
2
by: Dan | last post by:
How does one do this?
4
by: RossettoeCioccolato | last post by:
How do I determine programmatically whether or not the VC8 C/C++ SxS assemblies currently are installed on a system? Regards, Rossetoecioccolato.
4
by: ug26jhw | last post by:
Is there any way to determine whether an element in a document exists. I have some code like this where the variable i changes: if(document.getElementById('pref'+i).innerHTML... When it...
4
by: Nathan Sokalski | last post by:
When determining whether a String can be converted to a DateTime, you can use the IsDate() method. However, I would also like to know whether the string is a date, a time, or both a date and a...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.