C
cyberco
Thanks to help from this group I got a long way towards changing the
route table on my WM5 PPC (.Net CF) device (TyTN). It seems that
Iphlpapi.dll is what I should use. Unfortunately I'm inexperienced in
using p/invoke from within a C# application. Say I want to invoke
GetIpForwardTable from Iphlpapi.dll as described here:
http://msdn.microsoft.com/library/d...cecomm5/html/wce50lrfcreateipforwardentry.asp
=========== Iphlpapi.dll ===============
DWORD GetIpForwardTable(
PMIB_IPFORWARDTABLE pIpForwardTable,
PULONG pdwSize,
BOOL bOrder
);
==================================
This uses MIB_IPFORWARDTABLE, which is described here:
http://msdn.microsoft.com/library/d...s/wcecomm5/html/wce50lrfmibipforwardtable.asp
=========== Iphlpapi.dll ===============
typedef struct _MIB_IPFORWARDTABLE {
DWORD dwNumEntries;
MIB_IPFORWARDROW table[ANY_SIZE];
} MIB_IPFORWARDTABLE, *PMIB_IPFORWARDTABLE;
===================================
In C# I declare
============ C# =====================
[StructLayout(LayoutKind.Sequential)]
public struct MIB_IPFORWARDTABLE {
public int dwNumEntries;
public MIB_IPFORWARDROW[] table;
}
====================================
It usess MIB_IPFORWARDROW as well, which is described here:
http://msdn.microsoft.com/library/d...-us/wcecomm5/html/wce50lrfmibipforwardrow.asp
============ C# =====================
[StructLayout(LayoutKind.Sequential)]
public struct MIB_IPFORWARDROW {
public UInt32 dwForwardDest;
public UInt32 dwForwardMask;
public UInt32 dwForwardPolicy;
public UInt32 dwForwardNextHop;
public UInt32 dwForwardIfIndex;
public UInt32 dwForwardType;
public UInt32 dwForwardProto;
public UInt32 dwForwardAge;
public UInt32 dwForwardNextHopAS;
public UInt32 dwForwardMetric1;
public UInt32 dwForwardMetric2;
public UInt32 dwForwardMetric3;
public UInt32 dwForwardMetric4;
public UInt32 dwForwardMetric5;
}
====================================
Now, what I wonder is how I declare 'GetIpForwardTable'? My guess is as
follows, but I have no idea what for types to use for the parameters
etc.
============ C# =====================
[DllImport("Iphlpapi.dll")]
[return: MarshalAs(UnmanagedType.U4)]
static extern int GetIpForwardTable(ref MIB_IPFORWARDTABLE
pIpForwardTable, UInt32 pdwSize, bool bOrder);
====================================
So my questions are:
1. What are my the C# types to use?
2. How do I invoke the method
3. What return types can I expect?
4. Where are the returntypes specified?
Ultimately I want to be able to add and remove IPFORWARDROWs to the
route table. At this moment I keep getting a return value of 87, but I
don't know what that means or what I'm doing wrong.
Thanks in advance for any help.
route table on my WM5 PPC (.Net CF) device (TyTN). It seems that
Iphlpapi.dll is what I should use. Unfortunately I'm inexperienced in
using p/invoke from within a C# application. Say I want to invoke
GetIpForwardTable from Iphlpapi.dll as described here:
http://msdn.microsoft.com/library/d...cecomm5/html/wce50lrfcreateipforwardentry.asp
=========== Iphlpapi.dll ===============
DWORD GetIpForwardTable(
PMIB_IPFORWARDTABLE pIpForwardTable,
PULONG pdwSize,
BOOL bOrder
);
==================================
This uses MIB_IPFORWARDTABLE, which is described here:
http://msdn.microsoft.com/library/d...s/wcecomm5/html/wce50lrfmibipforwardtable.asp
=========== Iphlpapi.dll ===============
typedef struct _MIB_IPFORWARDTABLE {
DWORD dwNumEntries;
MIB_IPFORWARDROW table[ANY_SIZE];
} MIB_IPFORWARDTABLE, *PMIB_IPFORWARDTABLE;
===================================
In C# I declare
============ C# =====================
[StructLayout(LayoutKind.Sequential)]
public struct MIB_IPFORWARDTABLE {
public int dwNumEntries;
public MIB_IPFORWARDROW[] table;
}
====================================
It usess MIB_IPFORWARDROW as well, which is described here:
http://msdn.microsoft.com/library/d...-us/wcecomm5/html/wce50lrfmibipforwardrow.asp
============ C# =====================
[StructLayout(LayoutKind.Sequential)]
public struct MIB_IPFORWARDROW {
public UInt32 dwForwardDest;
public UInt32 dwForwardMask;
public UInt32 dwForwardPolicy;
public UInt32 dwForwardNextHop;
public UInt32 dwForwardIfIndex;
public UInt32 dwForwardType;
public UInt32 dwForwardProto;
public UInt32 dwForwardAge;
public UInt32 dwForwardNextHopAS;
public UInt32 dwForwardMetric1;
public UInt32 dwForwardMetric2;
public UInt32 dwForwardMetric3;
public UInt32 dwForwardMetric4;
public UInt32 dwForwardMetric5;
}
====================================
Now, what I wonder is how I declare 'GetIpForwardTable'? My guess is as
follows, but I have no idea what for types to use for the parameters
etc.
============ C# =====================
[DllImport("Iphlpapi.dll")]
[return: MarshalAs(UnmanagedType.U4)]
static extern int GetIpForwardTable(ref MIB_IPFORWARDTABLE
pIpForwardTable, UInt32 pdwSize, bool bOrder);
====================================
So my questions are:
1. What are my the C# types to use?
2. How do I invoke the method
3. What return types can I expect?
4. Where are the returntypes specified?
Ultimately I want to be able to add and remove IPFORWARDROWs to the
route table. At this moment I keep getting a return value of 87, but I
don't know what that means or what I'm doing wrong.
Thanks in advance for any help.