byssx752
驱动牛犊
驱动牛犊
  • 注册日期2008-06-16
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分15分
  • 威望81点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1983回复:1

在passthru里面获取ip地址的问题

楼主#
更多 发布于:2009-06-05 13:40
各位大虾:
在网上查找过,可以通过PtRequestComplete里再
case NdisRequestSetInformation:
        ASSERT( Oid != OID_PNP_SET_POWER);
      if (Oid == OID_GEN_NETWORK_LAYER_ADDRESSES )
  {    
             获取ip地址;
    }
有一个疑问,何时会进入到这个逻辑,我自己写了一个查询,试图进入上面的逻辑,但是不行
  PIO_STACK_LOCATION  pIrpSp;
   NTSTATUS            NtStatus = STATUS_SUCCESS;
   ULONG               BytesReturned = 0;
   PUCHAR              ioBuffer = NULL;
   ULONG               inputBufferLength;
   ULONG               outputBufferLength;
   NDIS_OID            Oid;
   PADAPT              pAdapt;
   POPEN_CONTEXT       pOpenContext;
   PNDIS_REQUEST_EX    pLocalRequest;
   NDIS_STATUS         NdisStatus;
   char                szFunction[] = "DevQueryInformation()";

   UNREFERENCED_PARAMETER(pDeviceObject);

   pIrpSp = IoGetCurrentIrpStackLocation(pIrp);

   DbgPrint("[%s] [%s] [%u]:==>Pt DevQueryInformation: FileObject %p\n", __file__, szFunction, __LINE__, pIrpSp->FileObject);

   ioBuffer = pIrp->AssociatedIrp.SystemBuffer;
   inputBufferLength  = pIrpSp->Parameters.DeviceIoControl.InputBufferLength;
   outputBufferLength = pIrpSp->Parameters.DeviceIoControl.OutputBufferLength;

   pOpenContext = pIrpSp->FileObject->FsContext;

   if( !pOpenContext )
   {
      DbgPrint("[%s] [%s] [%u]:Invalid Handle\n", __file__, szFunction, __LINE__);
      
      NtStatus = STATUS_INVALID_HANDLE;
      goto CompleteTheIRP;
   }


   DbgPrint("[%s] [%s] [%u]:Found Open Context\n", __file__, szFunction, __LINE__);

   pAdapt = pOpenContext->pAdapt;

   if( !pAdapt )
   {
      DbgPrint("[%s] [%s] [%u]:Adapter Not Found\n", __file__, szFunction, __LINE__);
      
      NtStatus = STATUS_INVALID_HANDLE;
      goto CompleteTheIRP;
   }

   //
   // Sanity Check On Input Buffer/OID
   //
   if( inputBufferLength != sizeof( NDIS_OID ) )
   {
      DbgPrint("[%s] [%s] [%u]:Invalid OID Input Buffer Length\n", __file__, szFunction, __LINE__);

      NtStatus = STATUS_INVALID_PARAMETER;
      goto CompleteTheIRP;
   }

   Oid = *(PNDIS_OID )ioBuffer;

   DbgPrint("[%s] [%s] [%u]:Query for Information on OID 0x%8.8X\n", __file__, szFunction, __LINE__, Oid );

   //
   // Fail Open If Unbind Is In Progress
   //
   NdisAcquireSpinLock(&pAdapt->Lock);

   if( pAdapt->UnbindingInProcess )
   {
      NdisReleaseSpinLock(&pAdapt->Lock);
      DbgPrint("[%s] [%s] [%u]:Unbind In Process\n", __file__, szFunction, __LINE__);

      NtStatus = STATUS_INVALID_DEVICE_STATE;
      goto CompleteTheIRP;
   }

   //
   // All other queries are failed, if the miniport is not at D0,
   //
   if (pAdapt->MPDeviceState > NdisDeviceStateD0)
   {
      NdisReleaseSpinLock(&pAdapt->Lock);
      DbgPrint("[%s] [%s] [%u]:Invalid Miniport Device State\n", __file__, szFunction, __LINE__);

      NtStatus = STATUS_INVALID_DEVICE_STATE;
      goto CompleteTheIRP;
   }

   //
   // This is in the process of powering down the system, always fail the request
   //
   if (pAdapt->StandingBy == TRUE)
   {
      NdisReleaseSpinLock(&pAdapt->Lock);
      DbgPrint("[%s] [%s] [%u]:Miniport Powering Down\n", __file__, szFunction, __LINE__);

      NtStatus = STATUS_INVALID_DEVICE_STATE;
      goto CompleteTheIRP;
   }

   NdisReleaseSpinLock(&pAdapt->Lock);

   //
   // Now (Finally) Make The NDIS Request...
   //

   //
   // May need to add ref counts to adapt and open context. Also, bump
   // a counter of outstanding requests...
   //

   DevRefOpenContext( pOpenContext );

   pLocalRequest = &pOpenContext->LocalRequest;

   pLocalRequest->Request.RequestType = NdisRequestQueryInformation;
   pLocalRequest->Request.DATA.QUERY_INFORMATION.Oid =OID_GEN_NETWORK_LAYER_ADDRESSES ;
   pLocalRequest->Request.DATA.QUERY_INFORMATION.InformationBuffer = ioBuffer;
   pLocalRequest->Request.DATA.QUERY_INFORMATION.InformationBufferLength = outputBufferLength;
   pLocalRequest->Request.DATA.QUERY_INFORMATION.BytesNeeded = 0;
   pLocalRequest->Request.DATA.QUERY_INFORMATION.BytesWritten = 0;

   pLocalRequest->RequestCompleteHandler = DevRequestComplete;
   pLocalRequest->RequestContext = pOpenContext;

   NdisResetEvent( &pLocalRequest->RequestEvent );

   NdisRequest(
      &NdisStatus,
      pAdapt->BindingHandle,
      (PNDIS_REQUEST )pLocalRequest
      );

   if( NdisStatus != NDIS_STATUS_PENDING )
   {
      DevRequestComplete( pAdapt, pLocalRequest, NdisStatus );
   }

   NdisWaitEvent( &pLocalRequest->RequestEvent, 0 );

   NdisStatus = pLocalRequest->RequestStatus;

   if( NdisStatus == NDIS_STATUS_SUCCESS )
   {
      BytesReturned = pLocalRequest->Request.DATA.QUERY_INFORMATION.BytesWritten;

      if( BytesReturned > outputBufferLength )
      {
         BytesReturned = outputBufferLength;
      }

      NtStatus = STATUS_SUCCESS;
   }
   else
   {
      NDIS_STATUS_TO_NT_STATUS( NdisStatus, &NtStatus);
   }

   DevDerefOpenContext( pOpenContext );

   //
   // Complete The IRP
   //
CompleteTheIRP:

   pIrp->IoStatus.Information = BytesReturned;
   pIrp->IoStatus.Status = NtStatus;
   IoCompleteRequest(pIrp, IO_NO_INCREMENT);

   DbgPrint("[%s] [%s] [%u]:<== Pt DevQueryInformation\n", __file__, szFunction, __LINE__);
  
   return NtStatus;
查询后,返回值始终是invalid oid,不知道什么原因,麻烦高人帮忙解答
pasding
驱动牛犊
驱动牛犊
  • 注册日期2005-10-12
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分19分
  • 威望141点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2009-07-19 21:40
协议驱动会调用的,你不必调用。一般初始化好久自动被协议驱动调用了。
游客

返回顶部