我写了一个程序来测试raw socket sento函数,我发现当我写一个错误的校验和的tcp消息时,我在wireshark中观察到一个正确的校验和,以下是我的程序:
int main()
{
int sock_raw_fd,len;
struct sockaddr_ll sll;
struct ifreq ethreq;
strncpy (ethreq.ifr_name, "eth0", (sizeof(ethreq.ifr_name) - 1));
ethreq.ifr_name[sizeof(ethreq.ifr_name)-1] = '\0';
sock_raw_fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
if(sock_raw_fd < 0){
perror("socket");
exit(1);
}
if(-1 == ioctl(sock_raw_fd, SIOCGIFINDEX, ðreq)){
perror("ioctl");
close(sock_raw_fd);
exit(1);
}
bzero(&sll, sizeof(sll));
sll.sll_ifindex = ethreq.ifr_ifindex;
unsigned char buf[size] = {0xF0,0xDE,0xF1,0x06,0x71,0x3A,0x00,0xE0,0x66,0xE2,0xEA,0xC0,0x08,0x00,0x45,0x00,0x05,0xDC,0x2B,0x5E,0x40,0x00,0x40,0x06,0x85,0xE9,0xC0,0xA8,0x01,0x0A,0xC0,0xA8,0x01,0x7A,0x09,0x79,0xD8,0xB7,0x27,0x6C,0x4C,0x2C,0xF5,0x9C,0xAB,0xC9,0x50,0x10,0x01,0x00,0xAB,0xC9,0x00,0x00,0x7C,0xC8,0xE8,0x89,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFF,0xFF,0xFE,0xFF,0xFF,0xFF,0xFD,0xFF,0xFD,0xFE,0xFF,0xFE,0xFE,0xFE,0xFE,0xFE,0xFD,0xFE,0xFF,0xFD,0xFE,0xFF,0xFF,0xFC,0xFF,0xFF,0xFD,0xFF,0xFE,0xFE,0xFF,0xFD,0xFE,0xFF,0xFE,0xFC,0xFE,0xFE,0xFD,0xFE,0xFE,0xFD,0xFF,0xFE,0xFC,0xFD,0xFE,0xFD,0xFE,0xFE,0xFC,0xFF,0xFE,0xFC,0xFE,0xFE,0xFC,0xFD,0xFE,0xFB,0xFF,0xFE,0xFC,0xFF,0xFE,0xFC,0xFF,0xFE,0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,0xDF,0xFB,0xF4,0xDE,0xFB,0xF3,0xDD,0xFB,0xF2,0xDE,0xFB,0xF3,0xDE,0xFB,0xF2,0xDE,0xFB,0xF3,0xDE,0xFB,0xF4,0xDD,0xFB,0xF4,0xDC,0xFB,0xF4,0xDD,0xFB,0xF4,0xDD,0xFB,0xF3,0xDC,0xFB,0xF2,0xDB,0xF9,0xF3,0xDC,0xFA,0xF3,0xDB,0xFA,0xF3,0xDA,0xF9,0xF3,0xDB,0xFA,0xF3,0xDA,0xFA,0xF3,0xDA,0xFA,0xF3,0xDA,0xFA,0xF3,0xDA,0xFA,0xF3,0xDA,0xC8,0xE8,0x89,0xC2,0xE6,0x7C,0x7A,0x92,0x4B,0x47,0x50,0x82,0x47,0x50,0x82,0x47,0x50,0x82,0x47,0x50,0x82,0x47,0x50,0x82,0x47,0x50,0x82,0x47,0x50,0x82,0x47,0x50,0x82,0x47,0x50,0x82,0x47,0x50,0x82,0x48,0x51,0x83,0x47,0x50,0x82,0x47,0x50,0x82,0x46,0x4F,0x81,0x46,0x4F,0x81,0x46,0x4F,0x81,0x46,0x4F,0x81,0x46,0x4F,0x81,0x46,0x4F,0x81,0x46,0x4F,0x81,0x46,0x4F,0x81,0x46,0x4F,0x81,0x46,0x4F,0x81,0x46,0x4F,0x81,0x46,0x4F,0x81,0x46,0x4F,0x81,0x48,0x4F,0x81,0x48,0x4F,0x81,0x48,0x4F,0x81,0x48,0x4F,0x81,0x47,0x4E,0x80,0x47,0x4E,0x80,0x47,0x4E,0x80,0x47,0x4E,0x80,0x47,0x4E,0x80,0x47,0x4E,0x80,0x47,0x4E,0x80,0x47,0x4E,0x80,0x47,0x4E,0x80,0x47,0x4E,0x80,0x47,0x4E,0x80,0x48,0x4F,0x81,0x48,0x4F,0x81,0x48,0x4F,0x81,0x48,0x4F,0x81,0x48,0x4F,0x81,0x48,0x4F,0x81,0x48,0x4F,0x81,0x47,0x4E,0x80,0x47,0x4E,0x80,0x47,0x4E,0x80,0x47,0x4E,0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F1,0xF9,0xF1,0xF1,0xF9,0xF1,0xF1,0xF9,0xF1,0xF1,0xF9,0xF1,0xF1,0xF9,0xF1,0xF1,0xF9,0xF1,0xF1,0xF9,0xF1,0xF1,0xF9,0xF1,0xF1,0xF9,0xF1,0xF1,0xF9,0xF1,0xF1,0xF9,0xF1,0xF1,0xF9,0xF1,0xF1,0xF9,0xF1,0xF1,0xF9,0xF1,0xF1,0xF9,0xF1,0xF1,0xF9,0xF1,0xF1,0xF9,0xF1,0xF1,0xF9,0xF1,0xF1,0xF9,0xF1,0xF1,0xF9,0xF1,0xF1,0xF9,0xF1,0xF1,0xF9,0xF1,0xF1,0xF9,0xF1,0xC2,0xE6,0x7C,0x7A,0x92,0x4B,0x4E,0x54,0x81,0x4E,0x54,0x83,0x4E,0x54,0x83,0x4E,0x54,0x83,0x4E,0x54,0x83,0x4E,0x54,0x83,0x4E,0x54,0x83,0x4E,0x54,0x83,0x4E,0x54,0x83,0x4F,0x55,0x84,0x4E,0x54,0x83,0x4E,0x54,0x83,0x4E,0x54,0x83,0x4E,0x54,0x83,0x4F,0x55,0x84,0x4F,0x55,0x84,0x4F,0x55,0x84,0x4F,0x55,0x84,0x4F,0x55,0x84,0x4F,0x55,0x84,0x4F,0x55,0x84,0x4E,0x54,0x83,0x4E,0x54,0x83,0x4E,0x54,0x83,0x4E,0x54,0x83,0x4E,0x54,0x83,0x4E,0x54,0x83,0x4E,0x54,0x83,0x4E,0x54,0x83,0x4F,0x55,0x84,0x4F,0x55,0x84,0x4F,0x55,0x84,0x4F,0x55,0x84,0x51,0x55,0x85,0x51,0x55,0x85,0x50,0x56,0x85,0x50,0x56,0x85,0x50,0x56,0x85,0x50,0x56,0x85,0x4E,0x56,0x85,0x4E,0x56,0x85,0x4E,0x56,0x85,0x4E,0x56,0x85,0x4C,0x56,0x85,0x4C,0x56,0x85,0x4C,0x56,0x85,0x4C,0x56,0x85,0x4A,0x57,0x85,0x4A,0x57,0x85,0x4E,0x56,0x85,0x4E,0x56,0x85,0x4E,0x56,0x85,0x4E,0x56,0x85,0x4E,0x56,0x85,0x4E,0x56,0x85,0x4E,0x56,0x85,0x4E,0x56,0x85,0x4E,0x56,0x85,0x4E,0x56,0x85,0x4E,0x56,0x85,0x4E,0x56,0x85,0x4E,0xF2,0xF2,0xF2,0xF2,0xF2,0xF2,0xF2,0xF2,0xF2,0xF2,0xF2,0xF2,0xF2, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
len = sendto(sock_raw_fd, &buf[0], size, 0, (struct sockaddr*)&sll, sizeof(sll));
printf("send succeed: %d bytes\n",len);
return 0;
}
我发送的校验和是ABC9 但是我在wireshark中收到了这条消息 wireshark message
校验和是DEEA,它是正确的,我想看到校验和是ABC9而不正确,但我不知道如何设置原始套接字不改变我的校验和。
谢谢你!答案 0 :(得分:1)
我认为wireshark转储来自接收机器,而不是来自发送方,这可能是由于您的网卡正在进行校验和卸载。 您可以使用ethtool禁用该行为:
ethtool -K eth0 tx-checksum-ipv4 off
ethtool -K eth0 tx-checksum-ip-generic off
您现在可以使用
检查您的设置是否正确ethtool -k eth0