tcp::endpoint const GetAddressForClient(Realm const& realm, ip::address const& clientAddr)
{
    ip::address realmIp;

    // Attempt to send best address for client
    if (clientAddr.is_loopback())
    {
        // Try guessing if realm is also connected locally
        if (realm.LocalAddress.is_loopback() || realm.ExternalAddress.is_loopback())
            realmIp = clientAddr;
        else
        {
            // Assume that user connecting from the machine that authserver is located on
            // has all realms available in his local network
            realmIp = realm.LocalAddress;
        }
    }
    else
    {
        if (clientAddr.is_v4() &&
                (clientAddr.to_v4().to_ulong() & realm.LocalSubnetMask.to_v4().to_ulong()) ==
                (realm.LocalAddress.to_v4().to_ulong() & realm.LocalSubnetMask.to_v4().to_ulong()))
        {
            realmIp = realm.LocalAddress;
        }
        else
            realmIp = realm.ExternalAddress;
    }

    tcp::endpoint endpoint(realmIp, realm.port);

    // Return external IP
    return endpoint;
}
Exemple #2
0
 bool IPAddress::isPrefixValid ( const std::string& p_prefix, const ::ip::address& p_address ) {
   uint8_t max_prefix = p_address.is_v4() ? 32 : 128;
   
   try {
     c_prefix_number = boost::lexical_cast<int>(p_prefix);
   } catch(boost::bad_lexical_cast &e) {
     return false;
   }
   
   return ( c_prefix_number >= 0 && c_prefix_number < max_prefix );
 }