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

后端 未结 2 1712
心在旅途
心在旅途 2021-01-03 03:08

I am studying raw sockets. I used the IP_HDRINCL option to build my own IP headers. After the IP header, I am building a UDP header. Then I am sending the packet to my syste

相关标签:
2条回答
  • 2021-01-03 03:33

    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:

    • UDP: Checksum Computation
    • IETF: RFC 768
    0 讨论(0)
  • 2021-01-03 03:44

    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.

    0 讨论(0)
提交回复
热议问题