Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than iphlpapi, prefix the name with the module name and a period.
GetIpAddrTable (iphlpapi)
.
C# Signature:
[DllImport("iphlpapi.dll", SetLastError=true)]
public static extern int GetIpAddrTable(IntPtr pIpAddrTable, ref int pdwSize, bool bOrder);
VB Signature:
Declare Ansi Function
GetIpAddrTable Lib "iphlpapi.dll" (ByRef ipTable As IntPtr, ByRef tableSize As IntPtr, ByVal ordered As Boolean) As UInt32
foreach (System.Net.IPAddress strIP in System.Net.Dns.GetHostAddresses(System.Net.Dns.GetHostName()))
{
Console.WriteLine(strIP.ToString());
}
Notes:
None.
Tips & Tricks:
Please add some!
Sample Code:
IntPtr pBuf = IntPtr.Zero;
int nBufSize = 0;
// get the required buffer size
GetIpAddrTable( IntPtr.Zero, ref nBufSize, false );
// allocate the buffer
pBuf = Marshal.AllocHGlobal( nBufSize );
int r = GetIpAddrTable( pBuf, ref nBufSize, false );
if ( r != 0 )
throw new System.ComponentModel.Win32Exception( r );
int entrySize = Marshal.SizeOf(typeof(MIB_IPADDRROW));
int nEntries = Marshal.ReadInt32(pBuf);
int tableStartAddr = (int)pBuf + sizeof(int);
for (int i = 0; i < nEntries; i++)
{
IntPtr pEntry = (IntPtr)(tableStartAddr + i * entrySize);
MIB_IPADDRROW addrStruct = (MIB_IPADDRROW)Marshal.PtrToStructure(pEntry, typeof(MIB_IPADDRROW));
string ipAddrStr = IPToString( IPAddress.NetworkToHostOrder((int)addrStruct._address) );
string ipMaskStr = IPToString( IPAddress.NetworkToHostOrder((int)addrStruct._mask) );
}
if ( pBuf != IntPtr.Zero )
Marshal.FreeHGlobal( pBuf );
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).