Use alternate dns name if name resolution fails for internet server (6dns.org seems to be unreliable, but is still the only one to provide both ipv4 and ipv6 name resolution for free).

This commit is contained in:
lotodore
2007-11-30 21:28:38 +00:00
parent 3838b2e22f
commit b97c56cd26
5 changed files with 31 additions and 2 deletions
+5
View File
@@ -47,6 +47,10 @@ public:
{return m_serverAddr;}
void SetServerAddr(const std::string &serverAddr)
{m_serverAddr = serverAddr;}
const std::string &GetAlternateServerAddr() const
{return m_alternateServerAddr;}
void SetAlternateServerAddr(const std::string &serverAddr)
{m_alternateServerAddr = serverAddr;}
unsigned GetServerPort() const
{return m_serverPort;}
void SetServerPort(unsigned serverPort)
@@ -79,6 +83,7 @@ private:
int m_protocol;
int m_addrFamily;
std::string m_serverAddr;
std::string m_alternateServerAddr;
unsigned m_serverPort;
std::string m_password;
sockaddr_storage m_clientSockaddr;
+1
View File
@@ -48,6 +48,7 @@ public:
// (i.e. after starting the thread).
void Init(
const std::string &serverAddress,
const std::string &alternateServerAddress,
unsigned serverPort,
bool ipv6,
bool sctp,
+3 -1
View File
@@ -70,7 +70,8 @@ ClientThread::~ClientThread()
void
ClientThread::Init(
const string &serverAddress, unsigned serverPort, bool ipv6, bool sctp,
const string &serverAddress, const string &alternateServerAddress,
unsigned serverPort, bool ipv6, bool sctp,
const string &pwd, const string &playerName, const string &avatarFile)
{
if (IsRunning())
@@ -84,6 +85,7 @@ ClientThread::Init(
context.SetProtocol(sctp ? SOCKET_IPPROTO_SCTP : 0);
context.SetAddrFamily(ipv6 ? AF_INET6 : AF_INET);
context.SetServerAddr(serverAddress);
context.SetAlternateServerAddr(alternateServerAddress);
context.SetServerPort(serverPort);
context.SetPassword(pwd);
context.SetPlayerName(playerName);
+14
View File
@@ -45,6 +45,7 @@ ResolverThread::Init(const ClientContext &context)
GetContext().SetAddrFamily(context.GetAddrFamily());
GetContext().SetServerAddr(context.GetServerAddr());
GetContext().SetAlternateServerAddr(context.GetAlternateServerAddr());
GetContext().SetServerPort(context.GetServerPort());
}
@@ -78,6 +79,19 @@ ResolverThread::Main()
context.GetProtocol(),
(struct sockaddr *)context.GetClientSockaddr(),
context.GetClientSockaddrSize());
if (!m_retVal && !context.GetAlternateServerAddr().empty())
{
// Try alternate name.
m_retVal = socket_resolve(
context.GetAlternateServerAddr().c_str(),
tmpStr.str().c_str(),
context.GetAddrFamily(),
SOCK_STREAM,
context.GetProtocol(),
(struct sockaddr *)context.GetClientSockaddr(),
context.GetClientSockaddrSize());
}
}
const ClientContext &