创建网络堆栈 [英] Creating a network stack

查看:99
本文介绍了创建网络堆栈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用winpcap设计网络消息系统。我正在尝试使用Decorator模式进行设计。假设有一个名为DataBuffer的类包装缓冲区。还有其他类说EthernetPacket,IPPacket,TCPPacket / UdpPacket类,它们是DataPacket并且有Datapacket *。



class DataPackets

{

#pragma region MemberFunctions

public:

//公共会员功能

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; }

虚拟空白Packetize();



受保护:

//受保护的成员函数

virtual void AddHeader();



private:

//私人会员功能



#pragma endregion



#pragma region DataMembers

public:

//公共数据成员



受保护:

//受保护的Datamembers

E_DATA_PACKET_TYPE m_data_packet_type;

Byte * m_pData;



private:

//私人数据成员

unsigned short m_nDataLength;

unsigned short m_packet_count;

#pragma endregion

};



我的困惑这是

1.这是我正在使用的正确模式吗?

2.当添加每个图层数据头时,我有一些额外的字节,例如a TCPHeader需要添加20个字节开始。为此,我需要将标头和缓冲区复制到每个层的内部缓冲区。这似乎效率不高。有没有更好的方法。

3.在IP层,内部数据包将根据网络的MTU进行分割。因此,如果缓冲区是65504字节,那么将有44个IP层数据包。如何处理?



我尝试过:



1在数据缓冲层中,将标题空间保留为空。然后在TCP或UDP中复制标头。这里的问题是TCP头是20个字节,其中UDP层头只有8个字节。如何处理?



我很困惑。请帮助

解决方案

在.NET中使用TCP-UDP支持托管C ++应用程序:



TCP-UDP | Microsoft Docs [ ^ ]

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

解决方案

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

TCP-UDP | Microsoft Docs[^]


这篇关于创建网络堆栈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆