阅读:2839回复:20
帮忙解释ddk中前视缓冲区的含义
在读ddk中前视缓冲区是什莫含义,有什莫作用?谢谢
|
|
沙发#
发布于:2003-10-13 14:50
在读ddk中前视缓冲区是什莫含义,有什莫作用?谢谢 lookaheadbuffer?? 这个缓冲区是给协议一段packet的内容,让协议来决定是否接受这个报文。 |
|
|
板凳#
发布于:2003-10-13 15:27
[quote]在读ddk中前视缓冲区是什莫含义,有什莫作用?谢谢 lookaheadbuffer?? 这个缓冲区是给协议一段packet的内容,让协议来决定是否接受这个报文。 [/quote] 谢谢斑竹,那莫你所说的**给协议一段packet内容**是怎莫控制的,到底要给那一段内容,有什莫规则要遵循?是不是这些都是由函数来执行的,我们只需要调用就可以了? |
|
地板#
发布于:2003-10-13 16:09
这个是有miniport驱动来决定究竟那个lookaheadbuffer的大小的,这个缓冲区是从报文的ip头开始的一段缓冲区,也有可能是包含了整个的ip报文,这个时候lookaheadbuffersize=packetsize了,
如果lookaheadbuffersiz<Packetsize,而这个时候协议驱动还要接受整个报文,那就调用ndistransferdata来获得整个的报文。 |
|
|
地下室#
发布于:2003-10-13 16:15
谢谢斑竹,给分了
|
|
5楼#
发布于:2003-10-14 16:40
这个是有miniport驱动来决定究竟那个lookaheadbuffer的大小的,这个缓冲区是从报文的ip头开始的一段缓冲区,也有可能是包含了整个的ip报文,这个时候lookaheadbuffersize=packetsize了, 斑竹解释得我好像是明白了,可一看到程序就不知道什莫意思了? 斑竹能给解释一下下面的程序吗,谢谢! if(LookaheadBufferSize!=PacketSize){ IndicateBuffer=TransferBuffer-HeaderBufferSize-LookaheadBufferSize; NdisMoveMemory( IndicateBuffer, HeaderBuffer, HeaderBufferSize); NdisMoveMemory( IndicateBuffer+HeaderBufferSize, LookaheadBuffer, Lookahea dBufferSize); NdisTransferData( &ReturnStatus, *((PUINT)NdisBindingContext+1), MacReceiveContext, LookaheadBufferSize, // ByteOffset, PacketSize-LookaheadBufferSize, //BytesToTransfer, RcvTransferPacket, &BytesTransfered ); HeaderBuffer=IndicateBuffer; LookaheadBuffer=IndicateBuffer+HeaderBufferSize; LookaheadBufferSize = PacketSize; } else { IndicateBuffer=HeaderBuffer; } |
|
6楼#
发布于:2003-10-14 21:55
这段程序就是判断lookaheadbuffersize是否等于packetsize,如果等于那就直接提交,如果不等于,就调用ndistranferdata来把剩余的数据都取上来,然后在一起提交。 |
|
|
7楼#
发布于:2003-10-15 10:05
谢谢斑竹,还有点小问题:
1 我不太明白HeaderBufferSize和LookaheadBufferSize大小是不是要重叠的?还有HeaderBuffer和LookaheadBuffer所代表的缓冲区的表示符是不是同指一个地址,假如要是重叠或是相同下面的两个NdisMoveMemory复制数据值就有重复了吧? 2 还有NdisTransferData中参数 *((PUINT)NdisBindingContext+1) 不明白什莫意思 |
|
8楼#
发布于:2003-10-15 10:11
1 headbuffer和lookaheadbuffer上不重叠的,指向的不是同以地址,packetsize是不包括headbuffer的大小的,headbuffer一般是以太网的头
2 *((PUINT)NdisBindingContext+1)这个你要看那个NdisBindingContext的声明了,指针向前挪了一个,应该是一个NDIS_HANDLE的指针,就是ndistransferdata的第二个参数。 |
|
|
9楼#
发布于:2003-10-15 10:35
mikeluo :
lookaheadbuffersize > packetsize 的情况下, 难道也要调用ndistransferdata 来获得 整个 数据吗 ?? 呵呵。 先谢 了。 |
|
10楼#
发布于:2003-10-15 10:43
mikeluo : 真的有这个时候?应该不会出现的。 那个判断其实应该是判断if(lookaheadbuffersize<packetsize) 那直接从lookaheadbuffer里面copy出来packetsize大小的数据就ok了啊。 |
|
|
11楼#
发布于:2003-10-15 11:23
1 headbuffer和lookaheadbuffer上不重叠的,指向的不是同以地址,packetsize是不包括headbuffer的大小的,headbuffer一般是以太网的头 谢谢斑竹! 第一个问题明白了,可第二个问题还有些不懂,我在ddk中查到ndistransferdata的第二个参数的意思是: Specifies the handle returned by NdisOpenAdapter that identifies the target NIC or the virtual adapter of the next-lower driver to which the caller is bound. 不明白为慎莫要加一呢,是不是要指向另一个the target NIC or the virtual adapter? 而且加一我认为是指针向后挪了一个? |
|
12楼#
发布于:2003-10-15 11:54
你在看谁的代码?他那个NdisBindingContext是怎么声明的?如何赋值的?
|
|
|
13楼#
发布于:2003-10-15 13:13
你在看谁的代码?他那个NdisBindingContext是怎么声明的?如何赋值的? 可能是胡老大的帖子吧 发信人: Immortal1015 (1015), 信区: WinDDK 标 题: 一个win95下的VPN SOURCE 发信站: BBS 水木清华站 (Fri Mar 16 15:00:46 2001) 转自白云黄鹤站系统内核版 发信人: huyuguang (不再困惑), 信区: SysInternals ;32mWWW-POSTm 标 题: win9x vpn source 发信站: 武汉白云黄鹤站 (Tue Aug 8 20:53:58 2000) , 站内信件 这个代码是17(oneseven)写的,我和他是源代码共享的, 由于前面友人向我要win9x下的vpn源代码,我相信肯定有 人看了我前面的简介还是不太明白,干脆贴在下面。 下文来自17的毕业论文,别的东西不好都贴上来,毕竟还有 点军队背景。 为了免得大家看的麻烦,我就不分成几块了,其实我是很喜欢 灌水的;-) 垫片模块的源程序: 1.Ndisshim.h,C语言头文件。 /*************************************************************************** * * * * THIS CODE AND INFORMATION IS PROVIDED \"AS IS\" WITHOUT WARRANTY OF ANY * * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE * * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR * * PURPOSE. * * * **************************************************************************** / #define WANTVXDWRAPS #include <basedef.h> #include <vmm.h> #include <shell.h> #include <debug.h> #include <vxdwraps.h> #include <vwin32.h> #include <winerror.h> #include <ndis.h> MAKE_HEADER(DWORD,_stdcall,VKD_Filter_Keyboard_Input, (VOID)) MAKE_HEADER(VOID,_cdecl,Ndis_Hook, ()) MAKE_HEADER(DWORD,_cdecl,_SHELL_PostMessage,(DWORD,DWORD,DWORD,DWORD,DWORD,D WORD)) MAKE_HEADER(USHORT,_cdecl,Encrypt_reg,(PUCHAR,USHORT,USHORT)) MAKE_HEADER(USHORT,_cdecl,Decrypt_reg,(PUCHAR,USHORT,USHORT)) #define Ndis_Hook PREPEND(Ndis_Hook) #define _SHELL_PostMessage PREPEND(_SHELL_PostMessage) #define Encrypt_reg PREPEND(Encrypt_reg) #define Decrypt_reg PREPEND(Decrypt_reg) #define WM_NSHIM_NEW 3002 #define IP_PROTOCOL 0x0008 #define IP_HEADER_LEN 20 #define MAC_HEADER_LEN 14 #define NSHIM_VERSION 0x400 #define NSHIM_V86_FUNCTION1 1 #define NSHIM_V86_FUNCTION2 2 #define NSHIM_PM_FUNCTION1 1 #define NSHIM_PM_FUNCTION2 2 #define MAX_NSHIM_W32_API (sizeof(NSHIM_W32_Proc)/sizeof(DWORD)) #define MAX_SEND_BUF_LIST 10 #define MAX_SEND_PKT_LIST 10 #define MAX_SEND_APPEND_LEN 21 #define MAX_ADAPTER_NUM 5 #define PACKET_REFUSE 0 #define PACKET_MUD 1 #define PACKET_CLEAR 2 #define PACKET_D_REFUSE 3 #define PACKET_D_QUERY 4 #define PACKET_D_CLEAR 5 #define QUERY_SEND_PACKET 0 #define QUERY_RCV_PACKET 1 /*#define ENCRYPT_Service Declare_Service #define ENCRYPT_DEVICE_ID 0x1800 Begin_Service_Table(ENCRYPT) ENCRYPT_Service(Encrypt_reg) ENCRYPT_Service(Decrypt_reg) End_Service_Table(ENCRYPT)*/ typedef DIOCPARAMETERS *LPDIOC; typedef struct _MAC_HEADER{ UCHAR MAC_DA[6]; UCHAR MAC_SA[6]; USHORT ProtocolType; } MAC_HEADER, *PMAC_HEADER; typedef struct _IP_HEADER{ UCHAR Ver; UCHAR Service; UCHAR LengthU; UCHAR LengthL; USHORT Identification; USHORT FragmentOffset; UCHAR LiveTime; UCHAR Protocol; USHORT HeaderCRC; ULONG IP_SA; ULONG IP_DA; } IP_HEADER, *PIP_HEADER; typedef struct _AC_ITEM { ULONG ip; ULONG net_mask; USHORT access; USHORT sndkeyno; } AC_ITEM, *PAC_ITEM; typedef struct _EXCP_ITEM { ULONG ip; USHORT tcp_port; } EXCP_ITEM, *PEXCP_ITEM; typedef struct _BINDING_INFO{ NDIS_HANDLE BindingHandle; UCHAR CtrlActived; NDIS_STRING Name; } BINDING_INFO, *PBINDING_INFO; typedef struct _PENDING_INFO{ NDIS_HANDLE ProtocolBindingContext; PNDIS_HANDLE NdisBindingHandle; NDIS_STRING Name; } PENDING_INFO, *PPENDING_INFO; DWORD _stdcall NSHIM_W32_DeviceIOControl(DWORD, DWORD, DWORD, LPDIOC); DWORD _stdcall NSHIM_CleanUp(void); DWORD _stdcall NSHIM_W32_OpenWnd(DWORD, DWORD, LPDIOC); DWORD _stdcall NSHIM_W32_CloseWnd(DWORD, DWORD, LPDIOC); DWORD _stdcall NSHIM_W32_GetAdapterInfo(DWORD, DWORD, LPDIOC); DWORD _stdcall NSHIM_W32_SetAdapterState(DWORD, DWORD, LPDIOC); DWORD _stdcall NSHIM_W32_SetACState(DWORD, DWORD, LPDIOC); DWORD _stdcall NSHIM_W32_LoadAccList(DWORD, DWORD, LPDIOC); DWORD _stdcall NSHIM_W32_LoadExcpList(DWORD, DWORD, LPDIOC); VOID _stdcall NSHIM_Send(PNDIS_STATUS, NDIS_HANDLE, PNDIS_PACKET); VOID _stdcall NSHIM_Request( OUT PNDIS_STATUS Status, IN NDIS_HANDLE NdisBindingHandle, IN PNDIS_REQUEST Request ); VOID NDIS_API NSHIM_RegisterProtocol( OUT PNDIS_STATUS Status, OUT PNDIS_HANDLE NdisProtocolHandle, IN PNDIS_PROTOCOL_CHARACTERISTICS ProtocolCharacteristics, IN UINT CharacteristicsLength ); NDIS_STATUS NDIS_API NSHIM_IPReceive( IN NDIS_HANDLE NdisBindingContext, IN NDIS_HANDLE MacReceiveContext, IN PVOID HeaderBuffer, IN UINT HeaderBufferSize, IN PVOID LookaheadBuffer, IN UINT LookaheadBufferSize, IN UINT PacketSize ); VOID NDIS_API NSHIM_IPSendComplete( IN NDIS_HANDLE NdisBindingContext, IN PNDIS_PACKET Packet, IN NDIS_STATUS Status ); VOID NDIS_API NSHIM_IPOpenAdapterComplete( IN NDIS_HANDLE ProtocolBindingContext, IN NDIS_STATUS Status, IN NDIS_STATUS OpenErrorStatus ); UINT CopyPacketToBuffer( IN OUT PUCHAR Buf, // destination IN PNDIS_PACKET Packet, // source packet IN UINT Offset, // offset in packet IN UINT Length // number of bytes to copy ); VOID CopyNdisString( PNDIS_STRING D_string, PNDIS_STRING S_string ); extern USHORT In_cksum( unsigned char *buf, int len); /*USHORT Encrypt_reg(PUCHAR buffer, USHORT buflen, USHORT sndkeyno ); USHORT Decrypt_reg(PUCHAR buffer, USHORT buflen, USHORT sndkeyno );*/ UCHAR QueryAccessList(PIP_HEADER Ip_header, UCHAR QueryType, PUSHORT sndkeyno ); UCHAR LoadAccessList(PUCHAR buffer, ULONG buflen ); UCHAR LoadExceptList(PUCHAR buffer, ULONG buflen ); VOID UnloadLists(); extern DWORD NdisIndicateReceiveAddr; extern DWORD NdisRequestAddr; extern DWORD NdisCompleteSendAddr; //extern DWORD NdisRegisterProtocolAddr; extern DWORD IPReceiveAddr; extern DWORD IPSendCompleteAddr; extern PUCHAR RcvBuffer; extern PUCHAR IndicateBuffer; extern PUCHAR TransferBuffer; extern NDIS_HANDLE RcvPacketPoolHandle; extern PNDIS_PACKET RcvTransferPacket; extern NDIS_HANDLE RcvBufferPoolHandle; extern PNDIS_BUFFER RcvPacketBuffer; extern PMAC_HEADER RcvMACHeader; extern PIP_HEADER RcvIPHeader; extern PUCHAR SendBuffer; extern PUCHAR CurSendBuffer; extern PMAC_HEADER SendMACHeader; extern PIP_HEADER SendIPHeader; extern NDIS_HANDLE SendBufferPoolHandle; extern NDIS_HANDLE SendPacketPoolHandle; extern PNDIS_PACKET SendPktList[MAX_SEND_PKT_LIST]; extern CHAR SendPktListHead; extern CHAR SendPktListTail; extern PNDIS_PACKET ReservedPkt[MAX_SEND_PKT_LIST]; extern NDIS_STATUS ReturnStatus; extern PNDIS_BUFFER BUFFER; extern DWORD CopiedLen; extern UINT BytesTransfered; extern USHORT Old_cksum,New_cksum; extern DWORD ViewHandle; extern BINDING_INFO BindingAdapterInfo[MAX_ADAPTER_NUM]; extern UCHAR BindingAdapterNum; 2.Nshim.c 垫片的C语言程序 #include \"ndisshim.h\" UINT CurSendPktLen; UINT MaxSendPktLen; DWORD NdisIndicateReceiveAddr; DWORD NdisRequestAddr; DWORD NdisCompleteSendAddr; //DWORD NdisRegisterProtocolAddr; DWORD IPReceiveAddr; DWORD IPSendCompleteAddr; DWORD IPOpenAdapterCompleteAddr; VOID (NDIS_API *NdisSendAddr )( PNDIS_STATUS, NDIS_HANDLE, PNDIS_PACKET); VOID (NDIS_API *NdisOpenAdapterAddr)( PNDIS_STATUS , PNDIS_STATUS , PNDIS_HANDLE , PUINT , PNDIS_MEDIUM , UINT , NDIS_HANDLE , NDIS_HANDLE , PNDIS_STRING , UINT , PSTRING ); VOID (NDIS_API *NdisRegisterProtocolAddr)( PNDIS_STATUS , PNDIS_HANDLE , PNDIS_PROTOCOL_CHARACTERISTICS , UINT ); /*VOID (NDIS_API *NdisRegisterMacAddr)( PNDIS_STATUS , PNDIS_HANDLE, NDIS_HANDLE , NDIS_HANDLE , PNDIS_MAC_CHARACTERISTICS, UINT );*/ PUCHAR RcvBuffer; PUCHAR IndicateBuffer; PUCHAR TransferBuffer; NDIS_HANDLE RcvPacketPoolHandle; PNDIS_PACKET RcvTransferPacket; NDIS_HANDLE RcvBufferPoolHandle; PNDIS_BUFFER RcvPacketBuffer; PMAC_HEADER RcvMACHeader; PIP_HEADER RcvIPHeader; PUCHAR SendBuffer; PUCHAR CurSendBuffer; PMAC_HEADER SendMACHeader; PIP_HEADER SendIPHeader; NDIS_HANDLE SendBufferPoolHandle; NDIS_HANDLE SendPacketPoolHandle; PNDIS_PACKET SendPktList[MAX_SEND_PKT_LIST]; CHAR SendPktListHead; CHAR SendPktListTail; PNDIS_PACKET ReservedPkt[MAX_SEND_PKT_LIST]; NDIS_STATUS ReturnStatus; PNDIS_BUFFER BUFFER; DWORD CopiedLen; UINT BytesTransfered; UCHAR ReadInfoOK=0; NDIS_HANDLE IPHandle; UCHAR AdapterNameBuf[2*MAX_ADAPTER_NUM][10]; BINDING_INFO BindingAdapterInfo[MAX_ADAPTER_NUM]; PENDING_INFO PendingOpenAdapter[MAX_ADAPTER_NUM]; UCHAR BindingAdapterNum = 0; UCHAR PendOpenNum = 0; NDIS_STRING TcpName = NDIS_STRING_CONST(\"MSTCP\"); //NDIS_HANDLE MacHandle; //NDIS_HANDLE WrapperHandle; //NDIS_HANDLE MacContext; USHORT Old_cksum,New_cksum; VOID _stdcall NSHIM_Send( OUT PNDIS_STATUS Status, IN NDIS_HANDLE NdisBindingHandle, IN PNDIS_PACKET Packet ) { USHORT sndkeyno; UCHAR i; for(i=0;i<BindingAdapterNum;i++){ if(BindingAdapterInfo.BindingHandle==NdisBindingHandle&& BindingAdapter Info.CtrlActived) break; } if(i==BindingAdapterNum) goto forward; NdisQueryPacket(Packet, NULL, NULL, NULL, &CurSendPktLen); if(CurSendPktLen>MaxSendPktLen) MaxSendPktLen=CurSendPktLen; if(SendBuffer!=NULL){ CurSendBuffer=SendBuffer+1500*SendPktListHead; SendMACHeader=(PMAC_HEADER)CurSendBuffer; SendIPHeader=(PIP_HEADER)(CurSendBuffer+MAC_HEADER_LEN); CopiedLen=CopyPacketToBuffer( CurSendBuffer, Packet, 0, MAC_HEADER_LEN //+IP_HEADER_LEN ); if(SendMACHeader->ProtocolType==IP_PROTOCOL){ CopiedLen = CopyPacketToBuffer( CurSendBuffer+MAC_HEADER_LEN,//+IP_HEADER_LEN, Packet, MAC_HEADER_LEN, //+IP_HEADER_LEN, CurSendPktLen-MAC_HEADER_LEN //-IP_HEADER_LEN ); switch( QueryAccessList(SendIPHeader,QUERY_SEND_PACKET,&sndkeyno) ){ case PACKET_REFUSE : *Status=NDIS_STATUS_SUCCESS; return; case PACKET_CLEAR : break; case PACKET_MUD : CurSendPktLen = Encrypt_reg( (PUCHAR)SendIPHeader+IP_HEADER_LEN, CurSendPktLen-MAC_HEADER_LEN-IP_HEADER_LEN, sndkeyno ); CurSendPktLen += (MAC_HEADER_LEN+IP_HEADER_LEN); Old_cksum = SendIPHeader->HeaderCRC; SendIPHeader->HeaderCRC = 0; SendIPHeader->LengthL = (CurSendPktLen-MAC_HEADER_LEN)&0xff; SendIPHeader->LengthU = ((CurSendPktLen-MAC_HEADER_LEN)&0xff00)>>8; New_cksum = In_cksum((PUCHAR)SendIPHeader,20); SendIPHeader->HeaderCRC = New_cksum; break; } NdisQueryPacket(SendPktList[SendPktListHead], NULL, NULL, &BUFFER, NULL); if(BUFFER!=NULL){ NdisUnchainBufferAtBack( SendPktList[SendPktListHead],&BUFFER); NdisFreeBuffer(BUFFER); } NdisAllocateBuffer( &ReturnStatus, &BUFFER, SendBufferPoolHandle, CurSendBuffer, //VirtualAddress, CurSendPktLen //Length ); NdisChainBufferAtBack( SendPktList[SendPktListHead],BUFFER); SendPktList[SendPktListHead]->ProtocolReserved[0]=SendPktListHead; ReservedPkt[SendPktListHead]=Packet; NdisSendAddr( Status, NdisBindingHandle, SendPktList[SendPktListHead] ); if(*Status!=NDIS_STATUS_SUCCESS){ SendPktListHead++; if(SendPktListHead==MAX_SEND_PKT_LIST) SendPktListHead=0; } return; } } forward: _asm pop edi _asm pop esi _asm pop ebx //_asm pop ebp _asm leave _asm jmp [NdisSendAddr] } VOID NDIS_API NSHIM_IPSendComplete( IN NDIS_HANDLE NdisBindingContext, IN PNDIS_PACKET Packet, IN NDIS_STATUS Status ) { UCHAR i; for(i=0;i<BindingAdapterNum;i++){ if(BindingAdapterInfo.BindingHandle==(*((PUINT)NdisBindingContext+1)) & & BindingAdapterInfo.CtrlActived) break; } if(i==BindingAdapterNum) goto forward; if(SendBuffer!= NULL){ CurSendBuffer = SendBuffer+SendPktListHead*1500; SendMACHeader = (PMAC_HEADER)CurSendBuffer; CopiedLen = CopyPacketToBuffer( CurSendBuffer, Packet, 0, MAC_HEADER_LEN //+IP_HEADER_LEN ); if(SendMACHeader->ProtocolType==IP_PROTOCOL){ Packet=ReservedPkt[Packet->ProtocolReserved[0]]; } } forward: _asm pop edi _asm pop esi _asm pop ebx _asm leave _asm jmp [IPSendCompleteAddr] } VOID NDIS_API NSHIM_Request( OUT PNDIS_STATUS Status, IN NDIS_HANDLE NdisBindingHandle, IN PNDIS_REQUEST Request ) { UCHAR i; for(i=0;i<BindingAdapterNum;i++){ if(BindingAdapterInfo.BindingHandle==NdisBindingHandle ) break; } if(i==BindingAdapterNum) goto forward; if( Request->RequestType == NdisRequestQueryInformation){ switch ( Request->DATA.QUERY_INFORMATION.Oid ){ case OID_GEN_MAXIMUM_FRAME_SIZE: *(PULONG)Request->DATA.QUERY_INFORMATION.InformationBuffer=1024-14; break; case OID_GEN_MAXIMUM_TOTAL_SIZE: *(PULONG)Request->DATA.QUERY_INFORMATION.InformationBuffer=1024; break; default: goto forward; } Request->DATA.QUERY_INFORMATION.BytesWritten=4; Request->DATA.QUERY_INFORMATION.BytesNeeded=4; *Status=NDIS_STATUS_SUCCESS; return; } forward: _asm pop edi _asm pop esi _asm pop ebx _asm leave _asm jmp [NdisRequestAddr] } VOID NDIS_API NSHIM_RegisterProtocol( OUT PNDIS_STATUS Status, OUT PNDIS_HANDLE NdisProtocolHandle, IN PNDIS_PROTOCOL_CHARACTERISTICS ProtocolCharacteristics, IN UINT CharacteristicsLength ) { if( !(NdisEqualString( &TcpName, &ProtocolCharacteristics->Name, FALSE )) ) goto forward; IPReceiveAddr = ProtocolCharacteristics->ReceiveHandler; ProtocolCharacteristics->ReceiveHandler = NSHIM_IPReceive; IPSendCompleteAddr = ProtocolCharacteristics->SendCompleteHandler; ProtocolCharacteristics->SendCompleteHandler = NSHIM_IPSendComplete; IPOpenAdapterCompleteAddr = ProtocolCharacteristics->OpenAdapterCompleteHan dler; ProtocolCharacteristics->OpenAdapterCompleteHandler = NSHIM_IPOpenAdapterCo mplete; NdisRegisterProtocolAddr( Status, NdisProtocolHandle, ProtocolCharacteristics, CharacteristicsLength ); if( *Status==NDIS_STATUS_SUCCESS) IPHandle = *NdisProtocolHandle; return; forward: _asm pop edi _asm pop esi _asm pop ebx _asm leave _asm jmp [NdisRegisterProtocolAddr] } VOID NDIS_API NSHIM_OpenAdapter( OUT PNDIS_STATUS Status, OUT PNDIS_STATUS OpenErrorStatus, OUT PNDIS_HANDLE NdisBindingHandle, OUT PUINT SelectedMediumIndex, IN PNDIS_MEDIUM MediumArray, IN UINT MediumArraySize, IN NDIS_HANDLE NdisProtocolHandle, IN NDIS_HANDLE ProtocolBindingContext, IN PNDIS_STRING AdapterName, IN UINT OpenOptions, IN PSTRING AddressingInformation OPTIONAL ) { if( NdisProtocolHandle!=IPHandle ) goto forward; PendingOpenAdapter[PendOpenNum].ProtocolBindingContext = ProtocolBindingCon text; PendingOpenAdapter[PendOpenNum].NdisBindingHandle = NdisBindingHandle; PendingOpenAdapter[PendOpenNum].Name.Buffer = AdapterNameBuf [PendOpenNum+MA X_ADAPTER_NUM]; CopyNdisString( &PendingOpenAdapter[PendOpenNum].Name, AdapterName ); PendOpenNum++; NdisOpenAdapterAddr( Status, OpenErrorStatus, NdisBindingHandle, SelectedMediumIndex, MediumArray, MediumArraySize, NdisProtocolHandle, ProtocolBindingContext, AdapterName, OpenOptions, AddressingInformation ); if(*Status==NDIS_STATUS_SUCCESS){ BindingAdapterInfo[BindingAdapterNum].BindingHandle = *NdisBindingHandle; BindingAdapterInfo[BindingAdapterNum].Name.Buffer = AdapterNameBuf [Binding AdapterNum]; CopyNdisString( &BindingAdapterInfo[BindingAdapterNum].Name, AdapterName ); BindingAdapterNum++; } return; forward: _asm pop edi _asm pop esi _asm pop ebx _asm leave _asm jmp [NdisOpenAdapterAddr] } VOID NDIS_API NSHIM_IPOpenAdapterComplete( IN NDIS_HANDLE ProtocolBindingContext, IN NDIS_STATUS Status, IN NDIS_STATUS OpenErrorStatus ) { UCHAR i; for(i=0;i<PendOpenNum;i++){ if(PendingOpenAdapter.ProtocolBindingContext==ProtocolBindingContext) break; } if(i==PendOpenNum) goto forward; if(Status==NDIS_STATUS_SUCCESS){ BindingAdapterInfo[BindingAdapterNum].BindingHandle = *PendingOpenAdapter [ i].NdisBindingHandle; BindingAdapterInfo[BindingAdapterNum].Name.Buffer = AdapterNameBuf [Binding AdapterNum]; CopyNdisString( &BindingAdapterInfo[BindingAdapterNum].Name, &PendingOpenAdapter.Name ); BindingAdapterNum++; } forward: _asm pop edi _asm pop esi _asm pop ebx _asm leave _asm jmp [IPOpenAdapterCompleteAddr] } NDIS_STATUS NDIS_API NSHIM_IPReceive( IN NDIS_HANDLE NdisBindingContext, IN NDIS_HANDLE MacReceiveContext, IN PVOID HeaderBuffer, IN UINT HeaderBufferSize, IN PVOID LookaheadBuffer, IN UINT LookaheadBufferSize, IN UINT PacketSize ) { USHORT sndkeyno; UCHAR i; for(i=0;i<BindingAdapterNum;i++){ if(BindingAdapterInfo.BindingHandle==(*((PUINT)NdisBindingContext+1)) & & BindingAdapterInfo.CtrlActived) break; } if(i==BindingAdapterNum) goto forward; if(LookaheadBufferSize!=PacketSize){ IndicateBuffer=TransferBuffer-HeaderBufferSize-LookaheadBufferSize; NdisMoveMemory( IndicateBuffer, HeaderBuffer, HeaderBufferSize); NdisMoveMemory( IndicateBuffer+HeaderBufferSize, LookaheadBuffer, Lookahea dBufferSize); NdisTransferData( &ReturnStatus, *((PUINT)NdisBindingContext+1), MacReceiveContext, LookaheadBufferSize, // ByteOffset, PacketSize-LookaheadBufferSize, //BytesToTransfer, RcvTransferPacket, &BytesTransfered ); HeaderBuffer=IndicateBuffer; LookaheadBuffer=IndicateBuffer+HeaderBufferSize; LookaheadBufferSize = PacketSize; }else{ IndicateBuffer=HeaderBuffer; } RcvMACHeader=(PMAC_HEADER)IndicateBuffer; if(RcvMACHeader->ProtocolType==IP_PROTOCOL){ RcvIPHeader=(PIP_HEADER)(IndicateBuffer+MAC_HEADER_LEN); switch( QueryAccessList(RcvIPHeader,QUERY_RCV_PACKET,&sndkeyno) ){ case PACKET_REFUSE: return NDIS_STATUS_SUCCESS; case PACKET_CLEAR: goto forward; case PACKET_MUD: PacketSize = Decrypt_reg( (PUCHAR)RcvIPHeader+IP_HEADER_LEN, (USHORT)PacketSize-IP_HEADER_LEN, sndkeyno ); PacketSize += IP_HEADER_LEN; Old_cksum = RcvIPHeader->HeaderCRC; RcvIPHeader->HeaderCRC = 0; RcvIPHeader->LengthL = (USHORT)(PacketSize)&0x00ff; RcvIPHeader->LengthU = ((USHORT)(PacketSize)&0xff00)>>8; New_cksum=In_cksum((PUCHAR)RcvIPHeader,IP_HEADER_LEN); RcvIPHeader->HeaderCRC=New_cksum; LookaheadBufferSize=PacketSize; break; } } forward: _asm pop edi _asm pop esi _asm pop ebx _asm leave _asm jmp [IPReceiveAddr] } /*VOID NDIS_API NSHIM_RegisterMac( OUT PNDIS_STATUS Status, OUT PNDIS_HANDLE NdisMacHandle, IN NDIS_HANDLE NdisWrapperHandle, IN NDIS_HANDLE MacMacContext, IN PNDIS_MAC_CHARACTERISTICS MacCharacteristics, IN UINT CharacteristicsLength ) { WrapperHandle = NdisWrapperHandle; MacContext = MacMacContext; NdisRegisterMacAddr( Status, NdisMacHandle, NdisWrapperHandle, MacMacContext, MacCharacteristics, CharacteristicsLength ); if(*Status==NDIS_STATUS_SUCCESS){ MacHandle = *NdisMacHandle; } return; }*/ UINT CopyPacketToBuffer( IN OUT PUCHAR Buf, // destination IN PNDIS_PACKET Packet, // source packet IN UINT Offset, // offset in packet IN UINT Length // number of bytes to copy ) /*++ Routine Description: Copies bytes from a packet into a buffer. Used to copy data out of a packet during loopback indications. Arguments: Buf - the destination buffer Packet - the source packet Offset - the offset in the packet to start copying at Length - the number of bytes to copy Return Value: The actual number of bytes copied; will be less than Length if the packet length is less than Offset+Length. --*/ { PNDIS_BUFFER CurBuffer; UINT BytesCopied; PUCHAR BufVA; UINT BufLen; UINT ToCopy; UINT CurOffset; BytesCopied = 0; // // First find a spot Offset bytes into the packet. // CurOffset = 0; NdisQueryPacket(Packet, NULL, NULL, &CurBuffer, NULL); while (CurBuffer != (PNDIS_BUFFER)NULL) { NdisQueryBuffer(CurBuffer, (PVOID *)&BufVA, &BufLen); if (CurOffset + BufLen > Offset) { break; } CurOffset += BufLen; NdisGetNextBuffer(CurBuffer, &CurBuffer); } // // See if the end of the packet has already been passed. // if (CurBuffer == (PNDIS_BUFFER)NULL) { return 0; } // // Now copy over Length bytes. // BufVA += (Offset - CurOffset); BufLen -= (Offset - CurOffset); for (;;) { ToCopy = (BytesCopied+BufLen > Length) ? Length - BytesCopied : BufL en; NdisMoveMemory(Buf+BytesCopied, BufVA, ToCopy); BytesCopied += ToCopy; if (BytesCopied == Length) { return BytesCopied; } NdisGetNextBuffer(CurBuffer, &CurBuffer); if (CurBuffer == (PNDIS_BUFFER)NULL) { break; } NdisQueryBuffer(CurBuffer, (PVOID *)&BufVA, &BufLen); } return BytesCopied; } VOID CopyNdisString( PNDIS_STRING D_string, PNDIS_STRING S_string ) { D_string->Length = S_string->Length; D_string->MaximumLength = S_string->MaximumLength; NdisMoveMemory( D_string->Buffer, S_string->Buffer, S_string->Length); return; } #pragma VxD_ICODE_SEG #pragma VxD_IDATA_SEG DWORD _stdcall NSHIM_Device_Init(void) { Out_Debug_String(\"NSHIMSAMP: Dynamic Init\\n\\r\"); return(VXD_SUCCESS); } DWORD _stdcall NSHIM_Sys_Crit_Init(void) { UCHAR i; Ndis_Hook(); if((SendBuffer=(PUCHAR)_HeapAllocate(15000,HEAPLOCKEDIFDP|HEAPZEROINIT))!=N ULL){ // SendMACHeader=(PMAC_HEADER)SendBuffer; // SendIPHeader =(PIP_HEADER)(SendBuffer+14); NdisAllocateBufferPool( &ReturnStatus, &SendBufferPoolHandle, MAX_SEND_BUF_LIST //* NumberOfDescriptors ); if(ReturnStatus!=NDIS_STATUS_SUCCESS){} NdisAllocatePacketPool( &ReturnStatus, &SendPacketPoolHandle, MAX_SEND_PKT_LIST, //NumberOfDescriptors, 1 //ProtocolReservedLength ); if(ReturnStatus!=NDIS_STATUS_SUCCESS){} for(i=0;i<MAX_SEND_PKT_LIST;i++){ NdisAllocatePacket( &ReturnStatus, &SendPktList, SendPacketPoolHandle ); if(ReturnStatus!=NDIS_STATUS_SUCCESS){} } SendPktListHead=SendPktListTail=0; } if((RcvBuffer=(PUCHAR)_HeapAllocate(2000,HEAPLOCKEDIFDP|HEAPZEROINIT))!=NUL L){ TransferBuffer=RcvBuffer+500; NdisAllocatePacketPool( &ReturnStatus, &RcvPacketPoolHandle, 1, //NumberOfDescriptors, 0 //ProtocolReservedLength ); if(ReturnStatus!=NDIS_STATUS_SUCCESS){} NdisAllocatePacket( &ReturnStatus, &RcvTransferPacket, RcvPacketPoolHandle ); if(ReturnStatus!=NDIS_STATUS_SUCCESS){} NdisAllocateBufferPool( &ReturnStatus, &RcvBufferPoolHandle, 1 //* NumberOfDescriptors ); if(ReturnStatus!=NDIS_STATUS_SUCCESS){} NdisAllocateBuffer( &ReturnStatus, &RcvPacketBuffer, RcvBufferPoolHandle, TransferBuffer, //VirtualAddress, 1500 //Length ); if(ReturnStatus!=NDIS_STATUS_SUCCESS){} NdisChainBufferAtBack( RcvTransferPacket, RcvPacketBuffer ); } // InitAccessList(); } |
|
14楼#
发布于:2003-10-15 14:15
是17的那个代码。
他那个NdisBindingContext相当于passthru里面的那个padapter结构,是一个自定义的结构,里面保存有那些handle什么的信息。 NdisBindingContext+1应该是那个NdisBindingHandle的位置。 |
|
|
15楼#
发布于:2003-10-15 14:51
是17的那个代码。 NdisBindingContext在原码中的定义好像都是函数的形式参数来定义的如: NDIS_STATUS NDIS_API NSHIM_IPReceive( IN NDIS_HANDLE NdisBindingContext, IN NDIS_HANDLE MacReceiveContext, 。。。。。。。。 } 从表面上看只能算是个句柄,+1还是不明白? 即使像您所说的那样,+1我认为是指向下一个adapter的地址,但是为什莫要指向下一个呢? 还有这个原码是不是不全啊? |
|
16楼#
发布于:2003-10-15 15:18
在17的那个代码中有一段函数是这样声明的
VOID (NDIS_API *NdisRegisterProtocolAddr)( PNDIS_STATUS , PNDIS_HANDLE , PNDIS_PROTOCOL_CHARACTERISTICS , UINT ); 问题是在语法上这种函数声明形式不大明白,NDIS_API在这里是什莫作用?这个问题挺弱的,请不要见笑!!! |
|
17楼#
发布于:2003-10-15 15:57
那个代码显然是不完全的。
NdisBindingContext相当于passthru里面的padapter,你看看passthru里面是如何使用的padapter结构就应该明白了。这里面NdisBindingContext指向的也应该是他的结构,+1的位置是保存ndisbindhandle的地方,这个指针上ndisopenadapter的时候返回的。 VOID (NDIS_API *NdisRegisterProtocolAddr)( PNDIS_STATUS , PNDIS_HANDLE , PNDIS_PROTOCOL_CHARACTERISTICS , UINT ); 声明的是函数指针,NDIS_API指明函数的调用方式,也就是参数入栈的次序。 |
|
|
18楼#
发布于:2003-10-15 16:23
那个代码显然是不完全的。 passthru的adapter结构我看了,里面有三个定义: PADAPT pPrimaryAdapt; // Pointer to the primary PADAPT pSecondaryAdapt; // Pointer to Secondary\'s structure PADAPT Next; 是不是与上面的定义有关吧,总之要是知道NdisBindingContext结构就清楚了,谢谢 我现在在做windows下的vpn的客户端,不知道17的那段代码能给我带来什莫帮助,也就是说什莫地方是可取的,你给提示一下好吗? 当然我会努力的把这段代码搞懂,谢谢你的帮助!! |
|
19楼#
发布于:2003-10-16 10:25
17的代码是98下vxd hook的代码,如果你在2k下做的话还是直接看passthru吧。
|
|
|
上一页
下一页