代码拉取完成,页面将自动刷新
#include "basetype.h"
#include "common.h"
#include "debug_lib.h"
#include "packet_lib.h"
#include "ethernet_lib.h"
#include "arp_lib.h"
#include "ipv4_lib.h"
#include "icmp_lib.h"
#include "device_data.h"
#include "route_data.h"
#include "arp_data.h"
#include "arp_pktprocess.h"
#include "icmp_pktprocess.h"
INT32 PcPacketProcess(UINT16 usDeviceId, UINT16 usIfNum, UINT8 *pucBuffer, UINT16 usPacketLen)
{
INT32 iRet = ERROR_SUCCESS;
UINT16 usPacketLenAnswer = 0;
ETHERNET_S ustEthernetHeader; // 报文头部
ARPHEAD_S ustArpHader; // arp报文头
IPV4HEAD_S ustIpv4Header;
ICMP_S stIcmpHeader;
DEVICE_IF_S *pstIf = NULL; // 设备接口
ARP_DEVICE_S *pstArpDevice = NULL; // ARP设备
ARP_NODE_S *pstArpNode = NULL; // ARP表
ROUTE_DEVICE_S *pstRouteDevice = NULL;
ROUTE_DATA_S *pstRoute = NULL;
// 广播mac
UINT8 aucBroadCastMac[MAC_BYTE] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
// 得到以太传输得是什么mac 协议
EthernetLib_DecodeEthernetHeader(pucBuffer, usPacketLen, &ustEthernetHeader);
pstIf = DeviceData_GetIf(usDeviceId, 0);
// 找到路由设备
pstRouteDevice = RouteData_FindDevice(usDeviceId);
if (ETHERNET_PROTOCOL_ARP == ustEthernetHeader.usNextProtocol)
{
if (0 == memcmp(ustEthernetHeader.aucDst, pstIf->aucMac, MAC_BYTE)) // 目的mac地址发送给自己
{
pktprocess_RecvARP(usDeviceId, pucBuffer, pstIf->aucMac, usIfNum);
}
else if (0 == memcmp(ustEthernetHeader.aucDst, aucBroadCastMac, MAC_BYTE)) // 目的mac地址 广播
{
ArpLib_DecodeArp(&ustArpHader, pucBuffer, usPacketLen);
pstRoute = RouteData_BestMatch(pstRouteDevice, ustArpHader.uiDstIPv4Addr);
if (NULL == pstRoute || 32 != pstRoute->usPrefixLen)
{
return iRet;
}
pktprocess_RecvARP(usDeviceId, pucBuffer, pstIf->aucMac, usIfNum);
}
}
else if (ETHERNET_PROTOCOL_IPV4 == ustEthernetHeader.usNextProtocol)
{
// 得到IP传输得是什么协议
Ipv4Lib_DecodeIPv4Header(pucBuffer, usPacketLen, &ustIpv4Header);
// IP 内容相应处理
if (ETHERNET_PROTOCOL_IPV4 == ustIpv4Header.ucProtocol)
{
return iRet;
}
// ICMP--------------------------------------------------------------------------------
// // 找到路由设备 pc路由匹配,if 匹配自己路由表[任何一条主机路由],else 丢弃
// pstRouteDevice = RouteData_FindDevice(usDeviceId);
// 查路由表 主机路由 直连路由
pstRoute = RouteData_BestMatch(pstRouteDevice, ustIpv4Header.uiDstIPv4Addr);
if (NULL == pstRoute)
return iRet;
if (Protocol_ICMP == ustIpv4Header.ucProtocol && 32 == pstRoute->usPrefixLen)
{
IcmpLib_DecodeIcmp(pucBuffer, &stIcmpHeader, usPacketLen);
// ICMP 处理函数 请求应答返回 一个 aucBufferAnswer, usPacketLenAnswer
pktprocess_RecvICMP(usDeviceId, &ustEthernetHeader, &ustIpv4Header, &stIcmpHeader, usPacketLen);
return iRet;
}
}
else if (ETHERNET_PROTOCOL_IPV6 == ustEthernetHeader.usNextProtocol)
{
}
else
{
}
// IP--------------------------------------------------------------------------------
return iRet;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。