I've posted this question in
'microsoft.public.dotnet.framework.compactframewor k' as well, but
despite the great help I still haven't solved the problem. So before
going the C++ route I would like to see if anybody in this group may
have the answer.
What I'm trying to do is change the route table of my Windows Mobile 5
Pocket PC (.Net CF) device (TyTN) using C#. This is probably similar as
doing it on standard CF. Using Iphlpapi.dll I can retrieve the route
table, but I am unable to change/add a route. I have specified the
following structs/pinvokes:
=========START===========
[StructLayout(LayoutKind.Sequential)]
public struct MIB_IPFORWARDROW {
public UInt32 dwForwardDest; //destination IP address.
public UInt32 dwForwardMask; //Subnet mask
public UInt32 dwForwardPolicy; //conditions for multi-path
route. Unused, specify 0.
public UInt32 dwForwardNextHop; //IP address of the next hop.
Own address?
public UInt32 dwForwardIfIndex; //index of interface
public UInt32 dwForwardType; //route type
public UInt32 dwForwardProto; //routing protocol.
public UInt32 dwForwardAge; //age of route.
public UInt32 dwForwardNextHopAS; //autonomous system number. 0
if not relevant
public int dwForwardMetric1; //-1 if not used (goes for all
metrics)
public int dwForwardMetric2;
public int dwForwardMetric3;
public int dwForwardMetric4;
public int dwForwardMetric5;
}
[StructLayout(LayoutKind.Sequential)]
public struct MIB_IPFORWARDTABLE {
public int dwNumEntries; //number of route entries in
the table.
public MIB_IPFORWARDROW[] table;
}
[DllImport("Iphlpapi.dll")]
[return: MarshalAs(UnmanagedType.U4)]
public static extern int CreateIpForwardEntry(ref MIB_IPFORWARDROW
pRoute);
[DllImport("Iphlpapi.dll")]
[return: MarshalAs(UnmanagedType.U4)]
public static extern int DeleteIpForwardEntry(ref MIB_IPFORWARDROW
pRoute);
[DllImport("Iphlpapi.dll")]
[return: MarshalAs(UnmanagedType.U4)]
public static extern int SetIpForwardEntry(ref MIB_IPFORWARDROW
pRoute);
[DllImport("Iphlpapi.dll")]
[return: MarshalAs(UnmanagedType.U4)]
public static extern int GetIpForwardTable(byte[] pIpForwardTable, out
int pdwSize, bool bOrder);
=========END===========
I invoke these methods as follows:
=========START===========
public int createIpForwardEntry(UInt32 destIPAddress, UInt32 destMask,
UInt32 nextHopIPAddress,
UInt32 ifIndex) {
MIB_IPFORWARDROW mifr = new MIB_IPFORWARDROW();
mifr.dwForwardDest = destIPAddress;
mifr.dwForwardMask = destMask;
mifr.dwForwardPolicy = Convert.ToUInt32(0);
mifr.dwForwardNextHop = nextHopIPAddress;
mifr.dwForwardIfIndex = ifIndex; //?
mifr.dwForwardType = Convert.ToUInt32(4);
mifr.dwForwardProto = Convert.ToUInt32(3);
mifr.dwForwardAge = Convert.ToUInt32(0);
mifr.dwForwardNextHopAS = Convert.ToUInt32(0);
mifr.dwForwardMetric1 = -1;
mifr.dwForwardMetric2 = -1;
mifr.dwForwardMetric3 = -1;
mifr.dwForwardMetric4 = -1;
mifr.dwForwardMetric5 = -1;
return CreateIpForwardEntry(ref mifr);
}
=========END===========
All IP addresses are added as unsigned ints (double checked whether
they are correct. I even tried adding a row that I just successfully
retrieved (thereby skipping my own structure). If that gives me an
error code 87 (invalid param).
Is there anybody here that has successfully done this or has a few
relevant pointers? Preferably C# examples, but C++ examples are a step
in the right direction. Thanks! 3 6955
Probably can find something here: http://msdn2.microsoft.com/en-us/library/aa915714.aspx
chanmm
"cyberco" <cy*****@gmail.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
I've posted this question in
'microsoft.public.dotnet.framework.compactframewor k' as well, but
despite the great help I still haven't solved the problem. So before
going the C++ route I would like to see if anybody in this group may
have the answer.
What I'm trying to do is change the route table of my Windows Mobile 5
Pocket PC (.Net CF) device (TyTN) using C#. This is probably similar as
doing it on standard CF. Using Iphlpapi.dll I can retrieve the route
table, but I am unable to change/add a route. I have specified the
following structs/pinvokes:
=========START===========
[StructLayout(LayoutKind.Sequential)]
public struct MIB_IPFORWARDROW {
public UInt32 dwForwardDest; //destination IP address.
public UInt32 dwForwardMask; //Subnet mask
public UInt32 dwForwardPolicy; //conditions for multi-path
route. Unused, specify 0.
public UInt32 dwForwardNextHop; //IP address of the next hop.
Own address?
public UInt32 dwForwardIfIndex; //index of interface
public UInt32 dwForwardType; //route type
public UInt32 dwForwardProto; //routing protocol.
public UInt32 dwForwardAge; //age of route.
public UInt32 dwForwardNextHopAS; //autonomous system number. 0
if not relevant
public int dwForwardMetric1; //-1 if not used (goes for all
metrics)
public int dwForwardMetric2;
public int dwForwardMetric3;
public int dwForwardMetric4;
public int dwForwardMetric5;
}
[StructLayout(LayoutKind.Sequential)]
public struct MIB_IPFORWARDTABLE {
public int dwNumEntries; //number of route entries in
the table.
public MIB_IPFORWARDROW[] table;
}
[DllImport("Iphlpapi.dll")]
[return: MarshalAs(UnmanagedType.U4)]
public static extern int CreateIpForwardEntry(ref MIB_IPFORWARDROW
pRoute);
[DllImport("Iphlpapi.dll")]
[return: MarshalAs(UnmanagedType.U4)]
public static extern int DeleteIpForwardEntry(ref MIB_IPFORWARDROW
pRoute);
[DllImport("Iphlpapi.dll")]
[return: MarshalAs(UnmanagedType.U4)]
public static extern int SetIpForwardEntry(ref MIB_IPFORWARDROW
pRoute);
[DllImport("Iphlpapi.dll")]
[return: MarshalAs(UnmanagedType.U4)]
public static extern int GetIpForwardTable(byte[] pIpForwardTable, out
int pdwSize, bool bOrder);
=========END===========
I invoke these methods as follows:
=========START===========
public int createIpForwardEntry(UInt32 destIPAddress, UInt32 destMask,
UInt32 nextHopIPAddress,
UInt32 ifIndex) {
MIB_IPFORWARDROW mifr = new MIB_IPFORWARDROW();
mifr.dwForwardDest = destIPAddress;
mifr.dwForwardMask = destMask;
mifr.dwForwardPolicy = Convert.ToUInt32(0);
mifr.dwForwardNextHop = nextHopIPAddress;
mifr.dwForwardIfIndex = ifIndex; //?
mifr.dwForwardType = Convert.ToUInt32(4);
mifr.dwForwardProto = Convert.ToUInt32(3);
mifr.dwForwardAge = Convert.ToUInt32(0);
mifr.dwForwardNextHopAS = Convert.ToUInt32(0);
mifr.dwForwardMetric1 = -1;
mifr.dwForwardMetric2 = -1;
mifr.dwForwardMetric3 = -1;
mifr.dwForwardMetric4 = -1;
mifr.dwForwardMetric5 = -1;
return CreateIpForwardEntry(ref mifr);
}
=========END===========
All IP addresses are added as unsigned ints (double checked whether
they are correct. I even tried adding a row that I just successfully
retrieved (thereby skipping my own structure). If that gives me an
error code 87 (invalid param).
Is there anybody here that has successfully done this or has a few
relevant pointers? Preferably C# examples, but C++ examples are a step
in the right direction. Thanks!
Those look like really useful utilities, but, forgive me for asking an
obvious question, where can I get those tools? The location at the top
of the page doesn't mean much to me... :(
chanmm wrote:
Probably can find something here: http://msdn2.microsoft.com/en-us/library/aa915714.aspx
chanmm
I figured maybe the problem is that I should reserve some memory for
the new MIB_IPFORWARDROW I'm creating (as I do in the following code)?
=========START===========
public int createIpForwardEntry(UInt32 destIPAddress, UInt32 destMask,
UInt32 nextHopIPAddress,
UInt32 ifIndex) {
MIB_IPFORWARDROW mifr = new MIB_IPFORWARDROW();
mifr.dwForwardDest = destIPAddress;
mifr.dwForwardMask = destMask;
mifr.dwForwardPolicy = Convert.ToUInt32(0);
mifr.dwForwardNextHop = nextHopIPAddress;
mifr.dwForwardIfIndex = ifIndex; //?
mifr.dwForwardType = Convert.ToUInt32(4);
mifr.dwForwardProto = Convert.ToUInt32(3);
mifr.dwForwardAge = Convert.ToUInt32(0);
mifr.dwForwardNextHopAS = Convert.ToUInt32(0);
mifr.dwForwardMetric1 = -1;
mifr.dwForwardMetric2 = -1;
mifr.dwForwardMetric3 = -1;
mifr.dwForwardMetric4 = -1;
mifr.dwForwardMetric5 = -1;
return CreateIpForwardEntry(ref mifr);}
=========END===========
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: jason |
last post by:
If one is attempting to insert data into tables at the same time what is the
best way to do this. I could do it the way below - but is there any reason I
should not do it this way or perhaps follow...
|
by: Jon Brunson |
last post by:
Is it possible to use a DataAdapter to fill a DataTable, change the
DataColumns of that DataTable (and maybe even it's name) and then commit
those changes to the database (in my case SQL Server...
|
by: Jothi |
last post by:
Hi All,
I implemented source to notify any changes in route table using
"NotifyRouteChange". ie., I am monitoring the route table, if any
change in PC. If any body(process/application) changes...
|
by: Paolo Pignatelli |
last post by:
I am trying to get an output/file like this (below) in an XML file
(MyXmlFile.xml) (which I will use for a slide show)
--
<gallery timer="3" order="sequential" fadetime="2" looping="yes"...
|
by: Alpha |
last post by:
I have a window application. On one of the form, there is a listbox and a
few combox. The lstSchItem has a dataview as a datasource. The comboxes are
bind to its selected value but through the...
|
by: Tommy Martin |
last post by:
If I add a web reference to my code it works fine. I need to know how to
dynamically set the url for the web reference. Sometimes URL's change and
would be nice to let the user enter a new URL in a...
|
by: michael ngong |
last post by:
pramod@rtimes.com (Pramod Ramachandran) wrote in message news:<6616e304.0306240122.4dd3ecd5@posting.google.com>...
Permit me start with the second question.
It would be easier to be more...
|
by: Darkside12 |
last post by:
Hi,
I'm trying to build a dynamic query by form. The idea is that a user can select a table in the database via a combo box and this will then change all of the text box labels on the form to...
|
by: Glenton |
last post by:
Hi All
Here is a very simple little class for finding a shortest route on a network, following Dijkstra's Algorithm:
#!/usr/bin/env python
#This is meant to solve a maze with Dijkstra's...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |