c - 是否允许从截断的有效负载计算 UDP 校验和?

标签 c sockets networking udp protocols

UDP 套接字仅在具有正确校验和的情况下才接受传入的数据报。但我听说有时 UDP 数据包会因为最大传输单元 (MTU) 而被截断。

(1) 如何处理故意截断的数据报?是否允许在截断的有效负载上计算校验和?或者是否要求始终对应用程序打算在一个数据报中发送的整个数据计算校验和?

(2) 此外,是否允许数据报被分段,然后以另一个或不完整的顺序进行碎片整理?这会破坏校验和吗?

主要问题是:是否可以保证当接收到具有正确校验和的 UDP 数据报并将其传递给应用程序时,有效载荷正是发送方应用程序传递给操作系统的数据?

最佳答案

I've heard that sometimes UDP packets are truncated because of the Maximum Transmission Unit (MTU).

你听错了。由于这个原因,它们可以被分割

(1) How are datagrams handled that are truncated purposely?

它们并没有被截断,它们是支离 splinter 的。如果所有片段都到达,则可以重构数据报并验证其校验和。否则什么也不会发生。

Is it allowed that the checksum is calculated over a truncated payload?

不可能,见上文。

Or is it required that the checksum is always calculated over the whole data the application intended to send in one datagram?

是的。

(2) Also, is it allowed that a datagram is fragmented and then de-fragmented in another or incomplete order?

没有。

Would that corrupt the checksum?

它甚至不会发生。

The main question is: Is it guaranteed that when a UDP datagram is received with the right checksum and passed to the application, that the payload is exactly the data that the sender application passed to the OS?

是的。

关于c - 是否允许从截断的有效负载计算 UDP 校验和?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27661766/

相关文章:

Linux 套接字 : Zero-copy local, TCP/IP 远程

c++ - I/O 优化端口补全框架

复共轭转置matlab到C

c - 加入任何终止的线程

C如何比较未知类型的2个元素

python - 如何从python中的套接字编程中的另一个线程唤醒被select.poll.poll()函数阻塞的线程?

c - 打印列数和行数为奇数的数组的值

sockets - 监听对 UDP 多播消息的 UDP 单播回复

java - Netty channel 处理程序、线程和堆栈

Android - 在网络中查找服务器