NetworkTools: Add support for multiple traceroute results for the same hop
@@ -140,9 +140,25 @@ VOID TracertQueueHostLookup(
memcpy(&sockAddrIn, SocketAddress, sizeof(IN_ADDR));
if (NT_SUCCESS(RtlIpv4AddressToStringEx(&sockAddrIn, 0, addressString, &addressStringLength)))
+ {
+ if (!PhIsNullOrEmptyString(Node->IpAddressString))
+ {
+ // Make sure we don't append the same address.
+ if (PhFindStringInString(Node->IpAddressString, 0, addressString) == -1)
+ {
+ // Some routes can return multiple addresses for the same ping or 'hop',
+ // so make sure we don't lose this information (as every other tracert tool does)
+ // and instead append the additional IP address to the node.
+ PhMoveReference(&Node->IpAddressString,
+ PhFormatString(L"%s, %s", PhGetString(Node->IpAddressString), addressString)
+ );
+ }
+ }
+ else
{
PhMoveReference(&Node->IpAddressString, PhCreateString(addressString));
}
+ }
resolve = PhCreateAlloc(sizeof(TRACERT_RESOLVE_WORKITEM));
memset(resolve, 0, sizeof(TRACERT_RESOLVE_WORKITEM));
@@ -175,9 +191,25 @@ VOID TracertQueueHostLookup(
memcpy(&sockAddrIn6, SocketAddress, sizeof(IN6_ADDR));
if (NT_SUCCESS(RtlIpv6AddressToStringEx(&sockAddrIn6, 0, 0, addressString, &addressStringLength)))
+ {
+ if (!PhIsNullOrEmptyString(Node->IpAddressString))
+ {
+ // Make sure we don't append the same address.
+ if (PhFindStringInString(Node->IpAddressString, 0, addressString) == -1)
+ {
+ // Some routes can return multiple addresses for the same ping or 'hop',
+ // so make sure we don't lose this information (as every other tracert tool does)
+ // and instead append the additional IP address to the node.
+ PhMoveReference(&Node->IpAddressString,
+ PhFormatString(L"%s, %s", PhGetString(Node->IpAddressString), addressString)
+ );
+ }
+ }
+ else
{
PhMoveReference(&Node->IpAddressString, PhCreateString(addressString));
}
+ }
resolve = PhCreateAlloc(sizeof(TRACERT_RESOLVE_WORKITEM));
memset(resolve, 0, sizeof(TRACERT_RESOLVE_WORKITEM));
@@ -695,14 +727,34 @@ INT_PTR CALLBACK TracertDlgProc(
PPH_STRING hostName = (PPH_STRING)lParam;
PTRACERT_ROOT_NODE traceNode;
- traceNode = FindTracertNode(context, index);
+ if (traceNode = FindTracertNode(context, index))
+ {
+ if (!PhIsNullOrEmptyString(traceNode->HostnameString))
+ {
+ // Make sure we don't append the same hostname.
+ if (PhFindStringInString(traceNode->HostnameString, 0, PhGetString(hostName)) == -1)
+ {
+ // Some routes can return multiple addresses for the same ping or 'hop',
+ // so make sure we don't lose this information (as every other tracert tool does)
+ // and instead append the additional hostname to the node.
+ PhMoveReference(&traceNode->HostnameString,
+ PhFormatString(L"%s, %s", PhGetString(traceNode->HostnameString), PhGetString(hostName))
+ );
- if (traceNode)
+ UpdateTracertNode(context, traceNode);
+ }
+ else
+ {
+ PhDereferenceObject(hostName);
+ }
+ }
+ else
{
PhMoveReference(&traceNode->HostnameString, hostName);
UpdateTracertNode(context, traceNode);
}
+ }
else
{
PhDereferenceObject(hostName);
