summaryrefslogtreecommitdiff
path: root/src/net/netcomputer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/netcomputer.cpp')
-rw-r--r--src/net/netcomputer.cpp17
1 files changed, 13 insertions, 4 deletions
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;
}