0

I need to write code that can determine if an IP address is in a subnet based one the subnet address and mask.

I don't even know where to begin with this, so any tips would be appreciated.

Thanks.

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by cableguy414
0

Okay, how about this.

Make a function that accepts an IP Address, and the Subnet (Subnet Address and Mask) and have it return a bool. It returns true if the IP Address exists in the subnet, or false if it doesn't.

bool ValidIP(const string& ipAddress, const string& subnetAddress, const string& mask){

// ...
   bool validIPAddress = false;
// ...

   return validIPAddress;

}

... Or are you asking about the algorithm to determine whether an IP Adress exists in the subnet or not?

Also, the following source(s) may help:

http://techpulp.com/2008/10/how-to-validate-ip-address-in-c/

http://beej.us/guide/bgnet/output/html/multipage/inet_ntopman.html

http://en.wikipedia.org/wiki/Subnetwork

http://www.subnet-calculator.com/

0

No, I need code to be able to check if a given IP address is within a certain network. Or, what the network address for a given IP is. Either way.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.