Hello,
I’m having trouble with TdiBuildConnect(). Whenever I try to connect to a
listening server (which has been tested and works) I get
STATUS_HOST_UNREACHABLE. I tried to get my connection work since this
morning and I am becoming crazy… Help !!
Here samples of my source code:
NTSTATUS Connect(IN PFILE_OBJECT FileObject,IN ULONG Address,IN USHORT
Port,
IN PLARGE_INTEGER Time,OUT PTDI_CONNECTION_INFORMATION
ReturnConnectionInfo)
{
PIRP Irp; // IRP
KEVENT Event; // Event
NTSTATUS Status; // NT status
IO_STATUS_BLOCK IoStatus; // I/O status block
TA_IP_ADDRESS AdresseIP; // Connection address
PDEVICE_OBJECT DeviceObject; // Target device
TDI_CONNECTION_INFORMATION RequestConnectionInfo; // connection info
// Set IRP for the request
KeInitializeEvent(&Event,NotificationEvent,FALSE);
DeviceObject=IoGetRelatedDeviceObject(FileObject);
Irp=TdiBuildInternalDeviceControlIrp(TDI_CONNECT,DeviceObject,FileObject,&Event,&IoStatus);
if(Irp!=NULL)
{
// Set address structure
RtlZeroMemory(&AdresseIP,sizeof(TA_IP_ADDRESS));
AdresseIP.TAAddressCount=1;
AdresseIP.Address[0].AddressLength=TDI_ADDRESS_LENGTH_IP;
AdresseIP.Address[0].AddressType=TDI_ADDRESS_TYPE_IP;
AdresseIP.Address[0].Address[0].sin_port=W_LITTLE_TO_BIG_ENDIAN(Port);
AdresseIP.Address[0].Address[0].in_addr=D_LITTLE_TO_BIG_ENDIAN(Address);
// Set info structure
RequestConnectionInfo.UserDataLength=0;
RequestConnectionInfo.UserData=NULL;
RequestConnectionInfo.OptionsLength=0;
RequestConnectionInfo.Options=NULL;
RequestConnectionInfo.RemoteAddressLength=sizeof(TA_IP_ADDRESS);
RequestConnectionInfo.RemoteAddress=&AdresseIP;
// Connection request
TdiBuildConnect(Irp,DeviceObject,FileObject,NULL,NULL,Time,&RequestConnectionInfo,ReturnConnectionInfo);
Status=IoCallDriver(DeviceObject,Irp);
if(Status==STATUS_PENDING)
{
Status=KeWaitForSingleObject(&Event,Executive,KernelMode,FALSE,0);
}
}
else
Status=STATUS_INSUFFICIENT_RESOURCES;
return Status == STATUS_SUCCESS ? IoStatus.Status : Status;
}
Thanks !