示例#1
0
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;
}
示例#2
0
void c_net_node::add_to_inbox (char *data, size_t size, const ip::address &source_address) {
	_info("add_to_inbox");
	std::lock_guard<std::mutex> lg(m_inbox_mutex);
	s_message message;
	message.m_data.assign(data, size);
	message.m_source_id = source_address.to_string();
	m_inbox.emplace_back(std::move(message));
}
示例#3
0
promise< mac::address >
arp_win32::resolve( const ip::address &ip_address )
{
	auto self	= false;
	auto ret	= promise< mac::address >();

	for ( auto nif : machine::self().nifs() )
	{
		if ( nif.address() == ip_address )
		{
			mac::address mac = nif.mac_address();

			runloop::shared().dispatch( [=]() mutable
			{
				ret.resolve( std::move( mac ) );
			} );

			self = true;
			break;
		}
	}

	if ( !self )
	{
		std::thread t( [=]() mutable
		{
			IPAddr			dest;
			ULONG			bytes[ 2 ];
			ULONG			len = sizeof( bytes );
			mac::address	mac;
			auto			err = std::error_code();

			ip_address >> dest;

			auto aerr = SendARP( dest, INADDR_ANY, &bytes, &len );
			ncheck_error_action( aerr == NO_ERROR, err = make_error_code( std::errc::no_such_device_or_address ), exit, "SendARP to % failed (%)", ip_address.to_string(), err );
			ncheck_error_action( len == 6, err = make_error_code( std::errc::no_such_device_or_address ), exit, "bad mac address size: %", len );
			mac = mac::address( reinterpret_cast< std::uint8_t* >( &bytes ), len );

			mlog( marker::arp, log::level_t::info, "% -> %", ip_address.to_string(), mac.to_string() );

		exit:

			runloop::shared().dispatch( [=]() mutable
			{
				if ( !err )
				{
					ret.resolve( std::move( mac ) );
				}
				else
				{
					ret.reject( err );
				}
			} );
		} );
示例#4
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 );
 }