I am having a task in Hand to design a network messaging system using winpcap. I am trying to design it using a Decorator pattern. Say there is a class wrapping buffer called DataBuffer. There are other classes say EthernetPacket, IPPacket, TCPPacket/UdpPacket classes those are DataPacket and has Datapacket*.
class DataPackets
{
#pragma region MemberFunctions
public:
// public member functions
DataPackets();
DataPackets( unsigned int length_i);
virtual ~DataPackets();
void* GetInternalBuffer();
void SetInternalBuffer(Byte*& newBuffer, int buffer_length);
inline unsigned short GetBufferLength();
virtual E_DATA_PACKET_TYPE GetDataPacketType() { return m_data_packet_type; }
virtual void Packetize();
protected:
// Protected member functions
virtual void AddHeader();
private:
// Private member functions
#pragma endregion
#pragma region DataMembers
public:
// Public data members
protected:
// Protected Datamembers
E_DATA_PACKET_TYPE m_data_packet_type;
Byte* m_pData;
private:
// Private data members
unsigned short m_nDataLength;
unsigned short m_packet_count;
#pragma endregion
};
My confusion here is
1. Is this the correct pattern that i am using?
2. When each layer data header is added, then i have some extra bytes for example for a TCPHeader 20 bytes needed to be added at the beginning. For this i need to copy header and then the buffer to internal buffer to each layer. This seems not efficient. Is there any better way.
3. In IP layer, the internal packet will get splitted depending on the MTU of the network. So if the buffer is 65504 bytes,then there will be 44 IP layer packets. How to handle this?
What I have tried:
1. In data buffer layer, keep the header space empty. And in the TCP or UDP later copy the header. Here the issue is TCP header is 20 bytes where as the UDP layer header is just 8 bytes. How to handle this?
I am confused. Please help