打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
UDP checksum计算方法 (附详细例子)
userphoto

2012.05.11

关注

文章来自: http://irw.ncut.edu.tw/peterju/internet.html#udp

udp checksum的計算

提示:
1.UDP的Pseudo Header會用到 IP 封包中的 Sorurce Address, Destination Address, 與 Protocol。
2.UDP Length會在Pseudo Header與UDP Header中各出現1次,也就是說會被計算2次。《== (注意
3.若Data的長度若非Word(2 Bytes)的倍數,則必須在最後面補一個 byte的padding「0」。

假設有一封包資料如下

 

  1. // ------- BEGIN Ethernet HEADER ----------------------------   
  2. 00 09 5b 4f 64 72 // Destination HW address   
  3. 00 07 95 e7 79 2d // Src HW address   
  4. 08 00 // Type (not really sure what this octet's for)   
  5. // ------- BEGIN IP HEADER ----------------------------   
  6. 45 // IP version (IPv4)   
  7. 00 // Differentiated Services Code Point (i have no idea what this octet is for)   
  8. 00 38 // Total Length (of the packet?)   
  9. 5d 02 // ID (not really sure what this octet's for)   
  10. 00 00 // Fragmentation offset   
  11. 80 // Time To Live (in network hops)   
  12. 11 // Protocol (UDP)   
  13. 33 d6 // IP Header Checksum   
  14. c0 a8 00 02 // Source IP   
  15. c0 f6 28 3c // Destination IP   
  16. // ------- BEGIN UDP HEADER ---------------------------   
  17. 6d 38 // Source Port   
  18. 6d 2e // Destination Port   
  19. 00 24 // Length (of the UDP Packet?)   
  20. 29 b5 // UDP Checksum   
  21. ff ff ff ff // Marker (part of the packet data, no idea what it's for)   
  22. 67 65 74 73 65 72 76 65 72 73 20 38 32 20 66 75 6c 6c 20 65 6d 70 74 79 // Packet Data  

 

將上述資料以2byte為一組(16 bits)予以加總(Pseudo Header, UDP Header, UDP Data)

 

  1. c0a8 + 0002 + c0f6 + 283c + // Source IP, Dest IP   
  2. 0011 + // Protocol   
  3. 0024 + // UDP length   
  4. 6d38 + 6d2e + // Source Port, Dest Port   
  5. 0024 + // UDP length   
  6. 0000 + // empty checksum   
  7. ffff + ffff + 6765 + 7473 + 6572 + 7665 + 7273 + 2038 + 3220 + 6675 + 6c6c + 2065 + 6d70 + 7479 // Data   
  8. = 8d642  

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
IP数据包分析与解析
802.3/TCP/UDP包头结构
tcpip详解笔记(6) icmp协议
hping
为什么UDP需要有长度字段,而TCP不需要长度字段呢?
UDP 协议校验和计算
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服