https://git.reactos.org/?p=reactos.git;a=commitdiff;h=500a5151ea1ef6d35ea4f…
commit 500a5151ea1ef6d35ea4f77ecd16679ce7bdf852
Author: Pierre Schweitzer <pierre(a)reactos.org>
AuthorDate: Thu Nov 22 21:50:21 2018 +0100
Commit: Pierre Schweitzer <pierre(a)reactos.org>
CommitDate: Thu Nov 22 21:52:11 2018 +0100
[TCPIP] Fix returned IP address when querying TCP connections
This gives something like that now:
https://twitter.com/HeisSpiter/status/1065706156331606017 :-)
CORE-15363
---
drivers/network/tcpip/tcpip/ninfo.c | 41 ++++++++++++++++++++++++-------------
1 file changed, 27 insertions(+), 14 deletions(-)
diff --git a/drivers/network/tcpip/tcpip/ninfo.c b/drivers/network/tcpip/tcpip/ninfo.c
index 54e9be4955..42894767ea 100644
--- a/drivers/network/tcpip/tcpip/ninfo.c
+++ b/drivers/network/tcpip/tcpip/ninfo.c
@@ -177,43 +177,56 @@ TDI_STATUS InfoTdiQueryGetIPSnmpInfo( TDIEntityID ID,
return Status;
}
+#define ntohs(n) ((((n) & 0xff) << 8) | (((n) & 0xff00) >> 8))
+
TDI_STATUS InfoTdiQueryGetConnectionTcpTable(PADDRESS_FILE AddrFile,
PNDIS_BUFFER Buffer,
PUINT BufferSize)
{
MIB_TCPROW TcpRow;
- PADDRESS_FILE EndPoint;
- TDI_STATUS Status = TDI_INVALID_REQUEST;
+ TDI_STATUS Status = TDI_SUCCESS;
TI_DbgPrint(DEBUG_INFO, ("Called.\n"));
- EndPoint = NULL;
TcpRow.State = 0; /* FIXME */
+ TcpRow.dwLocalAddr = AddrFile->Address.Address.IPv4Address;
+ TcpRow.dwLocalPort = AddrFile->Port;
if (AddrFile->Listener != NULL)
{
- EndPoint = AddrFile->Listener->AddressFile;
- TcpRow.State = MIB_TCP_STATE_LISTEN;
- }
- else if (AddrFile->Connection != NULL)
- EndPoint = AddrFile->Connection->AddressFile;
+ PADDRESS_FILE EndPoint;
- TcpRow.dwLocalAddr = AddrFile->Address.Address.IPv4Address;
- TcpRow.dwLocalPort = AddrFile->Port;
+ EndPoint = AddrFile->Listener->AddressFile;
- if (EndPoint != NULL)
- {
+ TcpRow.State = MIB_TCP_STATE_LISTEN;
TcpRow.dwRemoteAddr = EndPoint->Address.Address.IPv4Address;
TcpRow.dwRemotePort = EndPoint->Port;
}
+ else if (AddrFile->Connection != NULL &&
+ AddrFile->Connection->SocketContext != NULL)
+ {
+ TA_IP_ADDRESS EndPoint;
+
+ Status = TCPGetSockAddress(AddrFile->Connection,
(PTRANSPORT_ADDRESS)&EndPoint, TRUE);
+ if (NT_SUCCESS(Status))
+ {
+ ASSERT(EndPoint.TAAddressCount >= 1);
+ ASSERT(EndPoint.Address[0].AddressLength == TDI_ADDRESS_LENGTH_IP);
+ TcpRow.dwRemoteAddr = EndPoint.Address[0].Address[0].in_addr;
+ TcpRow.dwRemotePort = ntohs(EndPoint.Address[0].Address[0].sin_port);
+ }
+ }
else
{
TcpRow.dwRemoteAddr = 0;
TcpRow.dwRemotePort = 0;
}
- Status = InfoCopyOut( (PCHAR)&TcpRow, sizeof(TcpRow),
- Buffer, BufferSize );
+ if (NT_SUCCESS(Status))
+ {
+ Status = InfoCopyOut( (PCHAR)&TcpRow, sizeof(TcpRow),
+ Buffer, BufferSize );
+ }
TI_DbgPrint(DEBUG_INFO, ("Returning %08x\n", Status));