Exemplo n.º 1
0
int ipinstance::determineGroup(std::string &user, int &fg)
{
	struct in_addr sin;
	inet_aton(user.c_str(), &sin);
	uint32_t addr = ntohl(sin.s_addr);
	// check straight IPs, subnets, and ranges
	fg = inList(addr);
	if (fg >= 0) {
#ifdef DGDEBUG
		std::cout << "Matched IP " << user << " to straight IP list" << std::endl;
#endif
		return DGAUTH_OK;
	}
	fg = inSubnet(addr);
	if (fg >= 0) {
#ifdef DGDEBUG
		std::cout << "Matched IP " << user << " to subnet" << std::endl;
#endif
		return DGAUTH_OK;
	}
	fg = inRange(addr);
	if (fg >= 0) {
#ifdef DGDEBUG
		std::cout << "Matched IP " << user << " to range" << std::endl;
#endif
		return DGAUTH_OK;
	}
#ifdef DGDEBUG
	std::cout << "Matched IP " << user << " to nothing" << std::endl;
#endif
	return DGAUTH_NOMATCH;
}
Exemplo n.º 2
0
// public
bool IPAddress::inSubnet(StringPiece cidrNetwork) const {
  auto subnetInfo = IPAddress::createNetwork(cidrNetwork);
  return inSubnet(subnetInfo.first, subnetInfo.second);
}