diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2009-09-11 15:04:47 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2009-09-11 15:04:47 +0200 |
commit | c18004e67869a9de88d9f8038a7a1957f20f63fc (patch) | |
tree | 67e1ae2e3886dfe4d8421fe0faf1e461dea14e04 /src | |
parent | 36a3a590ffa4133f7f2d980a57d48ef95c680b71 (diff) | |
download | mad-c18004e67869a9de88d9f8038a7a1957f20f63fc.tar mad-c18004e67869a9de88d9f8038a7a1957f20f63fc.zip |
Net: Add support for packets >64K
Need too secure this against DoS...
Diffstat (limited to 'src')
-rw-r--r-- | src/Net/Connection.cpp | 4 | ||||
-rw-r--r-- | src/Net/Packet.cpp | 4 | ||||
-rw-r--r-- | src/Net/Packet.h | 11 |
3 files changed, 10 insertions, 9 deletions
diff --git a/src/Net/Connection.cpp b/src/Net/Connection.cpp index 80a7163..f1beb35 100644 --- a/src/Net/Connection.cpp +++ b/src/Net/Connection.cpp @@ -96,7 +96,7 @@ void Connection::handleHeaderReceive(const boost::shared_array<boost::uint8_t> & enterReceiveLoop(); } else { - rawReceive(ntohs(header.length), boost::bind(&Connection::handleDataReceive, thisPtr.lock(), _1)); + rawReceive(ntohl(header.length), boost::bind(&Connection::handleDataReceive, thisPtr.lock(), _1)); } } @@ -104,7 +104,7 @@ void Connection::handleDataReceive(const boost::shared_array<boost::uint8_t> &da { boost::upgrade_lock<boost::shared_mutex> lock(connectionLock); - receiveSignal.emit(boost::shared_ptr<Packet>(new Packet(ntohs(header.requestId), data.get(), ntohs(header.length)))); + receiveSignal.emit(boost::shared_ptr<Packet>(new Packet(ntohs(header.requestId), data.get(), ntohl(header.length)))); } enterReceiveLoop(); diff --git a/src/Net/Packet.cpp b/src/Net/Packet.cpp index 3f32357..ca9cbee 100644 --- a/src/Net/Packet.cpp +++ b/src/Net/Packet.cpp @@ -22,11 +22,11 @@ namespace Mad { namespace Net { -Packet::Packet(boost::uint16_t requestId, const void *data, boost::uint16_t length) { +Packet::Packet(boost::uint16_t requestId, const void *data, boost::uint32_t length) { rawData = reinterpret_cast<Header*>(std::malloc(sizeof(Header)+length)); rawData->requestId = htons(requestId); - rawData->length = htons(length); + rawData->length = htonl(length); if(length) std::memcpy(reinterpret_cast<boost::uint8_t*>(rawData)+sizeof(Header), data, length); diff --git a/src/Net/Packet.h b/src/Net/Packet.h index 567c9c3..3844bad 100644 --- a/src/Net/Packet.h +++ b/src/Net/Packet.h @@ -38,15 +38,16 @@ namespace Net { class MAD_NET_EXPORT Packet { public: struct Header { + boost::uint32_t length; boost::uint16_t requestId; - boost::uint16_t length; + boost::uint16_t reserved; }; protected: Header *rawData; public: - Packet(boost::uint16_t requestId, const void *data = 0, boost::uint16_t length = 0); + Packet(boost::uint16_t requestId, const void *data = 0, boost::uint32_t length = 0); Packet(const Packet &p) { rawData = reinterpret_cast<Header*>(std::malloc(p.getRawDataLength())); @@ -63,8 +64,8 @@ class MAD_NET_EXPORT Packet { return ntohs(rawData->requestId); } - boost::uint16_t getLength() const { - return ntohs(rawData->length); + boost::uint32_t getLength() const { + return ntohl(rawData->length); } const boost::uint8_t* getData() const { @@ -76,7 +77,7 @@ class MAD_NET_EXPORT Packet { } unsigned long getRawDataLength() const { - return sizeof(Header) + ntohs(rawData->length); + return sizeof(Header) + getLength(); } }; |