我使用pylibnet來構造和發送UDP數據包。我用這種方式構造的UDP數據包似乎都有無效的校驗和。例如:libnet創建帶有無效校驗和的UDP數據包
# python
Python 2.4.3 (#1, Sep 3 2009, 15:37:12)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import libnet
>>> from libnet.constants import *
>>>
>>> net = libnet.context(RAW4, 'venet0:0')
>>> ip = net.name2addr4('www.stackoverflow.com', RESOLVE)
>>> data = 'This is my payload.'
>>> udptag = net.build_udp(sp=54321, dp=54321, payload=data)
>>> packetlen = IPV4_H + UDP_H + len(data)
>>> iptag = net.autobuild_ipv4(len=packetlen, prot=IPPROTO_UDP, dst=ip)
>>>
>>> net.write()
捕獲上述數據包發送主機上揭示了一個無效的校驗:
# tcpdump -i venet0:0 -n -v -v port 54321
tcpdump: WARNING: arptype 65535 not supported by libpcap - falling back to cooked socket
tcpdump: listening on venet0:0, link-type LINUX_SLL (Linux cooked), capture size 96 bytes
08:16:10.303719 IP (tos 0x0, ttl 64, id 1, offset 0, flags [none], proto: UDP (17), length: 47) 192.168.55.10.54321 > 69.59.196.211.54321: [bad udp cksum 50c3!] UDP, length 0
我錯了在這裏做什麼?
謝謝。我剛剛通過在接收主機上捕獲這些數據包進行了調查。校驗和在接收主機上也是不好的(並且在發送主機上的捕獲中觀察到相同的值)。所以它看起來不像校驗和卸載是這裏的答案。 – Mox 2009-12-15 19:28:14
如果接收主機實現了標準協議棧,或者兩臺主機之間至少有一臺路由器,則數據包永遠不會在接收主機上可見。其他事情正在發生。 – 2009-12-15 22:40:53