本论坛为只读模式,仅供查阅,不能注册新用户,不能发帖/回帖,有问题可发邮件 xikug.xp (^) gmail.com
查看: 2889|回复: 0

NDIS PACKET结构细节分析 [复制链接]

Rank: 1

发表于 2013-1-18 15:38:00 |显示全部楼层
本帖最后由 arthasprince 于 2013-1-18 15:38 编辑

NDIS PACKET封装了一个网络数据包,在以太网中,就是以太网封包,有时需要对数据进行拷贝再进行特殊的处理,如何做,它的结构体是什么样了?
基本框架结构:
typedef struct _NDIS_PACKET
{
NDIS_PACKET_PRIVATE Private;

union
{
struct // For Connection-less miniports
{
UCHAR MiniportReserved[2*sizeof(PVOID)];
UCHAR WrapperReserved[2*sizeof(PVOID)];
};

struct
{
//
// For de-serialized miniports. And by implication conn-oriented miniports.
//
UCHAR MiniportReservedEx[3*sizeof(PVOID)];
UCHAR WrapperReservedEx[sizeof(PVOID)];
};

struct
{
UCHAR MacReserved[4*sizeof(PVOID)];
};
};

ULONG_PTR Reserved[2]; // For compatibility with Win95
UCHAR ProtocolReserved[1];

} NDIS_PACKET, *PNDIS_PACKET, **PPNDIS_PACKET;

其中的最后一个成员是动态长度,在使用NDIS API 分配包时,可以自行指定,但它并不是这么简单。
其中用到的NDIS_PACKET_PRIVATE结构:
//
//
// wrapper-specific part of a packet
//
typedef struct _NDIS_PACKET_PRIVATE
{
UINT PhysicalCount; // number of physical pages in packet.
UINT TotalLength; // Total amount of data in the packet.
PNDIS_BUFFER Head; // first buffer in the chain
PNDIS_BUFFER Tail; // last buffer in the chain

// if Head is NULL the chain is empty; Tail doesn't have to be NULL also

PNDIS_PACKET_POOL Pool; // so we know where to free it back to
UINT Count;
ULONG Flags;
BOOLEAN ValidCounts;
UCHAR NdisPacketFlags; // See fPACKET_xxx bits below
USHORT NdisPacketOobOffset;
} NDIS_PACKET_PRIVATE, * PNDIS_PACKET_PRIVATE;

其中最后一个成员是一个偏移量,指示出的包数据结构的OOB数据结构成员的偏移量,对应一个NDIS_PACKET_OOB_DATA结构体:

typedef struct _NDIS_PACKET_OOB_DATA
{
union
{
ULONGLONG TimeToSend;
ULONGLONG TimeSent;
};
ULONGLONG TimeReceived;
UINT HeaderSize;
UINT SizeMediaSpecificInfo;
PVOID MediaSpecificInformation;

NDIS_STATUS Status;
} NDIS_PACKET_OOB_DATA, *PNDIS_PACKET_OOB_DATA;

但是在这之后,还有一个数据成员,记录此包的更多相关信息:
typedef struct _NDIS_PACKET_EXTENSION
{
PVOID NdisPacketInfo[MaxPerPacketInfo];
} NDIS_PACKET_EXTENSION, *PNDIS_PACKET_EXTENSION;

typedef enum _NDIS_PER_PACKET_INFO
{
TcpIpChecksumPacketInfo,
IpSecPacketInfo,
TcpLargeSendPacketInfo,
ClassificationHandlePacketInfo,
NdisReserved,
ScatterGatherListPacketInfo,
Ieee8021QInfo,
OriginalPacketInfo,
PacketCancelId,
OriginalNetBufferList,
CachedNetBufferList,
ShortPacketPaddingInfo,
MaxPerPacketInfo
} NDIS_PER_PACKET_INFO, *PNDIS_PER_PACKET_INFO;

综上所述,一个数据包的数据结构如下:
|NDIS_PACKET|PROTOCOL_RESERVED(DYNAMIC)|NDIS_PACKET_OOB_DATA|NDIS_PACKET_EXTENSION
如果需要拷贝一个数据包,需要注意所有以上相关数据成员。
您需要登录后才可以回帖 登录 | 立即加入

Archiver|手机版|第8个男人 - 论坛为只读模式,仅供查阅

GMT+8, 2019-5-22 01:44 , Processed in 0.024919 second(s), 8 queries .

Design by pvo.cn

© 2011 Pvo Inc.

回顶部