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.

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/

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.