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

后端 未结 2 1722
心在旅途
心在旅途 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

提交回复
热议问题