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 void CheckSize(const Data &packet, size_t requiredsize)
00034 {
00035 const Packet *p = (const Packet *) packet.GetData();
00036
00037
00038
00039 if( (btohs(p->size) != packet.GetSize() && packet.GetSize() <= 0xFFFF) ||
00040 packet.GetSize() < requiredsize )
00041
00042 {
00043 BadSize bs(btohs(p->size), packet.GetSize(), requiredsize);
00044 eout(bs.what());
00045 eout(packet);
00046 throw bs;
00047 }
00048 }
00049
00050 unsigned int GetSize(const Data &packet)
00051 {
00052 CheckSize(packet, 4);
00053
00054
00055
00056 if( packet.GetSize() > 0xFFFF ) {
00057 return packet.GetSize();
00058 }
00059 else {
00060 const Packet *p = (const Packet *) packet.GetData();
00061 return btohs(p->size);
00062 }
00063 }
00064
00065 }}
00066