Click to See Complete Forum and Search --> : Need help


blazerguns
August 30th, 2006, 05:47 AM
Hi all,

Iam really trying to make this one work but it is not. Iam not able to figure out why. You guys hopefully would give a sol.
This is my code:

[DllImport("Iphlpapi.dll")]
public extern static int GetInterfaceInfo(out IP_INTERFACE_INFO pIface, out UInt64 ReqBt);


[StructLayout(LayoutKind.Sequential)]
public struct IP_INTERFACE_INFO
{
public UInt32 NumAdapters;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 50)] /*Max Adapters iam assuming as 50*/
public IP_ADAPTER_INDEX_MAP[] Adapter;
}

[StructLayout(LayoutKind.Sequential)]
public struct IP_ADAPTER_INDEX_MAP
{
public UInt32 Index;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)] /*The value is MAX_ADAPTER_NAME = 128*/
public char[] DevName;
}


public IP_ADAPTER_INDEX_MAP[] GetIfaceInfo()
{
UInt64 val;
IP_INTERFACE_INFO IfaceInfo = new IP_INTERFACE_INFO();
if (GetInterfaceInfo(out IfaceInfo, out val) != 0)
{

}
if (GetInterfaceInfo(out IfaceInfo, out val) != 0)
{

}
//maxNoIface = IfaceInfo.NumAdapters;
return IfaceInfo.Adapter;


}

Well the call seems to work fine and in my system i have two ethernet card so even the value of IfaceInfo.NumAdapters = 2. But when i print the IP_ADAPTER_INDEX_MAP array i find that the arr[0] has all the correct value.
But arr[1] seems to be null and arr[2] seems to contain the second adaptors info but the index is wrong. Iam able to come to this conclusion because of the value displayed as forwardIfIndex in GetIpForwardTable() call.

Please help me with this.

Varun