简体   繁体   中英

Wrong checksum in received udp packet


Problem:

  • I wrote sniffer on RAW socket. It catch udp packet and recheck checksum;
  • I wrote udp client on DGRAM socket. Its send udp packet on localhost;
  • The checksum of packet is wrong. It include only pseudo header.

Create client socket:

sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
raddr.sin_family = AF_INET;
raddr.sin_addr.s_addr = inet_addr("127.0.0.1");
raddr.sin_port = htons(4848);
sendto(sock, buf, 256, 0, (struct sockaddr*) &raddr, addrlen);

Create sniffer socket:

sock_raw = socket(AF_PACKET, SOCK_RAW, ETH_P_ALL);
struct sockaddr_ll *s = (struct sockaddr_ll*) &sll;
        s->sll_family = AF_PACKET;
        s->sll_ifindex = if_nametoindex("lo");
        s->sll_protocol = htons(protocol);
size = sizeof(struct sockaddr_ll);
bind(sock_raw, &sll, size);
data_size = recvfrom(sock_raw, buffer, BUFSZ, 0, NULL, NULL);

Note:
I don't create udp server on port 4848 and sniffer catch ICMP packet with unreachable port. I think reason of wrong checksum can be here.
I try PacketSender for send udp packet. And if server is not running (i have ICMP reply that port unreachable) checksum wrong again.

Please, somebody, can you explain me why checksum of udp packet = checksum pseudo udp header!?

PS: sorry for my spelling.

Update: TCP packet has wrong checksum too. Catch packet with wireshark.

I had the same problem with qemu + centos7, just set the offload off:

def set_iface_offload_off(ifname):
        print "setting %s offloading off" % ifname
        f = os.popen('/usr/sbin/ethtool --offload ' + ifname + ' rx off  tx off')
        f.close()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM