diff options
author | Rogier Polak <rogier.l.a.polak@gmail.com> | 2007-03-11 00:39:29 +0000 |
---|---|---|
committer | Rogier Polak <rogier.l.a.polak@gmail.com> | 2007-03-11 00:39:29 +0000 |
commit | 0a74cd8c92844e730cf6f56bdc3dd578c65a10d0 (patch) | |
tree | 8fc705e7b0b5edd35e82f53c3041a09a16eb09e5 /src/net/netcomputer.cpp | |
parent | 8b56248ef58323c6e28264b5317d39c22c59db04 (diff) | |
download | manaserv-0a74cd8c92844e730cf6f56bdc3dd578c65a10d0.tar.gz manaserv-0a74cd8c92844e730cf6f56bdc3dd578c65a10d0.tar.bz2 manaserv-0a74cd8c92844e730cf6f56bdc3dd578c65a10d0.tar.xz manaserv-0a74cd8c92844e730cf6f56bdc3dd578c65a10d0.zip |
Added a utils::processor namespace and a function to determine if, the processor the program is running on, is little-endian or big-endian.
Diffstat (limited to 'src/net/netcomputer.cpp')
-rw-r--r-- | src/net/netcomputer.cpp | 17 |
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; } |