阅读:1354回复:1
TDI编程,遇到不能解决的问题了,bytessent 返回的值始终为0
TDI编程,遇到不能解决的问题了,bytessent 返回的值始终为0
我写的TDI程序,下面是接收例程,pBytesSent为指向返回的发送的字节数, 我调用这个例程 status = KsSend( pksocket,"senddata",sizeof( "senddata" ),&bytessent ); 不知道为什么,bytessent 返回的值始终为0 请高手指点 NTSTATUS KsSend(IN PKSOCKET pKsocket, IN PVOID SendData, IN ULONG DataLen, IN UINT *pBytesSent) { KEVENT SendEvent; PIRP pIrp; PMDL pMdl; NTSTATUS status; char * pSendBuffer; IO_STATUS_BLOCK IoStatus = {0}; KeInitializeEvent( &SendEvent, NotificationEvent, FALSE ); pSendBuffer = ExAllocatePool( NonPagedPool, DataLen ); memcpy( pSendBuffer, SendData, DataLen ); // build an IRP to connect to a remote host pIrp = TdiBuildInternalDeviceControlIrp( TDI_SEND, pKsocket -> pTcpDevObj, // TDI driver's device object. pKsocket -> pConnFileObj, // Connection (endpoint) file object. &SendEvent, // Event to be signalled when Irp completes. &IoStatus // I/O status block. ); if( NULL == pIrp ) { DbgPrint( "Could not get an IRP for TDI_SEND" ); if( pSendBuffer )ExFreePool( pSendBuffer ); return( STATUS_INSUFFICIENT_RESOURCES ); } // must run at <= DISPATCH_LEVEL ASSERT( KeGetCurrentIrql() <= DISPATCH_LEVEL ); pMdl = IoAllocateMdl( pSendBuffer, DataLen, FALSE, FALSE, pIrp ); if( pMdl ==NULL ) { DbgPrint( "Could not get an MDL for TDI_SEND" ); if( pSendBuffer )ExFreePool( pSendBuffer ); return( STATUS_INSUFFICIENT_RESOURCES ); } // must run at < DISPATCH_LEVEL for pageable memory ASSERT( KeGetCurrentIrql() < DISPATCH_LEVEL ); __try { MmProbeAndLockPages( pMdl, // (Try to) fix buffer. KernelMode, IoModifyAccess ); } __except(EXCEPTION_EXECUTE_HANDLER) { DbgPrint( "Exception calling MmProbeAndLockPages" ); if( pSendBuffer )ExFreePool( pSendBuffer ); return ( STATUS_INSUFFICIENT_RESOURCES ); } TdiBuildSend( pIrp, pKsocket -> pTcpDevObj, // TDI driver's device object. pKsocket -> pConnectFileObj, // Connection (endpoint) file object. NULL, // I/O completion routine. NULL, // Context for I/O completion routine. pMdl, // MDL address. 0, // Flags. 0 => send as normal TSDU. DataLen // Length of buffer mapped by MDL. ); // set our own completion routine // must run at PASSIVE_LEVEL ASSERT( KeGetCurrentIrql() == PASSIVE_LEVEL ); IoSetCompletionRoutine( pIrp, TDICompletionRoutine, &SendEvent, TRUE, TRUE, TRUE); //make the call // must run at <= DISPATCH_LEVEL ASSERT( KeGetCurrentIrql() <= DISPATCH_LEVEL ); // Send the command to the underlying TDI driver status = IoCallDriver( pKsocket -> pTcpDevObj, pIrp ); // wait on the IRP, if required... if ( STATUS_PENDING == status ) { DbgPrint( "Waiting on IRP (send)..." ); status = KeWaitForSingleObject( &SendEvent, Executive, KernelMode, FALSE, 0 ); if ( STATUS_TIMEOUT == status ) { //something is wrong DbgPrint( "STATUS_TIMEOUT (send), status 0x%08X", status ); } if ( STATUS_SUCCESS != IoStatus.Status ) { //something is wrong DbgPrint( "Completion of IRP failed (send), status 0x%08X", IoStatus.Status ); } } *pBytesSent = ( UINT )IoStatus.Information; status = IoStatus.Status; if(pMdl) { MmUnlockPages(pMdl); IoFreeMdl(pMdl); } return status; } |
|
沙发#
发布于:2007-11-12 10:05
解决了,*pBytesSent = ( UINT ) pIRP -> IoStatus.Information;
|
|