Raw Socket Help: Why UDP packets created by raw sockets are not being received by kernel UDP?

老子叫甜甜 提交于 2019-11-30 14:45:59
hgolyeri

There seems to be a problem with the calculation of the UDP check-sum.

udp->check=in_cksum((unsigned short*) udp,8+strlen(data));

UDP check-sum must include something called the "Pseudo-Header" before the UDP header. The code calculates checksum over only the UDP header and the payload. The UDP receiving process might not be receiving the packets because of the wrong check-sums.

Enable check-sum validation in Wireshark and check whether the check-sum fields of the UDP packets are correct or not.

See the following:

Ive tried something very similar. The problem is that the socket API and by extension any programs that use them, donot return data that is being WRITTEN by the interface unlike raw sockets used by sniffers like wiresharks/tcpdump which do. So, even though your packets are formed correctly, they are not being read by the UDP application. If you have another computer on the network, use one to generate the traffic and the other to read it. Alternatively if you have two interfaces, you could open a raw socket on each... one for writing and the other for reading.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!