This results in the network being incorrectly configured with no DNS servers and an attempt to read the DNS server addresses throws NullReferenceException
, and Netduino is unable to resolve any host names, even though the DNS servers have been provided and correctly received in the DHCP Offer.
CW suggested that a workaround might be possible in a future firmware version.
static void WaitForValidIpAddress()
{
NetworkInterface[] networkInterfaces;
Dbg.Trace("Waiting for valid IP address", Source.NetworkServer);
do
{
Thread.Sleep(100);
networkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
} while (networkInterfaces[0].IPAddress == "0.0.0.0");
Dbg.Trace("Found " + networkInterfaces.Length + " network interfaces - details as follows...", Source.NetworkServer);
for (int i = 0; i < networkInterfaces.Length; i++)
{
var nic = networkInterfaces[i];
Dbg.Trace("Network interface: " + i, Source.NetworkServer);
Dbg.Trace(" Interface type: " + nic.NetworkInterfaceType, Source.NetworkServer);
Dbg.Trace(" IPv4 address: " + nic.IPAddress, Source.NetworkServer);
Dbg.Trace(" Default gateway: " + nic.GatewayAddress, Source.NetworkServer);
Dbg.Trace(" Subnet mask: " + nic.SubnetMask, Source.NetworkServer);
var dnsServers = nic.DnsAddresses;
Dbg.Trace(" DNS servers:", Source.NetworkServer);
foreach (var dnsServer in dnsServers)
{
Dbg.Trace(" " + dnsServer, Source.NetworkServer);
}
}
}