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!?
P.S.: sorry for my spelling.
Update: TCP packet has wrong checksum too. Catch packet with wireshark.