diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2009-08-18 15:58:17 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2009-08-18 15:58:17 +0200 |
commit | db5ad2e09a6b38e841463dbe7eb076492b62c948 (patch) | |
tree | 5907f6416e35cbd25432a5f1f6dc9664d36aa73c /src/Net/Packet.h | |
parent | 5da7b0847bac2a5abec95b9ac1701b74baae8964 (diff) | |
download | mad-db5ad2e09a6b38e841463dbe7eb076492b62c948.tar mad-db5ad2e09a6b38e841463dbe7eb076492b62c948.zip |
Mad funktioniert jetzt unter Windows
Diffstat (limited to 'src/Net/Packet.h')
-rw-r--r-- | src/Net/Packet.h | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/src/Net/Packet.h b/src/Net/Packet.h index dc62cb7..567c9c3 100644 --- a/src/Net/Packet.h +++ b/src/Net/Packet.h @@ -20,30 +20,36 @@ #ifndef MAD_NET_PACKET_H_ #define MAD_NET_PACKET_H_ +#include "export.h" + #include <cstdlib> #include <cstring> -#include <netinet/in.h> -#include <stdint.h> +#include <boost/cstdint.hpp> + +#ifdef _WIN32 +# include <winsock2.h> +#else +# include <netinet/in.h> +#endif namespace Mad { namespace Net { -class Packet { +class MAD_NET_EXPORT Packet { public: - struct Data { - uint16_t requestId; - uint16_t length; - uint8_t data[0]; + struct Header { + boost::uint16_t requestId; + boost::uint16_t length; }; protected: - Data *rawData; + Header *rawData; public: - Packet(uint16_t requestId, const void *data = 0, uint16_t length = 0); + Packet(boost::uint16_t requestId, const void *data = 0, boost::uint16_t length = 0); Packet(const Packet &p) { - rawData = (Data*)std::malloc(p.getRawDataLength()); + rawData = reinterpret_cast<Header*>(std::malloc(p.getRawDataLength())); std::memcpy(rawData, p.rawData, p.getRawDataLength()); } @@ -53,24 +59,24 @@ class Packet { Packet& operator=(const Packet &p); - uint16_t getRequestId() const { + boost::uint16_t getRequestId() const { return ntohs(rawData->requestId); } - uint16_t getLength() const { + boost::uint16_t getLength() const { return ntohs(rawData->length); } - const uint8_t* getData() const { - return rawData->data; + const boost::uint8_t* getData() const { + return reinterpret_cast<boost::uint8_t*>(rawData)+sizeof(Header); } - const Data* getRawData() const { - return rawData; + const boost::uint8_t* getRawData() const { + return reinterpret_cast<boost::uint8_t*>(rawData); } unsigned long getRawDataLength() const { - return sizeof(Data) + ntohs(rawData->length); + return sizeof(Header) + ntohs(rawData->length); } }; |