Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

GetIfTable (iphlpapi)
 
.
Summary
P/ invoque for GetIfTable iphlpapi function. Only C# example. You need also a MIB_IFROW structure

C# Signature:

/// <summary>
    /// Get the information about the current Network adapter in the system
    /// </summary>
    /// <param name="pIfTable">A pointer to a buffer that receives the interface table as a MIB_IFTABLE structure</param>
    /// <param name="pdwSize">
    /// size of buffer
    /// On input, specifies the size in bytes of the buffer pointed to by the pIfTable parameter.
    /// On output, if the buffer is not large enough to hold the returned interface table,
    ///  the function sets this parameter equal to the required buffer size in bytes
    /// </param>
    /// <param name="bOrder">
    /// sort the table by index
    /// A Boolean value that specifies whether the returned interface table should be sorted
    /// in ascending order by interface index. If this parameter is TRUE, the table is sorted.
    /// </param>
    /// <returns>
    /// If the function succeeds, the return value is
    /// NO_ERROR = 0
    /// ERROR_INSUFFICIENT_BUFFER = 122
    /// </returns>
    [DllImport("Iphlpapi.dll")SetLastError=true]
    public static extern uint GetIfTable(IntPtr pIfTable, ref uint pdwSize, bool bOrder);

VB Signature:

Declare Function GetIfTable Lib "iphlpapi.dll" (TODO) As TODO

User-Defined Types:

None.

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

None.

Tips & Tricks:

Get if Table Wrapper Class

/// <summary>
    /// Wrapper to unmanaged code. to use all in C# declarations
    /// </summary>
    public class IPHelperWrapper
    {
    #region  fields
    /// <summary>
    /// MIB_IFROW Declaration
    /// </summary>
    protected static IPHelperTraslation.MIB_IFROW netWorkInfoBlock;

    /// <summary>
    /// MIB_IFROW structure array. Content the active networks connection
    /// </summary>
    public static IPHelperTraslation.MIB_IFROW[] mRows;
    #endregion

    #region Wrapper Method
    /// <summary>
    /// Get the Active Interface networks in an array of MIB_IFROW.
    /// each network comes in a row. See MIB_IFROW in IPHelper Traslation for more
    /// information about MIB_IFROW
    /// </summary>
    /// <returns>
    /// A array of MIB_IFROW structure
    /// </returns>
    public static IPHelperTraslation.MIB_IFROW[] GetNetworkInterfaceBlock()
    {

        uint size = 0;
        IPHelperTraslation.GetIfTable(IntPtr.Zero, ref size, false);
        IntPtr buf = Marshal.AllocHGlobal((int)size);
        IPHelperTraslation.GetIfTable(buf, ref size, false);
        int numEntries = Marshal.ReadInt32(buf);
        int pRows = 4 + (int)buf;
        mRows = new IPHelperTraslation.MIB_IFROW[numEntries];
        for (int i = 0; i < numEntries; i++)
        {
        mRows[i] = (IPHelperTraslation.MIB_IFROW)Marshal.PtrToStructure((IntPtr)pRows, typeof(IPHelperTraslation.MIB_IFROW));
        pRows += Marshal.SizeOf(typeof(IPHelperTraslation.MIB_IFROW));
        }
        Marshal.FreeHGlobal(buf);
        return mRows;

    }
    #endregion
    }

Documentation
GetIfTable on MSDN

Please edit this page!

Do you have...

  • 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).

 
Access PInvoke.net directly from VS:
Terms of Use
Find References
Show Printable Version
Revisions