udp packet fragmentation for raw sockets(原始套接字的 udp 数据包分段)
问题描述
问题跟进原始套接字的数据包碎片
如果我有一个这样实现的原始套接字:
If I have a raw socket implemented as such:
if ((sip_socket = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0)
{
cout << "Unable to create the SIP sockets."<< sip_socket<<"
";
return -3;
}
if ( setsockopt(sip_socket, IPPROTO_IP, IP_HDRINCL, &one, sizeof(one)) == -1)
{
cerr << "Unable to set option to Raw Socket.
";
return -4;
};
如果我的数据包大小为 1756(不包括 IP 标头),我该如何设置 ipHdr->fragment_offset(16 位,包括 3 位标志)?
我是否需要准备两个数据包——一个大小为 1480,另一个大小为 276,然后在两个数据包上打 IP 标头?
how can I set the ipHdr->fragment_offset (16 bits including 3 bit flags) if I have a packet of size 1756 (not including the IP header)?
Do I need to prepare two packets-one of size 1480 and another of size 276, and then slap IP headers on both packets?
谁能指出一个示例代码?
Can anyone point to an example code for this?
推荐答案
是的,你需要准备两个包,每个包都有自己的IP头.
Yes, you need to prepare two packets, each with their own IP header.
如果您在第一个数据包中放入 1480 个字节的数据,在第二个数据包中放入 276 个字节,那么 IP 标头应该是相同的,除了这些字段:
If you put 1480 bytes of data in the first packet and 276 in the second, then the IP headers should be identical, except for these fields:
Fragment Offset:第一个包设置为0,第二个包设置为1480;Total Length:设置为1480加上第一个包的头长度,276加上第二个包的头长度;MF标志:在第一个包中设置为1,在第二个包中设置为0;标头校验和:根据不同的标头重新计算.
Fragment Offset: set to0in the first packet, and1480in the second;Total Length: set to 1480 plus the header length in the first packet, and 276 plus the header length in the second packet;MFflag: set to1in the first packet and0in the second;Header Checksum: Recalculated over the different headers as appropriate.
这篇关于原始套接字的 udp 数据包分段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:原始套接字的 udp 数据包分段
基础教程推荐
- CString 到 char* 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
