原始套接字的数据包分片 [英] packet fragmentation for raw sockets

查看:222
本文介绍了原始套接字的数据包分片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用原始套接字发送大小为3000字节的UDP数据包,我需要在代码中自己处理数据包碎片,还是原始套接字句柄碎片应该类似于DGRAM套接字?

If I am using raw sockets to send a UDP packet of size 3000bytes, do I need to handle packet fragmentation myself in the code, or should the raw socket handle fragmentation similar to DGRAM socket?

推荐答案

好吧,如果你使用UDP,你真的不是发送RAW。 RAW是完全没有IP的,在这种情况下,你必须自己处理碎片。

Well, if you are using UDP, you aren't really sending RAW. RAW would be no IP at all, in which case yes you have to handle fragmentation yourself.

使用UDP你可以得到IP的碎片支持,这是IMHO足够好短-haul网络,其中碰撞应该是最小的。

With UDP you get IP's fragmentation support, which is IMHO plenty good enough for short-haul networks where collisions should be minimal. Make the link between the two systems a dedicated subnet, and it isn't an issue at all.

TCP通过UDP(以及其他方式)来获取你的TCP是一个专门的子网,能力只需要重新发送一个片段,如果它失去或hosed某种方式。使用UDP,如果发生这种情况,整个消息必须被丢弃。但是有一些开销,对于大多数现代网络,你可以用这种折衷方案。

What TCP buys you over UDP (among other things) is the stack's ability to just have to resend one fragment if it gets lost or hosed somehow. With UDP if that happens the entire message must be discarded. There's overhead with that though, and for most modern networks you can probably live with that trade-off.

这篇关于原始套接字的数据包分片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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