summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
Diffstat (limited to 'src/net')
-rw-r--r--src/net/connectionhandler.cpp21
-rw-r--r--src/net/connectionhandler.hpp6
-rw-r--r--src/net/netcomputer.cpp17
3 files changed, 17 insertions, 27 deletions
diff --git a/src/net/connectionhandler.cpp b/src/net/connectionhandler.cpp
index 53ec3446..04bf0169 100644
--- a/src/net/connectionhandler.cpp
+++ b/src/net/connectionhandler.cpp
@@ -31,18 +31,6 @@
#include "script.h"
#endif
-
-std::string
-ip4ToString(unsigned int ip4addr)
-{
- std::stringstream ss;
- ss << (ip4addr & 0x000000ff) << "."
- << ((ip4addr & 0x0000ff00) >> 8) << "."
- << ((ip4addr & 0x00ff0000) >> 16) << "."
- << ((ip4addr & 0xff000000) >> 24);
- return ss.str();
-}
-
bool ConnectionHandler::startListen(enet_uint16 port)
{
// Bind the server to the default localhost.
@@ -93,12 +81,11 @@ void ConnectionHandler::process(enet_uint32 timeout)
switch (event.type) {
case ENET_EVENT_TYPE_CONNECT:
{
- LOG_INFO("A new client connected from " <<
- ip4ToString(event.peer->address.host) << ":" <<
- event.peer->address.port << " to port " <<
- host->address.port);
NetComputer *comp = computerConnected(event.peer);
clients.push_back(comp);
+ LOG_INFO("A new client connected from " << *comp << ":"
+ << event.peer->address.port << " to port "
+ << host->address.port);
// Store any relevant client information here.
event.peer->data = (void *)comp;
@@ -140,7 +127,7 @@ void ConnectionHandler::process(enet_uint32 timeout)
case ENET_EVENT_TYPE_DISCONNECT:
{
NetComputer *comp = (NetComputer *)event.peer->data;
- LOG_INFO(ip4ToString(event.peer->address.host) << " disconnected.");
+ LOG_INFO("" << *comp << " disconnected.");
// Reset the peer's client information.
computerDisconnected(comp);
clients.erase(std::find(clients.begin(), clients.end(), comp));
diff --git a/src/net/connectionhandler.hpp b/src/net/connectionhandler.hpp
index 76bea198..5787375a 100644
--- a/src/net/connectionhandler.hpp
+++ b/src/net/connectionhandler.hpp
@@ -32,12 +32,6 @@ class MessageOut;
class NetComputer;
/**
- * Convert a IP4 address into its string representation
- */
-std::string
-ip4ToString(unsigned int ip4addr);
-
-/**
* This class represents the connection handler interface. The connection
* handler will respond to connect/reconnect/disconnect events and handle
* incoming messages, passing them on to registered message handlers.
diff --git a/src/net/netcomputer.cpp b/src/net/netcomputer.cpp
index 3e4a4dbc..f0b677ec 100644
--- a/src/net/netcomputer.cpp
+++ b/src/net/netcomputer.cpp
@@ -29,6 +29,7 @@
#include "net/messageout.hpp"
#include "net/netcomputer.hpp"
#include "utils/logger.h"
+#include "utils/processorutils.hpp"
NetComputer::NetComputer(ENetPeer *peer):
mPeer(peer)
@@ -84,10 +85,18 @@ std::ostream&
operator <<(std::ostream &os, const NetComputer &comp)
{
// address.host contains the ip-address in network-byte-order
+ if (utils::processor::isLittleEndian)
+ os << ( comp.mPeer->address.host & 0x000000ff) << "."
+ << ((comp.mPeer->address.host & 0x0000ff00) >> 8) << "."
+ << ((comp.mPeer->address.host & 0x00ff0000) >> 16) << "."
+ << ((comp.mPeer->address.host & 0xff000000) >> 24);
+ else
+ // big-endian
+ // TODO: test this
+ os << ((comp.mPeer->address.host & 0x000000ff) << 24) << "."
+ << ((comp.mPeer->address.host & 0x0000ff00) << 16) << "."
+ << ((comp.mPeer->address.host & 0x00ff0000) << 8) << "."
+ << ((comp.mPeer->address.host & 0xff000000) << 0);
- os << ((comp.mPeer->address.host & 0xff000000) >> 24) << "."
- << ((comp.mPeer->address.host & 0x00ff0000) >> 16) << "."
- << ((comp.mPeer->address.host & 0x0000ff00) >> 8) << "."
- << ((comp.mPeer->address.host & 0x000000ff) >> 0);
return os;
}