代码拉取完成,页面将自动刷新
#include "basetype.h"
#include "common.h"
#include "debug_lib.h"
#include "ethernet_lib.h"
#include "ipv4_lib.h"
#include "icmp_lib.h"
#include "addr_lib.h"
#include "device_data.h"
#include "timer_data.h"
#include "routing_process.h"
/*
* description:收到icmp请求或回应报文后的操作
*
* input:
* usDeviceId 源设备ID
* pustEthernetHeader 报文以太头
* pustIpv4Header 报文IP头
* pstIcmpHeader 报文icmp部分
* BufferLen 报文长度
*
* output:
* aucBufferAnswer 装载回应报文
* return: NULL
* tip: IN是空宏,表示改参数是输入
*/
UINT32 pktprocess_RecvICMP(UINT16 usDeviceId, ETHERNET_S* pustEthernetHeader,
IPV4HEAD_S* pustIpv4Header, ICMP_S* pstIcmpHeader, UINT32 BufferLen)
{
UINT16 Delay_Time = 20, usPacketAnswerLen = 0;
ICMP_TASK_S* pstIcmp_task;
UINT32 auiPara[4] = { 0 };
UINT8 aucBufferAnswer[PACKET_MAX_SIZE]; // PACKET_MAX_SIZE 报文最大长度
memset(aucBufferAnswer, 0, sizeof(aucBufferAnswer)); // 初始化 应答buffer 内存空间
if (ICMPoptype_Ask_Echoreply == pstIcmpHeader->ucOptype ||
pustIpv4Header->uiDstIPv4Addr == pustIpv4Header->uiSrcIPv4Addr) // 如果收到ICMP回应或 ping 自己
{
pstIcmp_task = DeviceData_GetIcmpTask(usDeviceId);
pstIcmp_task->ausSuccess[pstIcmp_task->usSeq] = 1;
TimerData_Del(pstIcmp_task->uiTimerId);
if (++pstIcmp_task->usSeq == 5)
{
IcmpTask_print(usDeviceId);
}
else
{
Ping(usDeviceId, pstIcmp_task->uiDstIP, pstIcmp_task->usSeq);
auiPara[0] = usDeviceId;
pstIcmp_task->uiTimerId = TimerData_Add(10, TIMER_ID_INVALID, auiPara, IcmpTask_Timeout);
}
return 0;
}
if (ICMPoptype_Ask_Echorequest == pstIcmpHeader->ucOptype) // 如果收到ICMP请求
{
usPacketAnswerLen += IcmpLib_EncodeIcmp(aucBufferAnswer, ICMPoptype_Ask_Echoreply, ICMPcode_Echorequest_Request, pstIcmpHeader->usSeqnum);
send3(usDeviceId, pustIpv4Header->uiSrcIPv4Addr, pustIpv4Header->uiDstIPv4Addr, aucBufferAnswer, usPacketAnswerLen, 0xFF, Protocol_ICMP); // 调用send3发送回复报文
return usPacketAnswerLen;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。