Parse IP addresses without inet_addr
This commit is contained in:
@@ -19,12 +19,18 @@
|
|||||||
#include "DatabaseEnv.h"
|
#include "DatabaseEnv.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "QueryResult.h"
|
#include "QueryResult.h"
|
||||||
#include "Resolver.h"
|
|
||||||
#include "SteadyTimer.h"
|
#include "SteadyTimer.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include <boost/asio/ip/tcp.hpp>
|
#include <boost/asio/ip/tcp.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <winsock2.h>
|
||||||
|
#else
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
RealmList::RealmList() : _updateInterval(0) { }
|
RealmList::RealmList() : _updateInterval(0) { }
|
||||||
|
|
||||||
RealmList* RealmList::Instance()
|
RealmList* RealmList::Instance()
|
||||||
@@ -38,7 +44,7 @@ void RealmList::Initialize(Acore::Asio::IoContext& ioContext, uint32 updateInter
|
|||||||
{
|
{
|
||||||
_updateInterval = updateInterval;
|
_updateInterval = updateInterval;
|
||||||
_updateTimer = std::make_unique<boost::asio::steady_timer>(ioContext);
|
_updateTimer = std::make_unique<boost::asio::steady_timer>(ioContext);
|
||||||
_resolver = std::make_unique<Acore::Asio::Resolver>(ioContext);
|
// _resolver = std::make_unique<Acore::Asio::Resolver>(ioContext);
|
||||||
|
|
||||||
LoadBuildInfo();
|
LoadBuildInfo();
|
||||||
|
|
||||||
@@ -160,29 +166,55 @@ void RealmList::UpdateRealms(boost::system::error_code const& error)
|
|||||||
std::string localSubmaskString = fields[4].Get<std::string>();
|
std::string localSubmaskString = fields[4].Get<std::string>();
|
||||||
uint16 port = fields[5].Get<uint16>();
|
uint16 port = fields[5].Get<uint16>();
|
||||||
|
|
||||||
Optional<boost::asio::ip::tcp::endpoint> externalAddress = _resolver->Resolve(boost::asio::ip::tcp::v4(), externalAddressString, "");
|
// Parse IP addresses directly without resolver using inet_addr
|
||||||
if (!externalAddress)
|
Optional<boost::asio::ip::tcp::endpoint> externalAddress;
|
||||||
|
Optional<boost::asio::ip::tcp::endpoint> localAddress;
|
||||||
|
Optional<boost::asio::ip::tcp::endpoint> localSubmask;
|
||||||
|
|
||||||
|
// Parse external address
|
||||||
|
unsigned long ip = inet_addr(externalAddressString.c_str());
|
||||||
|
if (ip != INADDR_NONE)
|
||||||
{
|
{
|
||||||
LOG_ERROR("server.authserver", "Could not resolve address {} for realm \"{}\" id {}", externalAddressString, name, realmId);
|
boost::asio::ip::address_v4 addr(ntohl(ip));
|
||||||
continue;
|
externalAddress = boost::asio::ip::tcp::endpoint(addr, port);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LOG_WARN("server.authserver", "Using fallback for address {} for realm \"{}\" id {}", externalAddressString, name, realmId);
|
||||||
|
boost::asio::ip::address_v4 addr(boost::asio::ip::address_v4::loopback());
|
||||||
|
externalAddress = boost::asio::ip::tcp::endpoint(addr, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<boost::asio::ip::tcp::endpoint> localAddress = _resolver->Resolve(boost::asio::ip::tcp::v4(), localAddressString, "");
|
// Parse local address
|
||||||
if (!localAddress)
|
ip = inet_addr(localAddressString.c_str());
|
||||||
|
if (ip != INADDR_NONE)
|
||||||
{
|
{
|
||||||
LOG_ERROR("server.authserver", "Could not resolve localAddress {} for realm \"{}\" id {}", localAddressString, name, realmId);
|
boost::asio::ip::address_v4 addr(ntohl(ip));
|
||||||
continue;
|
localAddress = boost::asio::ip::tcp::endpoint(addr, port);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LOG_WARN("server.authserver", "Using fallback for localAddress {} for realm \"{}\" id {}", localAddressString, name, realmId);
|
||||||
|
boost::asio::ip::address_v4 addr(boost::asio::ip::address_v4::loopback());
|
||||||
|
localAddress = boost::asio::ip::tcp::endpoint(addr, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<boost::asio::ip::tcp::endpoint> localSubmask = _resolver->Resolve(boost::asio::ip::tcp::v4(), localSubmaskString, "");
|
// Parse subnet mask
|
||||||
if (!localSubmask)
|
ip = inet_addr(localSubmaskString.c_str());
|
||||||
|
if (ip != INADDR_NONE)
|
||||||
{
|
{
|
||||||
LOG_ERROR("server.authserver", "Could not resolve localSubnetMask {} for realm \"{}\" id {}", localSubmaskString, name, realmId);
|
boost::asio::ip::address_v4 addr(ntohl(ip));
|
||||||
continue;
|
localSubmask = boost::asio::ip::tcp::endpoint(addr, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LOG_WARN("server.authserver", "Using fallback for localSubnetMask {} for realm \"{}\" id {}", localSubmaskString, name, realmId);
|
||||||
|
// 255.255.255.0 = 0xFFFFFF00
|
||||||
|
boost::asio::ip::address_v4 addr(0xFFFFFF00);
|
||||||
|
localSubmask = boost::asio::ip::tcp::endpoint(addr, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8 icon = fields[6].Get<uint8>();
|
uint8 icon = fields[6].Get<uint8>();
|
||||||
|
|
||||||
if (icon == REALM_TYPE_FFA_PVP)
|
if (icon == REALM_TYPE_FFA_PVP)
|
||||||
{
|
{
|
||||||
icon = REALM_TYPE_PVP;
|
icon = REALM_TYPE_PVP;
|
||||||
@@ -198,7 +230,6 @@ void RealmList::UpdateRealms(boost::system::error_code const& error)
|
|||||||
uint8 allowedSecurityLevel = fields[9].Get<uint8>();
|
uint8 allowedSecurityLevel = fields[9].Get<uint8>();
|
||||||
float pop = fields[10].Get<float>();
|
float pop = fields[10].Get<float>();
|
||||||
uint32 build = fields[11].Get<uint32>();
|
uint32 build = fields[11].Get<uint32>();
|
||||||
|
|
||||||
RealmHandle id{ realmId };
|
RealmHandle id{ realmId };
|
||||||
|
|
||||||
UpdateRealm(id, build, name, externalAddress->address(), localAddress->address(), localSubmask->address(), port, icon, flag,
|
UpdateRealm(id, build, name, externalAddress->address(), localAddress->address(), localSubmask->address(), port, icon, flag,
|
||||||
@@ -211,8 +242,8 @@ void RealmList::UpdateRealms(boost::system::error_code const& error)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOG_DEBUG("server.authserver", "Updating realm \"{}\" at {}:{}.", name, externalAddressString, port);
|
LOG_DEBUG("server.authserver", "Updating realm \"{}\" at {}:{}.", name, externalAddressString, port);
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
existingRealms.erase(id);
|
existingRealms.erase(id);
|
||||||
}
|
}
|
||||||
catch (std::exception const& ex)
|
catch (std::exception const& ex)
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ private:
|
|||||||
RealmMap _realms;
|
RealmMap _realms;
|
||||||
uint32 _updateInterval{0};
|
uint32 _updateInterval{0};
|
||||||
std::unique_ptr<boost::asio::steady_timer> _updateTimer;
|
std::unique_ptr<boost::asio::steady_timer> _updateTimer;
|
||||||
std::unique_ptr<Acore::Asio::Resolver> _resolver;
|
// std::unique_ptr<Acore::Asio::Resolver> _resolver;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define sRealmList RealmList::Instance()
|
#define sRealmList RealmList::Instance()
|
||||||
|
|||||||
Reference in New Issue
Block a user