/// <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);
Declare Function GetIfTable Lib "iphlpapi.dll" (TODO) As TODO
None.
System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()
None.
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
}