14 Star 9 Fork 0

zhangruoxu/demo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
pc_stackframe.c 3.46 KB
一键复制 编辑 原始数据 按行查看 历史
zhangruoxu 提交于 2023-06-09 14:41 . 路由器报文挂载出错
#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;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhangruoxudada/demo.git
git@gitee.com:zhangruoxudada/demo.git
zhangruoxudada
demo
demo
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385