阅读:1193回复:3
关于包描述符结构的问题
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. // This is for the send-path only. Packets indicated will use WrapperReserved // instead of WrapperReservedEx // 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_PACKET结构中, NDIS_PACKET_PRIVATE Private;和 UCHAR ProtocolReserved 这两个成员的作用是什么?看DDK看不太懂,请指教。 |
|
|
沙发#
发布于:2004-04-13 16:04
先说说Private:
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; Packet描述符中的Private.Head指向挂接在其上的Buffer描述符,Buffer描述符同时也是一个链表结构,这些连在一起的Buffer描述符中的每一个都指定了一块内存(在那块内存里才真正存放了我们要接受或发送的数据。 我们看看Private.Head Tail的结构: typedef struct _MDL { struct _MDL *Next; CSHORT Size; CSHORT MdlFlags; struct _EPROCESS *Process; PVOID MappedSystemVa; PVOID StartVa; ULONG ByteCount; ULONG ByteOffset; } MDL, *PMDL; typedef MDL NDIS_BUFFER, *PNDIS_BUFFER 这下你应该明白那些发送和接受的数据是怎么存储,再怎么用Buffer Descriptor来map,然后Buffer Descriptor再怎么chain到Packet Descriptor上面去的了吧。 |
|
板凳#
发布于:2004-04-13 16:23
再说说ProtocolReserved:
Highest-level protocol drivers and NDIS intermediate drivers can use this variable-sized area for their own purposes, as long as each such driver is given a fresh packet descriptor. Chained to each packet descriptor are one or more buffer descriptors mapping buffers that contain network packet data, either received or to be transmitted. NIC drivers and intermediate drivers allocate packet descriptors with, at least, 16 bytes of ProtocolReserved space to be used by protocols for receive indications. A single driver can use the MiniportReserved(Ex) area and a single driver can use the ProtocolReserved area while a particular packet descriptor is being used in a transfer operation. Consequently, NDIS intermediate drivers, which have both MiniportXxx and ProtocolXxx functions, cannot use these areas in incoming packet descriptors for their own purposes. 也就是说,这个ProtocolReserved并不是一个UCHAR,在它的后面回至少空出16bytes,再接下来是NDIS_PACKET_OOB_DATA部分,然后是NDIS_PACKET_EXTENSION部分,当然,你不用担心什么,因为这些数据和空间安排在你调用NdisAllocatePacket时自动完成了。 那么ProtocolReserved后的16bytes有什么用呢?除了网卡驱动,所用的protocol driver和intermediate driver在接受和发送时都要自己申请Packet Descriptor,然后你就有权根据需要使用其中的ProtocolReserved数据段了:比方说你可以在此记下源Packet的handle在SendComplete或ReceiveComplete时使用。当然,如果没有必要你可能也用不上这一段空间。 |
|
地板#
发布于:2004-04-13 16:24
快点给分吧
|
|