Setting IP address of an ad-hoc wireless connection

D

David Hearn

I've successfully used OpenNETCF to create an ad-hoc wireless connection
on a WM5 PDA (with the intention of talking to another PDA). The IP
address is assigned automatically by APIPA (Automatic Private IP
Addressing) and in the range 169.254.x.y with subnet mask 255.255.0.0.

I need to be able to change the IP addresses assigned. I cannot have
any external devices (other than 2 PDAs) and everything needs to be
controlled programmatically.

Is there any way to manually override/set the IP address using the
Compact Framework or OpenNETCF, or even native/PInvoke calls?

Thanks

David
 
G

Guest

The Smart Device Famrework has a "CurrentIPAddress" field for the Adapter
class. Simply set it (and probably set DhcpEnabled to false)

--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Managed Code in an Embedded World
www.OpenNETCF.com
 
P

Paul G. Tobey [eMVP]

I think that just setting the wireless adapter to *not* get the IP address
via DHCP and setting a static IP that you want is probably the right way to
fix the problem permanently. You're going to get weird things going on if,
every time you start up, you change the IP address of the device. If you
look through the registry under HKEY_LOCAL_MACHINE/Comm, you'll find a key
of the form <AdapterName><Number> where the AdapterName is the name
associated with the wireless network adapter. Under that key, you'll find a
subkey, Parms, and under that, TcpIp. In the TcpIp key branch, you'll find
things like EnableDHCP, a value that you can set to 0 to turn off DHCP for
getting addresses, and IpAddress, SubnetMask, and DefaultGateway, which are
multi-string values which you can set to the static IP, subnet, and gateway
that you want the adapter to use for itself.

Paul T.
 
D

David Hearn

The Smart Device Famrework has a "CurrentIPAddress" field for the Adapter
class. Simply set it (and probably set DhcpEnabled to false)

For some reason, after reading the online docs I thought it was a
read-only property - but looking again at the docs it clearly shots both
get and set. Similarly, I thought DhcpEnabled was read only - although
probably as I read the description as "Indicator of whether DHCP (for IP
address assignment from a server), is enabled for the adapter."

I should read the docs more closely.

Now the problem.

I tried this and it generates an exception. Specifically, I tried:

textBoxLog.Text += String.Format("IP: {0}\r\n",
wirelessNetworkAdaptor.CurrentIpAddress);

string currentIPAddress = wirelessNetworkAdaptor.CurrentIpAddress;

wirelessNetworkAdaptor.DhcpEnabled = false;
wirelessNetworkAdaptor.CurrentIpAddress = currentIPAddress;

textBoxLog.Text += String.Format("IP: {0}\r\n",
wirelessNetworkAdaptor.CurrentIpAddress);


And I get "InvalidCastException at OpenNETCF.Net.Adapter.set_DhcpEnabled()"

If I comment out the .DhcpEnabled = false line, I then get:

"InvalidCastException at OpenNETCF.Net.Adapter.set_CurrentIpAddress()"

I originally tried setting the IP manually via a hard coded string, so
tried getting the IP address and then setting it to the same IP address
to ensure the format was the same, but it made no difference.

I see that other people, using both 1.4 and 2.1 have experienced this
too:
http://www.opennetcf.org/forums/post.asp?method=TopicQuote&TOPIC_ID=8683&FORUM_ID=17

Any advice?

Thanks

David
 
D

David Hearn

Yes, it was a reported bug:
http://bugzilla.opennetcf.com/show_bug.cgi?id=107

If you've purchased the SDF, send an email to support[at]OpenNETCF.com to
get a patch, otherwise you'll have to wait for our next release.

I'm using the community edition, so I guess I'll have to wait.

With the Extensions for VS product, it comes with the sources. Would
this mean that we could, in theory, fix it ourselves? If so, it might
be a cheaper option than doing with the maintenance agreement option.

Thanks

D
 
G

Guest

With the Extensions for VS product, it comes with the sources. Would this
mean that we could, in theory, fix it ourselves? If so, it might be a
cheaper option than doing with the maintenance agreement option.

Not just "in theory". We can send you the fixed code and you can rebuild it
yourself, we just aren't at a state where we can recompile and release
another version the entire community edition for this fix.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Managed Code in an Embedded World
www.OpenNETCF.com
 
P

Paul G. Tobey [eMVP]

David,

You can manually make this change, if you want to and, when the fix comes
out, easily drop back to it. The IP address is stored in the registry at
the location I mentioned in my other message. Make the changes you need to
EnableDHCP and IPAddress, SubnetMask, and DefaultGateway, and then do an
Adapter.RebindAdapter() and the new information will be picked up from the
registry.

Paul T.


David Hearn said:
Yes, it was a reported bug:
http://bugzilla.opennetcf.com/show_bug.cgi?id=107

If you've purchased the SDF, send an email to support[at]OpenNETCF.com to
get a patch, otherwise you'll have to wait for our next release.

I'm using the community edition, so I guess I'll have to wait.

With the Extensions for VS product, it comes with the sources. Would this
mean that we could, in theory, fix it ourselves? If so, it might be a
cheaper option than doing with the maintenance agreement option.

Thanks

D
 
D

David Hearn

Paul said:
David,

You can manually make this change, if you want to and, when the fix comes
out, easily drop back to it. The IP address is stored in the registry at
the location I mentioned in my other message. Make the changes you need to
EnableDHCP and IPAddress, SubnetMask, and DefaultGateway, and then do an
Adapter.RebindAdapter() and the new information will be picked up from the
registry.

Paul T.

Excellent - I'll give that a go.

Thanks

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top