This repository has been archived by the owner on Jul 26, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add IPHlpApi - GetExtendedTcpTable * PR feedback * [chore] Add IPHlpApi * Make IPHlpApi dependency conditional Co-authored-by: Andrew Arnott <Andrew.arnott@Microsoft.com>
- Loading branch information
1 parent
a62e5d3
commit 840c6ac
Showing
13 changed files
with
678 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFrameworks>net472</TargetFrameworks> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\IPHlpApi\IPHlpApi.csproj" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright © .NET Foundation and Contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using System.Net.NetworkInformation; | ||
using System.Net.Sockets; | ||
using System.Runtime.InteropServices; | ||
using PInvoke; | ||
using Xunit; | ||
|
||
public class IPHlpApiFacts | ||
{ | ||
[Fact] | ||
public void StructSizeTest() | ||
{ | ||
Assert.Equal(0x04, Marshal.SizeOf<IPHlpApi.MIB_TCPTABLE_OWNER_PID>()); | ||
Assert.Equal(0x18, Marshal.SizeOf<IPHlpApi.MIB_TCPROW_OWNER_PID>()); | ||
} | ||
|
||
[Fact] | ||
public unsafe void GetExtendedTcpTableTest() | ||
{ | ||
IntPtr tcpTablePtr = IntPtr.Zero; | ||
int tcpTableLength = 0; | ||
|
||
if (IPHlpApi.GetExtendedTcpTable(tcpTablePtr, ref tcpTableLength, bOrder: true, AddressFamily.InterNetwork, IPHlpApi.TCP_TABLE_CLASS.TCP_TABLE_OWNER_PID_ALL, 0) == Win32ErrorCode.ERROR_INSUFFICIENT_BUFFER) | ||
{ | ||
try | ||
{ | ||
tcpTablePtr = Marshal.AllocHGlobal(tcpTableLength); | ||
|
||
if (IPHlpApi.GetExtendedTcpTable(tcpTablePtr, ref tcpTableLength, bOrder: true, AddressFamily.InterNetwork, IPHlpApi.TCP_TABLE_CLASS.TCP_TABLE_OWNER_PID_ALL, 0) == Win32ErrorCode.ERROR_SUCCESS) | ||
{ | ||
IPHlpApi.MIB_TCPTABLE_OWNER_PID* tcpTable = (IPHlpApi.MIB_TCPTABLE_OWNER_PID*)tcpTablePtr; | ||
var tableSize = Marshal.SizeOf<IPHlpApi.MIB_TCPTABLE_OWNER_PID>(); | ||
|
||
IPHlpApi.MIB_TCPROW_OWNER_PID* tcpRow = (IPHlpApi.MIB_TCPROW_OWNER_PID*)(tcpTablePtr + tableSize); | ||
|
||
for (int i = 0; i < tcpTable->dwNumEntries; ++i) | ||
{ | ||
Assert.InRange(tcpRow->LocalPort, 0, 65535); | ||
Assert.True(Enum.IsDefined(typeof(TcpState), tcpRow->dwState)); | ||
|
||
tcpRow++; | ||
} | ||
} | ||
} | ||
finally | ||
{ | ||
if (tcpTablePtr != IntPtr.Zero) | ||
{ | ||
Marshal.FreeHGlobal(tcpTablePtr); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,292 @@ | ||
AddIPAddress | ||
AllocateAndGetInterfaceInfoFromStack | ||
AllocateAndGetIpAddrTableFromStack | ||
CancelIfTimestampConfigChange | ||
CancelIPChangeNotify | ||
CancelMibChangeNotify2 | ||
CaptureInterfaceHardwareCrossTimestamp | ||
CloseCompartment | ||
CloseGetIPPhysicalInterfaceForDestination | ||
ConvertCompartmentGuidToId | ||
ConvertCompartmentIdToGuid | ||
ConvertGuidToString | ||
ConvertInterfaceAliasToLuid | ||
ConvertInterfaceGuidToLuid | ||
ConvertInterfaceIndexToLuid | ||
ConvertInterfaceLuidToAlias | ||
ConvertInterfaceLuidToGuid | ||
ConvertInterfaceLuidToIndex | ||
ConvertInterfaceLuidToName | ||
ConvertInterfaceNameToLuid | ||
ConvertInterfacePhysicalAddressToLuid | ||
ConvertIpv4MaskToLength | ||
ConvertLengthToIpv4Mask | ||
ConvertRemoteInterfaceAliasToLuid | ||
ConvertRemoteInterfaceGuidToLuid | ||
ConvertRemoteInterfaceIndexToLuid | ||
ConvertRemoteInterfaceLuidToAlias | ||
ConvertRemoteInterfaceLuidToGuid | ||
ConvertRemoteInterfaceLuidToIndex | ||
ConvertStringToGuid | ||
ConvertStringToInterfacePhysicalAddress | ||
CreateAnycastIpAddressEntry | ||
CreateCompartment | ||
CreateIpForwardEntry | ||
CreateIpForwardEntry2 | ||
CreateIpNetEntry | ||
CreateIpNetEntry2 | ||
CreatePersistentTcpPortReservation | ||
CreatePersistentUdpPortReservation | ||
CreateProxyArpEntry | ||
CreateSortedAddressPairs | ||
CreateUnicastIpAddressEntry | ||
DeleteAnycastIpAddressEntry | ||
DeleteCompartment | ||
DeleteIPAddress | ||
DeleteIpForwardEntry | ||
DeleteIpForwardEntry2 | ||
DeleteIpNetEntry | ||
DeleteIpNetEntry2 | ||
DeletePersistentTcpPortReservation | ||
DeletePersistentUdpPortReservation | ||
DeleteProxyArpEntry | ||
DeleteUnicastIpAddressEntry | ||
DisableMediaSense | ||
do_echo_rep | ||
do_echo_req | ||
EnableRouter | ||
FlushIpNetTable | ||
FlushIpNetTable2 | ||
FlushIpPathTable | ||
FreeDnsSettings | ||
FreeInterfaceDnsSettings | ||
FreeMibTable | ||
GetAdapterIndex | ||
GetAdapterOrderMap | ||
GetAdaptersAddresses | ||
GetAdaptersInfo | ||
GetAnycastIpAddressEntry | ||
GetAnycastIpAddressTable | ||
GetBestInterface | ||
GetBestInterfaceEx | ||
GetBestRoute | ||
GetBestRoute2 | ||
GetCurrentThreadCompartmentId | ||
GetCurrentThreadCompartmentScope | ||
GetDefaultCompartmentId | ||
GetDnsSettings | ||
GetExtendedTcpTable | ||
GetExtendedUdpTable | ||
GetFriendlyIfIndex | ||
GetIcmpStatistics | ||
GetIcmpStatisticsEx | ||
GetIfEntry | ||
GetIfEntry2 | ||
GetIfEntry2Ex | ||
GetIfStackTable | ||
GetIfTable | ||
GetIfTable2 | ||
GetIfTable2Ex | ||
GetInterfaceCompartmentId | ||
GetInterfaceCurrentTimestampCapabilities | ||
GetInterfaceDnsSettings | ||
GetInterfaceHardwareTimestampCapabilities | ||
GetInterfaceInfo | ||
GetInvertedIfStackTable | ||
GetIpAddrTable | ||
GetIpErrorString | ||
GetIpForwardEntry2 | ||
GetIpForwardTable | ||
GetIpForwardTable2 | ||
GetIpInterfaceEntry | ||
GetIpInterfaceTable | ||
GetIpNetEntry2 | ||
GetIpNetTable | ||
GetIpNetTable2 | ||
GetIpNetworkConnectionBandwidthEstimates | ||
GetIpPathEntry | ||
GetIpPathTable | ||
GetIpStatistics | ||
GetIpStatisticsEx | ||
GetJobCompartmentId | ||
GetMulticastIpAddressEntry | ||
GetMulticastIpAddressTable | ||
GetNetworkConnectivityHint | ||
GetNetworkConnectivityHintForInterface | ||
GetNetworkInformation | ||
GetNetworkParams | ||
GetNumberOfInterfaces | ||
GetOwnerModuleFromPidAndInfo | ||
GetOwnerModuleFromTcp6Entry | ||
GetOwnerModuleFromTcpEntry | ||
GetOwnerModuleFromUdp6Entry | ||
GetOwnerModuleFromUdpEntry | ||
GetPerAdapterInfo | ||
GetPerTcp6ConnectionEStats | ||
GetPerTcp6ConnectionStats | ||
GetPerTcpConnectionEStats | ||
GetPerTcpConnectionStats | ||
GetRTTAndHopCount | ||
GetSessionCompartmentId | ||
GetTcp6Table | ||
GetTcp6Table2 | ||
GetTcpStatistics | ||
GetTcpStatisticsEx | ||
GetTcpStatisticsEx2 | ||
GetTcpTable | ||
GetTcpTable2 | ||
GetTeredoPort | ||
GetUdp6Table | ||
GetUdpStatistics | ||
GetUdpStatisticsEx | ||
GetUdpStatisticsEx2 | ||
GetUdpTable | ||
GetUnicastIpAddressEntry | ||
GetUnicastIpAddressTable | ||
GetUniDirectionalAdapterInfo | ||
GetWPAOACSupportLevel | ||
Icmp6CreateFile | ||
Icmp6ParseReplies | ||
Icmp6SendEcho2 | ||
IcmpCloseHandle | ||
IcmpCreateFile | ||
IcmpParseReplies | ||
IcmpSendEcho | ||
IcmpSendEcho2 | ||
IcmpSendEcho2Ex | ||
if_indextoname | ||
if_nametoindex | ||
InitializeCompartmentEntry | ||
InitializeIpForwardEntry | ||
InitializeIpInterfaceEntry | ||
InitializeUnicastIpAddressEntry | ||
InternalCleanupPersistentStore | ||
InternalCreateAnycastIpAddressEntry | ||
InternalCreateIpForwardEntry | ||
InternalCreateIpForwardEntry2 | ||
InternalCreateIpNetEntry | ||
InternalCreateIpNetEntry2 | ||
InternalCreateUnicastIpAddressEntry | ||
InternalDeleteAnycastIpAddressEntry | ||
InternalDeleteIpForwardEntry | ||
InternalDeleteIpForwardEntry2 | ||
InternalDeleteIpNetEntry | ||
InternalDeleteIpNetEntry2 | ||
InternalDeleteUnicastIpAddressEntry | ||
InternalFindInterfaceByAddress | ||
InternalGetAnycastIpAddressEntry | ||
InternalGetAnycastIpAddressTable | ||
InternalGetBoundTcp6EndpointTable | ||
InternalGetBoundTcpEndpointTable | ||
InternalGetForwardIpTable2 | ||
InternalGetIfEntry2 | ||
InternalGetIfTable | ||
InternalGetIfTable2 | ||
InternalGetIpAddrTable | ||
InternalGetIpForwardEntry2 | ||
InternalGetIpForwardTable | ||
InternalGetIpInterfaceEntry | ||
InternalGetIpInterfaceTable | ||
InternalGetIpNetEntry2 | ||
InternalGetIpNetTable | ||
InternalGetIpNetTable2 | ||
InternalGetIPPhysicalInterfaceForDestination | ||
InternalGetMulticastIpAddressEntry | ||
InternalGetMulticastIpAddressTable | ||
InternalGetRtcSlotInformation | ||
InternalGetTcp6Table2 | ||
InternalGetTcp6TableWithOwnerModule | ||
InternalGetTcp6TableWithOwnerPid | ||
InternalGetTcpTable | ||
InternalGetTcpTable2 | ||
InternalGetTcpTableEx | ||
InternalGetTcpTableWithOwnerModule | ||
InternalGetTcpTableWithOwnerPid | ||
InternalGetTunnelPhysicalAdapter | ||
InternalGetUdp6TableWithOwnerModule | ||
InternalGetUdp6TableWithOwnerPid | ||
InternalGetUdpTable | ||
InternalGetUdpTableEx | ||
InternalGetUdpTableWithOwnerModule | ||
InternalGetUdpTableWithOwnerPid | ||
InternalGetUnicastIpAddressEntry | ||
InternalGetUnicastIpAddressTable | ||
InternalIcmpCreateFileEx | ||
InternalSetIfEntry | ||
InternalSetIpForwardEntry | ||
InternalSetIpForwardEntry2 | ||
InternalSetIpInterfaceEntry | ||
InternalSetIpNetEntry | ||
InternalSetIpNetEntry2 | ||
InternalSetIpStats | ||
InternalSetTcpEntry | ||
InternalSetTeredoPort | ||
InternalSetUnicastIpAddressEntry | ||
IpReleaseAddress | ||
IpRenewAddress | ||
LookupPersistentTcpPortReservation | ||
LookupPersistentUdpPortReservation | ||
NhGetGuidFromInterfaceName | ||
NhGetInterfaceDescriptionFromGuid | ||
NhGetInterfaceNameFromDeviceGuid | ||
NhGetInterfaceNameFromGuid | ||
NhpAllocateAndGetInterfaceInfoFromStack | ||
NotifyAddrChange | ||
NotifyCompartmentChange | ||
NotifyIfTimestampConfigChange | ||
NotifyIpInterfaceChange | ||
NotifyNetworkConnectivityHintChange | ||
NotifyRouteChange | ||
NotifyRouteChange2 | ||
NotifyStableUnicastIpAddressTable | ||
NotifyTeredoPortChange | ||
NotifyUnicastIpAddressChange | ||
NTPTimeToNTFileTime | ||
NTTimeToNTPTime | ||
OpenCompartment | ||
ParseNetworkString | ||
PfAddFiltersToInterface | ||
PfAddGlobalFilterToInterface | ||
PfBindInterfaceToIndex | ||
PfBindInterfaceToIPAddress | ||
PfCreateInterface | ||
PfDeleteInterface | ||
PfDeleteLog | ||
PfGetInterfaceStatistics | ||
PfMakeLog | ||
PfRebindFilters | ||
PfRemoveFilterHandles | ||
PfRemoveFiltersFromInterface | ||
PfRemoveGlobalFilterFromInterface | ||
PfSetLogBuffer | ||
PfTestPacket | ||
PfUnBindInterface | ||
register_icmp | ||
ResolveIpNetEntry2 | ||
ResolveNeighbor | ||
RestoreMediaSense | ||
SendARP | ||
SetAdapterIpAddress | ||
SetCurrentThreadCompartmentId | ||
SetCurrentThreadCompartmentScope | ||
SetDnsSettings | ||
SetIfEntry | ||
SetInterfaceDnsSettings | ||
SetIpForwardEntry | ||
SetIpForwardEntry2 | ||
SetIpInterfaceEntry | ||
SetIpNetEntry | ||
SetIpNetEntry2 | ||
SetIpStatistics | ||
SetIpStatisticsEx | ||
SetIpTTL | ||
SetJobCompartmentId | ||
SetNetworkInformation | ||
SetPerTcp6ConnectionEStats | ||
SetPerTcp6ConnectionStats | ||
SetPerTcpConnectionEStats | ||
SetPerTcpConnectionStats | ||
SetSessionCompartmentId | ||
SetTcpEntry | ||
SetUnicastIpAddressEntry | ||
UnenableRouter |
Oops, something went wrong.