代码拉取完成,页面将自动刷新
#include"basetype.h"
#include"common.h"
UINT16 EthernetLib_EncodeEthernetHeader(IN UINT8* pucSrcMac, IN UINT8* pucDstMac,
IN UINT16 usNextProtocol, OUT UINT8* pucBuffer)
{
UINT8* pucPointer = pucBuffer;
memcpy(pucPointer, pucDstMac, MAC_BYTE);
pucPointer += MAC_BYTE;
memcpy(pucPointer, pucSrcMac, MAC_BYTE);
pucPointer += MAC_BYTE;
// *(UINT16*)pucPointer = usNextProtocol;
*pucPointer = (UINT8)((usNextProtocol & 0xFF00) >> 8);
pucPointer++;
*pucPointer = usNextProtocol & 0xFF;
return 14;
}
/*
* description: 解封装报文里面的以太头部分
*
* input:
* pucBuffer 报文
* usPacketLen 报文长度
* output:
* ETHERNET_S* pstEthernetHeader 报文的以太头部分
* return: NULL
* tip: IN是空宏,表示改参数是输入
*/
VOID EthernetLib_DecodeEthernetHeader(IN UINT8* pucBuffer, UINT16 usPacketLen, ETHERNET_S* pstEthernetHeader)
{
if (usPacketLen < 14)
{
printf("Ethernet header message length error\n");
exit(-1);
}
UINT8* pucPointer = pucBuffer;
memcpy(pstEthernetHeader->aucDst, pucPointer, MAC_BYTE);
pucPointer += MAC_BYTE;
memcpy(pstEthernetHeader->aucSrc, pucPointer, MAC_BYTE);
pucPointer += MAC_BYTE;
pstEthernetHeader->usNextProtocol = ((UINT16)(*pucPointer) << 8);
pucPointer++;
pstEthernetHeader->usNextProtocol += (UINT16)(*pucPointer);
pucPointer++;
return;
}
VOID EthernetLib_DecodeEthernetVlanHeader(IN UINT8* pucBuffer, UINT16 usPacketLen, ETHERNET_VLAN_S* pstEthernetHeader)
{
if (usPacketLen < 18)
{
printf("Ethernet header message length error\n");
exit(-1);
}
UINT8* pucPointer = pucBuffer;
memcpy(pstEthernetHeader->aucDst, pucPointer, MAC_BYTE);
pucPointer += MAC_BYTE;
memcpy(pstEthernetHeader->aucSrc, pucPointer, MAC_BYTE);
pucPointer += MAC_BYTE;
memcpy((VOID*)&pstEthernetHeader->usEtype, pucPointer, VLAN_ETYPE);
pucPointer += VLAN_ETYPE;
memcpy((VOID*)&pstEthernetHeader->usVlanTag, pucPointer, VLAN_ID);
pucPointer += VLAN_ID;
pstEthernetHeader->usNextProtocol = ((UINT16)(*pucPointer) << 8);
pucPointer++;
pstEthernetHeader->usNextProtocol += (UINT16)(*pucPointer);
pucPointer++;
return;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。