From 8cfa2f925a083cf6dc599f19bcba4e51b9a5c810 Mon Sep 17 00:00:00 2001 From: Daniel Butum Date: Fri, 16 Oct 2015 11:22:20 +0300 Subject: [PATCH] Fix linux compilation --- src/network/protocols/connect_to_server.cpp | 12 +++++++----- src/network/stk_host.cpp | 4 ++-- src/network/types.hpp | 5 +++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/network/protocols/connect_to_server.cpp b/src/network/protocols/connect_to_server.cpp index 002e79dd2..08de8cf6c 100644 --- a/src/network/protocols/connect_to_server.cpp +++ b/src/network/protocols/connect_to_server.cpp @@ -138,7 +138,7 @@ void ConnectToServer::asynchronousUpdate() { Log::info("ConnectToServer", "Server's address known"); // 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."); m_state = REQUESTING_CONNECTION; 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"; 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()); #ifndef WIN32 // 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) { 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); @@ -249,7 +251,7 @@ void ConnectToServer::asynchronousUpdate() { timer = StkTime::getRealTime(); 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()); } break; diff --git a/src/network/stk_host.cpp b/src/network/stk_host.cpp index 55fdefd91..aef9eeafb 100644 --- a/src/network/stk_host.cpp +++ b/src/network/stk_host.cpp @@ -266,11 +266,11 @@ uint8_t* STKHost::receiveRawPacket(TransportAddress* sender) } // we received the data 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) { - 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); return buffer; diff --git a/src/network/types.hpp b/src/network/types.hpp index a8d0a1584..34edf0f9a 100644 --- a/src/network/types.hpp +++ b/src/network/types.hpp @@ -51,12 +51,13 @@ class TransportAddress : public CallbackObject private: uint32_t m_ip; //!< The IPv4 address uint16_t m_port; //!< The port number + public: /** Constructor. */ TransportAddress(uint32_t ip = 0, uint16_t port = 0) { m_ip = ip; - m_port = port; + m_port = port; } // TransportAddress // ------------------------------------------------------------------------ @@ -111,7 +112,7 @@ public: /** Compares if ip address and port are identical. */ 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== // ------------------------------------------------------------------------