File tree Expand file tree Collapse file tree 1 file changed +55
-0
lines changed
content/network/rfc768-udp Expand file tree Collapse file tree 1 file changed +55
-0
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ title : " RFC768 UDP包学习笔记"
3
+ date : " 2025-01-01 20:23:41"
4
+ draft : false
5
+ type : posts
6
+ tags :
7
+ - udp
8
+ categories :
9
+ - all
10
+ ---
11
+
12
+
13
+
14
+ # 包格式
15
+
16
+ UDP包头工占用8个字节, 其中源端口和目标端口各占2个字节,长度占2个字节,校验和占2个字节。
17
+
18
+ ```
19
+ 0 7 8 15 16 23 24 31
20
+ +--------+--------+--------+--------+
21
+ | Source | Destination |
22
+ | Port | Port |
23
+ +--------+--------+--------+--------+
24
+ | | |
25
+ | Length | Checksum |
26
+ +--------+--------+--------+--------+
27
+ |
28
+ | data octets ...
29
+ +---------------- ...
30
+
31
+ User Datagram Header Format
32
+ ```
33
+
34
+
35
+
36
+ # 字段
37
+
38
+ - ** 源端口** ,可选字段,默认为0,如果是有意义的其他端口,表示后续响应可以送回到该端口
39
+ - ** 目标端口** ,必须字段,用来关联目标主机上进程监听的端口
40
+ - ** 长度** ,长度是整个UDP包的长度,也就是包头 + 包的数据,包头固定8字节,那么length的最小长度就是8
41
+ - ** 校验和** ,用来验证传输过程中是否发生了错误。校验和的计算结果与源IP、目标IP、UDP的包长有关。 如果校验和失败,那么消息会被丢弃。 有些校验和计算的工作会被放置在网卡上,从而减少CPU的负载。当然如果在网卡上因为校验和的问题被网卡丢弃,上层应用是收不到不到UDP包的。但是用tcpdump可以抓到这种校验和有问题的包。
42
+
43
+
44
+
45
+ > 思考1: 为什么源端口可以设置为0?
46
+ >
47
+ > 答:有些UDP包,是不需要响应的,只需要发送出消息。
48
+
49
+
50
+
51
+ # 参考
52
+
53
+ - https://datatracker.ietf.org/doc/html/rfc768
54
+ - https://wdd.js.org/opensips/ch7/big-udp-msg/
55
+ - https://wdd.js.org/network/udp-checksum-offload/
You can’t perform that action at this time.
0 commit comments