阅读:1165回复:2
新手提问,老大们帮忙
小弟刚刚开始学NDIS,基本的东西了解一些
我试着改passthou,想让别人ping主机的 时候发个ARP包过去,冲他IP. 下面是code: PtBindAdapter{ .... NdisAllocateBufferPool(Status, &SendHandle, 3028); .... } PtReceive{ .... UCHAR s[42]={ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, 0x00,0x0C,0x29,0x1F,0x1B,0xB1, 0x08,0x06, 0x00,0x01, 0x08,0x00, 0x06,0x04, 0x00,0x01, 0x00,0x0C,0x29,0x1F,0x1B,0xB1, 0xC0,0xA8,0xB5,0x01, 0x00,0x00,0x00,0x00,0x00,0x00, 0xC0,0xA8,0xB5,0x03}; //arp packet PUCHAR pPacketContent; PNDIS_BUFFER firstBuffer; PVOID v_pt; UINT buffer_length; buffer_length = HeaderBufferSize + 1; if ( ((char*)LookAheadBuffer)[20] == 0x08 ) { NdisAllocateMemory( &pPacketContent, 60, 0, HighestAcceptableMax); NdisZeroMemory(pPacketContent, 60); NdisMoveMemory(pPacketContent, s, 42); NdisDprAllocatePacket(&Status, &pp, pAdapt->RecvPacketPoolHandle); NdisAllocateBuffer(&Status,&firstBuffer,send_handle,pPacketContent,60); NdisChainBufferAtFront( pp, firstBuffer); pp->Private.Head->Next = NULL; pp->Private.Tail = NULL; NdisSetPacketFlags(pp, NDIS_FLAGS_DONT_LOOPBACK); is_send = TRUE; NdisSend(&Status, pAdapt->BindingHandle, pp); Status = NDIS_STATUS_NOT_ACCEPTED; return Status; ....... } PtSendComplete{ ... NdisIMCopySendCompletePerPacketInfo (Pkt, Packet); if(is_send) { NdisUnchainBufferAtFront(Packet ,&firstBuffer); NdisQueryBufferSafe(firstBuffer, &pPacketContent, &BufLength,32 ); DBGPRINT(" pt send complete query buffer complete\n"); if(pPacketContent!= NULL) NdisFreeMemory(pPacketContent,BufLength, 0); NdisFreeBuffer(firstBuffer); NdisDprFreePacket(Packet); is_send=FALSE; } else { NdisDprFreePacket(Packet); NdisMSendComplete(pAdapt->MiniportHandle, Pkt, Status); } ... } 我是在虚拟机上试的,ping的时候可以返回arp包,但是虚拟机上马上挂掉 好像是在PtSendComplete中的NdisIMCopySendCompletePerPacketInfo (Pkt, Packet); 挂掉的,不知道怎么解决,请各位老大帮帮忙 (NdisIMCopySendCompletePerPacketInfo到底是干什么用的????DDK上没读懂) :( |
|
|
沙发#
发布于:2004-03-22 12:33
要对NDISSEND返回的情况做检查,如果不是PENDING,你的资源如何释放呀。
|
|
板凳#
发布于:2004-03-23 13:19
不好意思,那部分没贴出来
NdisSend(.....) if(Status != NDIS_STATUS_PENDING) { NdisUnchainBufferAtFront(pp ,&firstBuffer); NdisQueryBufferSafe(firstBuffer, &pPacketContent, &buffer_length, 32); if(pPacketContent != NULL) NdisFreeMemory(pPacketContent, buffer_length, 0); NdisFreeBuffer(firstBuffer); is_send = FALSE; }; 但是好像不只这里的问题 |
|
|