UDP概述:

UDP只是做了运输层协议能做的最少工作,仅做了复用/分解,少量的差错检验。

UDP是无连接的。

UDP优点:

  • 关于何时、发送什么数据的应用层控制更为精细:TCP在拥堵时会遏制发送方的发送;在发送失败时会持续发送直至成功
  • 无需建立连接:不会有建立连接的延迟
  • 无连接状态:需要在端系统中维护必要的参数
  • 分组头部开销小:8字节,而TCP需要20字节

UDP报文结构:

                  0      7 8     15 16    23 24    31
+--------+--------+--------+--------+
| Source | Destination |
| Port | Port |
+--------+--------+--------+--------+
| | |
| Length | Checksum |
+--------+--------+--------+--------+
|
| data octets ...
+---------------- ... User Datagram Header Format

首部(前两行):由四个字段组成,每个字段两个字节

  1. 源端口号:是可选的字段。当可用时用来指示发送方的端口号,或者再没有其他信息的情况下指向应答端口。当不使用时值为0
  2. 目的端口号:目的端口号
  3. 长度:UDP报文段中的字节数(首部加数据)
  4. 检验和:用于检测报文段中是否出现了差错
  1. Source Port is an optional field, when meaningful, it indicates the port of the sending process, and may be assumed to be the port to which a reply should be addressed in the absence of any other information. If not used, a value of zero is inserted.
  2. Destination Port has a meaning within the context of a particularinternet destination address.
  3. Length is the length in octets of this user datagram including thisheader and the data. (This means the minimum value of the length iseight.)
  4. Checksum is the 16-bit one's complement of the one's complement sum of apseudo header of information from the IP header, the UDP header, and thedata, padded with zero octets at the end (if necessary) to make amultiple of two octets.

伪首部(pseudo header):

伪首部并非UDP数据报中实际的有效成分,而是一个虚拟的数据结构,其中的信息是从数据报所在IP分组头的分组头中提取的,既不向下传送也不向上递交,而仅仅是为计算检验和。

伪头结构:

              0      7 8     15 16    23 24    31
+--------+--------+--------+--------+
| source address |
+--------+--------+--------+--------+
| destination address |
+--------+--------+--------+--------+
| zero |protocol| UDP length |
+--------+--------+--------+--------+

UDP检验和:

发送方将UDP报文(首部加数据)和伪头的16位比特字的和按位取反作为检验和放到检验和字段中。

求和过程中所有的溢出都要回卷。

接收方将接收到的报文和伪头(包含检验和)重新计算检验和,如果得到的结果为"FFFF"则说明没有出错。之所以是FFFF,是因为接收方的计算加上了发送方计算的检验和的按位反。

UDP仅提供差错检验,并没有恢复功能。但是可以在应用层进行人为添加。

参考来源:

https://datatracker.ietf.org/doc/rfc768/?include_text=1

《计算机网络:自顶向下方法》

最新文章

  1. COGS 2532. [HZOI 2016]树之美 树形dp
  2. 【原创】node+express+socket搭建一个实时推送应用
  3. WCF学习之旅——第一个WCF示例(一)
  4. SqlServer数据库大型应用解决方案总结
  5. kindEditor完整认识 PHP上调用并上传图片说明/////////////////////////////z
  6. zTree入门-最简单的树
  7. JavasSript实现秒转换为“天时分秒”控件和TDD测试方法应用
  8. jboss使用(eap 6.0以后版本)
  9. 在Image控件中绘制文字
  10. New Lantern Version Available Upgrade Lantern for improved blocking resistance!
  11. Navicat_Preminum
  12. Educational Codeforces Round 9
  13. leetcode first bad version python
  14. Java中String、StringBuilder以及StringBuffer
  15. python K-means工具包初解
  16. 9个Console控制台命令(转载)
  17. Linux工具参考篇(网摘)
  18. 使用logrotate分割tomcat日志
  19. Android SDK platforms build-tools等镜像下载
  20. magento登陆

热门文章

  1. 三步实现沉浸式状态栏(即状态栏与APP同色)
  2. 语法错误: unexpected ''); ?></span></span></h2> ' (T_CONSTANT_ENCAPSED_STRING), expecting ',' or ';'
  3. rest_framework-版本-总结完结篇
  4. [-] Failed to load plugin from /usr/share/metasploit-framework/plugins/db_autopwn: No classes were loaded from /usr/share/metasploit-framework/plugins/db_autopwn in the Msf::Plugin namespace.
  5. Metasploit的攻击实例讲解----辅助扫描工具
  6. FLUME KAFKA SOURCE 和 SINK 使用同一个 TOPIC
  7. 使用sysbench 对mysql进行性能测试
  8. 超轻便的 Cache_Lite 文件缓存
  9. NodeJS学习笔记 进阶 (6)本地调试远程服务器上的Node代码(ok)
  10. 洛谷3857 [TJOI2008]彩灯