本帖最后由 ylsljp 于 2018-11-15 16:40 编辑
STM32+LWIP+ICMP ping电脑时,电脑接收到的icmp报文校验和跟我发送出去的不一样,求大神解救!!!!!!!!!!!!!!!!!!!!!!
为啥上存不了图片了,要一点一点的贴代码,好坑。。。。。。
struct raw_pcb *ping_pcb;
__IO uint16_t NetCheckTime = 0;
__IO uint32_t PingSeqNum = 0;
unsigned char Icmp_Init(void)
{
ping_pcb = raw_new(IP_PROTO_ICMP);
if(!ping_pcb)
{
return 0;
}
return 1;
}
//网络状态周期性检测
void Net_Periodic_Check(void)
{
if(NetCheckTime == 1000)
{
if(NetStates == ALLCATION) //已经分配了地址,开始ping网关
{
Ping_Send(); //ping内网
}
else if(NetStates == CONNINTER) //已经连上内网,开始ping外网
{
}
NetCheckTime = 0;
}
}
void Ping_Send(void)
{
struct pbuf *pbuff;
struct ip_addr ipAddr;
struct icmp_echo_hdr *iecho;
//本机IP
//ipAddr = netif.ip_addr;
IP4_ADDR(&ipAddr, 192, 168, 111, 44);
ip_addr_set(&ping_pcb->local_ip, &ipAddr);
//目标IP //ipAddr = netif.gw;
IP4_ADDR(&ipAddr, 192, 168, 111, 49);
ip_addr_set(&ping_pcb->remote_ip, &ipAddr);
pbuff = pbuf_alloc(PBUF_IP, sizeof(struct icmp_echo_hdr), PBUF_RAM);
if(!pbuff)
{
return;
}
//组装icmp的报文
iecho = (struct icmp_echo_hdr *)pbuff->payload;
iecho->type = 8; //类型
iecho->code = 0; //code
iecho->id = htons(0x8899); //id
iecho->seqno = htons(++PingSeqNum); //报文序列号
iecho->chksum = 0; //校验和清0
iecho->chksum = inet_chksum(pbuff->payload, sizeof(struct icmp_echo_hdr)); //重算校验和
//发送ping数据包
raw_sendto(ping_pcb, pbuff, &ping_pcb->remote_ip);
pbuf_free(pbuff);
}
在 raw_sendto(ping_pcb, pbuff, &ping_pcb->remote_ip) 发送icmp数据前,我在KEIL里Watch1上看到 iecho 的类型是8,code是0,校验和是0x656f,id是0x9988,序列号是0x0100。
但是电脑上用Wireshark抓到的数据跟发送的不一样,校验和不同,校验和变成0x0000了,
Internet Control Message Protocol
Type: 8 (Echo (ping) request)
Code: 0
Checksum: 0x0000 [incorrect, should be 0x6f65]
Identifier (BE): 34969 (0x8899)
Identifier (LE): 39304 (0x9988)
Sequence number (BE): 1 (0x0001)
Sequence number (LE): 256 (0x0100)
[No response seen]
[Expert Info (Warn/Sequence): No response seen to ICMP request in frame 10583]
[No response seen to ICMP request in frame 10583]
[Severity level: Warn]
[Group: Sequence]
求大神解救!!!!!!!!!!!!
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
the ICMP checksum field should be set to 0, this is required only for Tx ICMP*/
一周热门 更多>