Click here to Skip to main content
15,893,190 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 11-Aug-18 11:46am

1 solution

Use the TCP-UDP support in .NET for your "managed" C++ app:

TCP-UDP | Microsoft Docs[^]
 
Share this answer
 
Comments
kuttiylajai 12-Aug-18 13:36pm    
I am using this system in high load data transmission network in a car. So when i am using sockets, i am getting packets drops. This is why i am planning to switch to WinPCAP. I tested this and frequency of drops have drastically reduced.In this case i was trying to create a network stack of my one. It would be great if you can give me some suggestions on what pattern to use to design a network stack. I thought of decorator because i need to know the basic pay load initially to to create a checksum in the case of TCP packet and IP Packet.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900