Merge pull request #2352 from leyyin/fix-compilation

Fix linux compilation
This commit is contained in:
Deve 2015-10-16 10:43:10 +02:00
commit 9b5e4e9201
3 changed files with 12 additions and 9 deletions

View File

@ -138,7 +138,7 @@ void ConnectToServer::asynchronousUpdate()
{ {
Log::info("ConnectToServer", "Server's address known"); Log::info("ConnectToServer", "Server's address known");
// we're in the same lan (same public ip address) !! // we're in the same lan (same public ip address) !!
if (m_server_address.getIP() == m_public_address.getIP()) if (m_server_address.getIP() == m_public_address.getIP())
Log::info("ConnectToServer", "Server appears to be in the same LAN."); Log::info("ConnectToServer", "Server appears to be in the same LAN.");
m_state = REQUESTING_CONNECTION; m_state = REQUESTING_CONNECTION;
m_current_protocol_id = m_listener->requestStart(new RequestConnection(m_server_id)); m_current_protocol_id = m_listener->requestStart(new RequestConnection(m_server_id));
@ -179,7 +179,7 @@ void ConnectToServer::asynchronousUpdate()
const char data[] = "aloha_stk\0"; const char data[] = "aloha_stk\0";
if (strcmp(data, (char*)(received_data)) == 0) if (strcmp(data, (char*)(received_data)) == 0)
{ {
Log::info("ConnectToServer", "LAN Server found : %s", Log::info("ConnectToServer", "LAN Server found : %s",
sender.toString().c_str()); sender.toString().c_str());
#ifndef WIN32 #ifndef WIN32
// just check if the ip is ours : if so, then just use localhost (127.0.0.1) // just check if the ip is ours : if so, then just use localhost (127.0.0.1)
@ -191,8 +191,10 @@ void ConnectToServer::asynchronousUpdate()
if (ifa->ifa_addr->sa_family==AF_INET) if (ifa->ifa_addr->sa_family==AF_INET)
{ {
sa = (struct sockaddr_in *) ifa->ifa_addr; sa = (struct sockaddr_in *) ifa->ifa_addr;
if (ntohl(sa->sin_addr.s_addr) == sender.m_ip) // this interface is ours
sender.m_ip = 0x7f000001; // 127.0.0.1 // This interface is ours
if (ntohl(sa->sin_addr.s_addr) == sender.getIP())
sender.setIP(0x7f000001); // 127.0.0.1
} }
} }
freeifaddrs(ifap); freeifaddrs(ifap);
@ -249,7 +251,7 @@ void ConnectToServer::asynchronousUpdate()
{ {
timer = StkTime::getRealTime(); timer = StkTime::getRealTime();
NetworkManager::getInstance()->connect(m_server_address); NetworkManager::getInstance()->connect(m_server_address);
Log::info("ConnectToServer", "Trying to connect to %s", Log::info("ConnectToServer", "Trying to connect to %s",
m_server_address.toString().c_str()); m_server_address.toString().c_str());
} }
break; break;

View File

@ -266,11 +266,11 @@ uint8_t* STKHost::receiveRawPacket(TransportAddress* sender)
} }
// we received the data // we received the data
sender->setIP( ntohl((uint32_t)(addr.sin_addr.s_addr)) ); sender->setIP( ntohl((uint32_t)(addr.sin_addr.s_addr)) );
sender->setPort( ntohs(addr.sin_port) ); sender->setPort( ntohs(addr.sin_port) );
if (addr.sin_family == AF_INET) if (addr.sin_family == AF_INET)
{ {
Log::info("STKHost", "IPv4 Address of the sender was %s", sender->toString()); Log::info("STKHost", "IPv4 Address of the sender was %s", sender->toString().c_str());
} }
STKHost::logPacket(NetworkString(std::string((char*)(buffer), len)), true); STKHost::logPacket(NetworkString(std::string((char*)(buffer), len)), true);
return buffer; return buffer;

View File

@ -51,12 +51,13 @@ class TransportAddress : public CallbackObject
private: private:
uint32_t m_ip; //!< The IPv4 address uint32_t m_ip; //!< The IPv4 address
uint16_t m_port; //!< The port number uint16_t m_port; //!< The port number
public: public:
/** Constructor. */ /** Constructor. */
TransportAddress(uint32_t ip = 0, uint16_t port = 0) TransportAddress(uint32_t ip = 0, uint16_t port = 0)
{ {
m_ip = ip; m_ip = ip;
m_port = port; m_port = port;
} // TransportAddress } // TransportAddress
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@ -111,7 +112,7 @@ public:
/** Compares if ip address and port are identical. */ /** Compares if ip address and port are identical. */
bool operator==(const TransportAddress& other) const bool operator==(const TransportAddress& other) const
{ {
return other.m_ip == m_ip && other.m_port == m_port; return other.m_ip == m_ip && other.m_port == m_port;
} // operator== } // operator==
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------