传输层 UDP/TCP
最后更新于:2022-04-02 04:06:51
[TOC]
## IP UDP TCP 关系
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/fa/7f/fa7febcdc66b95b3ecc8f71e45da1f02_960x464.png)
## IP报文
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/5b/95/5b958ee72a185f03135afce19906b174_1978x1164.png)
## UDP 报文
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/ee/31/ee3183f672d851f44aefdc6b53d1eb77_1132x452.png)
## TCP 的报文
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/67/87/678786472d246a108b0f741bfc6109f9_1562x654.png)
## 总结
ip 报文长度为20
udp 报文长度为16
tcp 报文长度为20
```
假设报文为 pack
ip+udp的报文:
ip = pack[:20]
udp = pack[20:20+8]
ip+tcp的报文长度:
ip = pack[:20]
udp = pack[20:20+20]
```
可以查看 python解析报文的示例
[python解析IP/TCP/UDP 报文](../../python/%E5%86%85%E7%BD%AE%E5%8C%85/struct%E5%A4%A7-%E5%B0%8F%E7%AB%AF%E5%BA%8F.md)
';