📄 pkt.c
字号:
//--------------------------------------------------------------------------
// Ip Stack
//--------------------------------------------------------------------------
// PKT.C
//
// Packet Object
//
// Author: Michael A. Denio
// Copyright 1999 by Texas Instruments Inc.
//-------------------------------------------------------------------------
#include <stkmain.h>
#ifdef _STRONG_CHECKING
static char *dpfStr = "PktFun: HTYPE %04x";
#endif
//--------------------------------------------------------------------
// PktNew()
//
// Creates a packet object
//--------------------------------------------------------------------
HANDLE PktNew()
{
PACKET *pp;
// If alloc fails, return NULL
if( !(pp = mmAlloc(sizeof(PACKET))) )
{
DbgPrintf(DBG_WARN,"PktNew: OOM");
ExecLowResource();
return( 0 );
}
// Initialize type
pp->Type = HTYPE_PKT;
// Initialize some defaults
pp->Flags = 0; // No status flags
pp->hIFRx = 0; // No Interface handle
pp->hIFTx = 0; // No Interface handle
pp->hLLADst = 0; // No Destination handle
pp->hRoute = 0; // No Route handle
pp->hFrag = 0; // No frag handle
return( (HANDLE)pp );
}
//--------------------------------------------------------------------
// PktFree()
//
// Destroys a packet object
//--------------------------------------------------------------------
void PktFree( HANDLE h )
{
PACKET *pp = (PACKET *)h;
#ifdef _STRONG_CHECKING
if( pp->Type != HTYPE_PKT )
{
DbgPrintf(DBG_ERROR,"PktFree: HTYPE %04x",pp->Type);
return;
}
#endif
// Kill type for debug
pp->Type = 0;
// Free any frag
if( pp->hFrag )
FragFree( pp->hFrag );
// Get rid of any LLA or Route objects
if( pp->hLLADst )
LLADeRef( pp->hLLADst );
if( pp->hRoute )
RtDeRef( pp->hRoute );
// Free packet memory
mmFree( pp );
}
void PktSetLLADst( HANDLE h, HANDLE hLLA )
{
PACKET *pp = (PACKET *)h;
#ifdef _STRONG_CHECKING
if( pp->Type != HTYPE_PKT )
{
DbgPrintf(DBG_ERROR,dpfStr,pp->Type);
return;
}
#endif
// Update References
if( hLLA )
LLARef( hLLA );
if( pp->hLLADst )
LLADeRef( pp->hLLADst );
pp->hLLADst = hLLA;
}
void PktSetRoute( HANDLE h, HANDLE hRoute )
{
PACKET *pp = (PACKET *)h;
#ifdef _STRONG_CHECKING
if( pp->Type != HTYPE_PKT )
{
DbgPrintf(DBG_ERROR,dpfStr,pp->Type);
return;
}
#endif
// Update References
if( hRoute )
RtRef( hRoute );
if( pp->hRoute )
RtDeRef( pp->hRoute );
pp->hRoute = hRoute;
}
#ifdef _STRONG_CHECKING
//--------------------------------------------------------------------
// The Following is a GET/SET nightmare
//
// We'll try to help things along by validating entries in the flags
// as they're written, and return NULL for entries that are not valid.
//--------------------------------------------------------------------
void PktSetFlagsSet( HANDLE h, uint Flags )
{
PACKET *pp = (PACKET *)h;
if( pp->Type != HTYPE_PKT )
{
DbgPrintf(DBG_ERROR,dpfStr,pp->Type);
return;
}
pp->Flags |= Flags;
}
void PktSetFlagsClear( HANDLE h, uint Flags )
{
PACKET *pp = (PACKET *)h;
if( pp->Type != HTYPE_PKT )
{
DbgPrintf(DBG_ERROR,dpfStr,pp->Type);
return;
}
pp->Flags &= ~Flags;
}
void PktSetIFRx( HANDLE h, HANDLE hIF )
{
PACKET *pp = (PACKET *)h;
if( pp->Type != HTYPE_PKT )
{
DbgPrintf(DBG_ERROR,dpfStr,pp->Type);
return;
}
pp->hIFRx = hIF;
}
void PktSetIFTx( HANDLE h, HANDLE hIF )
{
PACKET *pp = (PACKET *)h;
if( pp->Type != HTYPE_PKT )
{
DbgPrintf(DBG_ERROR,dpfStr,pp->Type);
return;
}
pp->hIFTx = hIF;
}
void PktSetEthType( HANDLE h, uint wEtherType )
{
PACKET *pp = (PACKET *)h;
if( pp->Type != HTYPE_PKT )
{
DbgPrintf(DBG_ERROR,dpfStr,pp->Type);
return;
}
pp->EtherType = wEtherType;
}
void PktSetSizeLLC( HANDLE h, uint wSizeLLCHdr )
{
PACKET *pp = (PACKET *)h;
if( pp->Type != HTYPE_PKT )
{
DbgPrintf(DBG_ERROR,dpfStr,pp->Type);
return;
}
pp->SizeLLCHdr = wSizeLLCHdr;
}
void PktSetSizeNet( HANDLE h, uint wSizeNetHdr )
{
PACKET *pp = (PACKET *)h;
if( pp->Type != HTYPE_PKT )
{
DbgPrintf(DBG_ERROR,dpfStr,pp->Type);
return;
}
pp->SizeNetHdr = wSizeNetHdr;
}
void PktSetSizeTP( HANDLE h, uint wSizeTPHdr )
{
PACKET *pp = (PACKET *)h;
if( pp->Type != HTYPE_PKT )
{
DbgPrintf(DBG_ERROR,dpfStr,pp->Type);
return;
}
pp->SizeTPHdr = wSizeTPHdr;
}
void PktSetFrag( HANDLE h, HANDLE hFrag )
{
PACKET *pp = (PACKET *)h;
if( pp->Type != HTYPE_PKT )
{
DbgPrintf(DBG_ERROR,dpfStr,pp->Type);
return;
}
pp->hFrag = hFrag;
}
uint PktGetFlags( HANDLE h )
{
PACKET *pp = (PACKET *)h;
if( pp->Type != HTYPE_PKT )
{
DbgPrintf(DBG_ERROR,dpfStr,pp->Type);
return( 0 );
}
return( pp->Flags );
}
HANDLE PktGetIFRx( HANDLE h )
{
PACKET *pp = (PACKET *)h;
if( pp->Type != HTYPE_PKT )
{
DbgPrintf(DBG_ERROR,dpfStr,pp->Type);
return( 0 );
}
return( pp->hIFRx );
}
HANDLE PktGetIFTx( HANDLE h )
{
PACKET *pp = (PACKET *)h;
if( pp->Type != HTYPE_PKT )
{
DbgPrintf(DBG_ERROR,dpfStr,pp->Type);
return( 0 );
}
return( pp->hIFTx );
}
uint PktGetEthType( HANDLE h )
{
PACKET *pp = (PACKET *)h;
if( pp->Type != HTYPE_PKT )
{
DbgPrintf(DBG_ERROR,dpfStr,pp->Type);
return( 0 );
}
return( pp->EtherType );
}
HANDLE PktGetLLADst( HANDLE h )
{
PACKET *pp = (PACKET *)h;
if( pp->Type != HTYPE_PKT )
{
DbgPrintf(DBG_ERROR,dpfStr,pp->Type);
return( 0 );
}
return( pp->hLLADst );
}
HANDLE PktGetRoute( HANDLE h )
{
PACKET *pp = (PACKET *)h;
if( pp->Type != HTYPE_PKT )
{
DbgPrintf(DBG_ERROR,dpfStr,pp->Type);
return( 0 );
}
return( pp->hRoute );
}
uint PktGetSizeLLC( HANDLE h )
{
PACKET *pp = (PACKET *)h;
if( pp->Type != HTYPE_PKT )
{
DbgPrintf(DBG_ERROR,dpfStr,pp->Type);
return( 0 );
}
return( pp->SizeLLCHdr );
}
uint PktGetSizeNet( HANDLE h )
{
PACKET *pp = (PACKET *)h;
if( pp->Type != HTYPE_PKT )
{
DbgPrintf(DBG_ERROR,dpfStr,pp->Type);
return( 0 );
}
return( pp->SizeNetHdr );
}
uint PktGetSizeTP( HANDLE h )
{
PACKET *pp = (PACKET *)h;
if( pp->Type != HTYPE_PKT )
{
DbgPrintf(DBG_ERROR,dpfStr,pp->Type);
return( 0 );
}
return( pp->SizeTPHdr );
}
HANDLE PktGetFrag( HANDLE h )
{
PACKET *pp = (PACKET *)h;
if( pp->Type != HTYPE_PKT )
{
DbgPrintf(DBG_ERROR,dpfStr,pp->Type);
return( 0 );
}
return( pp->hFrag );
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -