diff options
Diffstat (limited to 'src/Net/Packet.h')
-rw-r--r-- | src/Net/Packet.h | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/Net/Packet.h b/src/Net/Packet.h index cd734a4..08bc9be 100644 --- a/src/Net/Packet.h +++ b/src/Net/Packet.h @@ -22,6 +22,7 @@ #include <cstdlib> #include <cstring> +#include <netinet/in.h> namespace Mad { namespace Net { @@ -48,10 +49,10 @@ class Packet { Packet(Type type, unsigned short requestId, const void *data = NULL, unsigned short length = 0) { rawData = (Data*)std::malloc(sizeof(Data)+length); - rawData->type = type; - rawData->requestId = requestId; + rawData->type = htons(type); + rawData->requestId = htons(requestId); rawData->reserved = 0; - rawData->length = length; + rawData->length = htons(length); if(length) std::memcpy(rawData->data, data, length); @@ -79,15 +80,15 @@ class Packet { } Type getType() const { - return (Type)rawData->type; + return (Type)ntohs(rawData->type); } unsigned short getRequestId() const { - return rawData->requestId; + return ntohs(rawData->requestId); } unsigned short getLength() const { - return rawData->length; + return ntohs(rawData->length); } const unsigned char* getData() const { @@ -99,7 +100,7 @@ class Packet { } unsigned long getRawDataLength() const { - return sizeof(Data) + rawData->length; + return sizeof(Data) + ntohs(rawData->length); } }; |