Hi
I am writing my own little functions to open and close an UDP Port over TDI.
The open function works fine and when i use netstat -a i see that the port is
opened. But when i call the close function the port is still open.
Open:
// open an specific port
NTSTATUS UdpToTdi_OpenPort(UDP_PORT_INFO* port,ushort udpport)
{
NTSTATUS status = STATUS_SUCCESS;
PFILE_FULL_EA_INFORMATION pEa;
PTA_IP_ADDRESS pSin;
PTCP_REQUEST_SET_INFORMATION_EX pSetInfoEx;
PIO_STACK_LOCATION StackLocation;
void *pBuf = &gl_tos_value;
gl_tos_size = sizeof(gl_tos_value);
if(gl_StatusInit == 0)
{
DbgPrint("TdiInterfaceUdp::UdpToTdi_OpenPort: TDI not initialized\n");
return STATUS_ACCESS_DENIED;
}
InitializeObjectAttributes(&port->Attr,
&gl_DeviceName,
OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
NULL,
NULL);
pEa = (PFILE_FULL_EA_INFORMATION)port->pEa_buf;
pEa->NextEntryOffset = 0;
pEa->Flags = 0;
pEa->EaNameLength = TDI_TRANSPORT_ADDRESS_LENGTH;
RtlCopyMemory(pEa->EaName, TdiTransportAddress, pEa->EaNameLength + 1);
pEa->EaValueLength = sizeof(TA_IP_ADDRESS);
pSin = (PTA_IP_ADDRESS)(pEa->EaName + pEa->EaNameLength + 1);
pSin->TAAddressCount = 1;
pSin->Address[0].AddressLength = TDI_ADDRESS_LENGTH_IP;
pSin->Address[0].AddressType = TDI_ADDRESS_TYPE_IP;
pSin->Address[0].Address[0].sin_port = RtlUshortByteSwap(udpport);
pSin->Address[0].Address[0].in_addr = 0; // own ip address (0...he is
searching it himself)
RtlZeroMemory(pSin->Address[0].Address[0].sin_zero,
sizeof(pSin->Address[0].Address[0].sin_zero));
status = ZwCreateFile(&port->hFile,
GENERIC_READ | GENERIC_WRITE,
&port->Attr,
&port->IoStatus,
0,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ | FILE_SHARE_WRITE,
FILE_OPEN,
0,
pEa,
sizeof(port->pEa_buf)
);
if (!NT_SUCCESS(status))
{
DbgPrint("TdiInterfaceUdp::UdpToTdi_OpenPort: ZwCreateFile failed\n");
return status;
}
status = ObReferenceObjectByHandle(port->hFile,
GENERIC_READ | GENERIC_WRITE,
NULL,
KernelMode,
(PVOID *)&port->pAddrFileObj,
NULL);
if (!NT_SUCCESS(status))
{
DbgPrint("TdiInterfaceUdp::UdpToTdi_OpenPort: ObReferenceObjectByHandle
failed\n");
return status;
}
// set the QoS bits in the IP header
pSetInfoEx = (PTCP_REQUEST_SET_INFORMATION_EX)&(port->pSetInfoEx);
RtlZeroMemory(pSetInfoEx, sizeof(TCP_REQUEST_SET_INFORMATION_EX) +
gl_tos_size);
pSetInfoEx->ID.toi_entity.tei_entity = CL_TL_ENTITY;
pSetInfoEx->ID.toi_entity.tei_instance = 0;
pSetInfoEx->ID.toi_class = INFO_CLASS_PROTOCOL;
pSetInfoEx->ID.toi_type = INFO_TYPE_ADDRESS_OBJECT;
pSetInfoEx->ID.toi_id = AO_OPTION_TOS;
RtlMoveMemory(pSetInfoEx->Buffer, pBuf, gl_tos_size);
pSetInfoEx->BufferSize = gl_tos_size;
port->pIrp = IoBuildDeviceIoControlRequest(IOCTL_TCP_SET_INFORM ATION_EX,
gl_pDevice,
(PVOID)pSetInfoEx,
sizeof(TCP_REQUEST_SET_INFORMATION_EX) + gl_tos_size,
NULL,
0,
FALSE,
NULL,
NULL);
if(port->pIrp)
{
StackLocation = IoGetNextIrpStackLocation(port->pIrp);
StackLocation->DeviceObject = gl_pDevice;
StackLocation->FileObject = port->pAddrFileObj;
status = IoCallDriver(gl_pDevice, port->pIrp);
if(status != STATUS_SUCCESS && status != STATUS_PENDING)
DbgPrint("TdiInterfaceUdp::UdpToTdi_OpenPort: IoCallDriver failed\n");
}
return status;
}
Close:
NTSTATUS UdpToTdi_ClosePort(UDP_PORT_INFO* port)
{
NTSTATUS status = STATUS_SUCCESS;
if(gl_StatusInit == 0)
{
DbgPrint("TdiInterfaceUdp::UdpToTdi_ClosePort: TDI not initialized\n");
return STATUS_ACCESS_DENIED;
}
status = ObDereferenceObject(port->pAddrFileObj);
if(!NT_SUCCESS(status))
DbgPrint("TdiInterfaceUdp::UdpToTdi_ClosePort: ObDereferenceObject
failed\n");
status = ZwClose(&port->hFile);
if(!NT_SUCCESS(status))
DbgPrint("TdiInterfaceUdp::UdpToTdi_ClosePort: ZwClose failed\n");
return status;
}
Did i miss anything in the close function?
Harald
|