阅读:1393回复:3
为什么只有在packapp中设置了filter后,packet协议驱动程序才能进入PacketReceivePacket函数?
NTSTATUS
PacketIoControl( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp ) { ... ... ... open = DeviceObject->DeviceExtension; IoIncrement(open); // // Check to see whether you are still bound to the adapter // if(!open->Bound) { Irp->IoStatus.Status = status = STATUS_UNSUCCESSFUL; IoCompleteRequest(Irp, IO_NO_INCREMENT); IoDecrement(open); return status; } DebugPrint(("Function code is %08lx buff size=%08lx %08lx\n", functionCode,irpSp->Parameters.DeviceIoControl.InputBufferLength, irpSp->Parameters.DeviceIoControl.OutputBufferLength)); // // Important: Since we have marked the IRP pending, we must return // STATUS_PENDING even we happen to complete the IRP synchronously. // IoMarkIrpPending(Irp); if (functionCode == IOCTL_PROTOCOL_RESET) { DebugPrint(("IoControl - Reset request\n")); // // Since NDIS doesn't have an interface to cancel a request // pending at miniport, we cannot set a cancel routine. // As a result if the application that made the request // terminates, we wait in the Cleanup routine for all pending // NDIS requests to complete. // ExInterlockedInsertTailList( &open->ResetIrpList, &Irp->Tail.Overlay.ListEntry, &open->ResetQueueLock); NdisReset( &status, open->AdapterHandle ); if (status != NDIS_STATUS_PENDING) { DebugPrint(("IoControl - ResetComplete being called\n")); PacketResetComplete( open, status ); } } else { // // See if it is an Ndis request // PPACKET_OID_DATA OidData=Irp->AssociatedIrp.SystemBuffer; pRequest = ExAllocatePool(NonPagedPool, sizeof(INTERNAL_REQUEST)); if(NULL == pRequest) { Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES; IoCompleteRequest (Irp, IO_NO_INCREMENT); IoDecrement(open); return STATUS_PENDING; } pRequest->Irp=Irp; if (((functionCode == IOCTL_PROTOCOL_SET_OID) || (functionCode == IOCTL_PROTOCOL_QUERY_OID)) && (irpSp->Parameters.DeviceIoControl.InputBufferLength == irpSp->Parameters.DeviceIoControl.OutputBufferLength) && (irpSp->Parameters.DeviceIoControl.InputBufferLength >= sizeof(PACKET_OID_DATA)) && (irpSp->Parameters.DeviceIoControl.InputBufferLength >= sizeof(PACKET_OID_DATA)-1+OidData->Length)) { DebugPrint(("IoControl: Request: Oid=%08lx, Length=%08lx\n", OidData->Oid,OidData->Length)); // // The buffer is valid // if (functionCode == IOCTL_PROTOCOL_SET_OID) { pRequest->Request.RequestType=NdisRequestSetInformation; pRequest->Request.DATA.SET_INFORMATION.Oid=OidData->Oid; pRequest->Request.DATA.SET_INFORMATION.InformationBuffer= OidData->Data; pRequest->Request.DATA.SET_INFORMATION.InformationBufferLength= OidData->Length; } else { pRequest->Request.RequestType=NdisRequestQueryInformation; pRequest->Request.DATA.QUERY_INFORMATION.Oid= OidData->Oid; pRequest->Request.DATA.QUERY_INFORMATION.InformationBuffer= OidData->Data; pRequest->Request.DATA.QUERY_INFORMATION.InformationBufferLength= OidData->Length; } // // submit the request // NdisRequest( &status, open->AdapterHandle, &pRequest->Request ); } else { // // Buffer too small. The irp is completed by // PacketRequestComplete routine. // status=NDIS_STATUS_FAILURE; pRequest->Request.DATA.SET_INFORMATION.BytesRead=0; pRequest->Request.DATA.QUERY_INFORMATION.BytesWritten=0; } if (status != NDIS_STATUS_PENDING) { DebugPrint(("Calling RequestCompleteHandler\n")); PacketRequestComplete( open, &pRequest->Request, status ); } } return STATUS_PENDING; } 以上是PACKET例子中PacketIoControl函数中的后半部分源代码。 在packapp程序中只有执行了 Result=DeviceIoControl( AdapterObject->hFile, (DWORD) Set ? IOCTL_PROTOCOL_SET_OID : IOCTL_PROTOCOL_QUERY_OID, OidData, sizeof(PACKET_OID_DATA)-1+OidData->Length, OidData, sizeof(PACKET_OID_DATA)-1+OidData->Length, &BytesReturned, NULL ); 后,即设置了 filter后,packet驱动程序才能进入PacketReceivePacket函数, 请问这是为什么? |
|
|
沙发#
发布于:2004-04-07 09:14
能MAIL一份你的完整给我吗?
youngyt@133sh.com 因为设成混杂模式后就接收所有的包,下层NIC DRVIER有时会资源不足等问题只调用PTRECEIVE。相关的可以看以前的关于这两个函数的讨论。 |
|
板凳#
发布于:2004-04-07 17:34
其实不管设置什么filter,都会进入PacketReceivePacket
函数,我搞不清楚PacketIoControl后半段的代码的作用是什么, 怎样使得收到数据后能进入PacketReceivePacket函数的, 请指教。 |
|
|
地板#
发布于:2004-04-14 19:33
哎。。。。要设置网卡的工作模式呀。。。没有设置好工作模式怎么工作呀????就这么简单。。。
|
|