Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "protocol.h"
00023 #include "protostructs.h"
00024 #include "data.h"
00025 #include "endian.h"
00026 #include "error.h"
00027 #include "debug.h"
00028
00029 #include <sstream>
00030
00031 namespace Barry { namespace Protocol {
00032
00033
00034
00035
00036 void CheckSize(const Data &packet, size_t requiredsize)
00037 {
00038 const Packet *p = (const Packet *) packet.GetData();
00039
00040
00041
00042 if( (packet.GetSize() >= 4 && btohs(p->size) != packet.GetSize() && packet.GetSize() <= 0xFFFF) ||
00043 packet.GetSize() < requiredsize )
00044
00045 {
00046 BadSize bs(packet.GetSize() >= 4 ? btohs(p->size) : 0,
00047 packet.GetSize(), requiredsize);
00048 eout(bs.what());
00049 eout(packet);
00050 throw bs;
00051 }
00052 }
00053
00054 unsigned int GetSize(const Data &packet)
00055 {
00056 CheckSize(packet, 4);
00057
00058
00059
00060 if( packet.GetSize() > 0xFFFF ) {
00061 return packet.GetSize();
00062 }
00063 else {
00064 const Packet *p = (const Packet *) packet.GetData();
00065 return btohs(p->size);
00066 }
00067 }
00068
00069 }}
00070