@ andre.m - I looked through your previous posts but couldn’t find the original issue you were having with DHCP and EMX.
I have a Cobra 1, and have had this issue with DHCP ever since I upgraded to 4.2.
if (ethernet.IsActivated)
{
ethernet.Close();
ethernet.Dispose();
ethernet = new EthernetBuiltIn();
}
ethernet.CableConnectivityChanged += new EthernetBuiltIn.CableConnectivityChangedEventHandler(Eth1_CableConnectivityChanged);
ethernet.NetworkAddressChanged += new NetworkInterfaceExtension.NetworkAddressChangedEventHandler(Eth1_NetworkAddressChanged);
ethernet.Open();
if (NetworkInterfaceExtension.AssignedNetworkInterface == null)
{
NetworkInterfaceExtension.AssignNetworkingStackTo(ethernet);
}
else if (NetworkInterfaceExtension.AssignedNetworkInterface.NetworkInterface.NetworkInterfaceType != NetworkInterfaceType.Ethernet)
{
NetworkInterfaceExtension.AssignNetworkingStackTo(ethernet);
}
if (ethernet.IsActivated && ethernet.IsOpen && ethernet.IsCableConnected)
{
NetworkInterface networkInterface = ethernet.NetworkInterface;
if (useDHCP)
{
Logger.WriteInfo("Main", "Setting dynamic IP address...");
if (networkInterface.IsDhcpEnabled == true)
{
networkInterface.RenewDhcpLease();
}
else
{
networkInterface.EnableDhcp();
}
int waitSecs = 10;
IPAddress ip = IPAddress.GetDefaultLocalAddress();
while (ip == IPAddress.Any && waitSecs > 0)
{
Thread.Sleep(1000);
waitSecs--;
ip = IPAddress.GetDefaultLocalAddress();
}
}
else
{
Logger.WriteInfo("Main", "Setting static IP address...");
networkInterface.EnableStaticIP(myIP, subnetMask, gatewayAddress);
networkInterface.EnableStaticDns(new[] { dnsAddresses });
}
// display results
if (IPAddress.GetDefaultLocalAddress() != IPAddress.Any)
{
Logger.WriteInfo("Main", "Network ready.");
Logger.WriteInfo("Main", " IP Address: " + IPAddress.GetDefaultLocalAddress());
Logger.WriteInfo("Main", " IP Address: " + networkInterface.IPAddress);
Logger.WriteInfo("Main", " Subnet Mask: " + networkInterface.SubnetMask);
Logger.WriteInfo("Main", " Default Gateway: " + networkInterface.GatewayAddress);
Logger.WriteInfo("Main", " # DNS Servers: " + networkInterface.DnsAddresses.Length);
foreach (string dnsAddress in networkInterface.DnsAddresses)
{
Logger.WriteInfo("Main", " DNS Server: " + dnsAddress);
}
return true;
}
else
{
Logger.WriteInfo("Main", "Network failed to initialize.");
Logger.WriteInfo("Main", " IP Address: " + IPAddress.GetDefaultLocalAddress());
}
}
else
{
Logger.WriteInfo("Main", "No network device found.");
}
Here is the output (ignore the dates and times, I didn’t initialize the system clock).
The first IP address is from IPAddress.GetDefaultLocalAddress().
I’m able to communicate with an external web site and a TCP server, so it is working, but…
Info : 06/01/2011 | 00:03:15.228 | Main | Initializing network…
Info : 06/01/2011 | 00:03:17.776 | Main | Setting dynamic IP address…
Info : 06/01/2011 | 00:03:19.489 | Main | Network ready.
Info : 06/01/2011 | 00:03:19.545 | Main | IP Address: 192.168.1.8
Info : 06/01/2011 | 00:03:19.573 | Main | IP Address: 0.0.0.0
Info : 06/01/2011 | 00:03:19.601 | Main | Subnet Mask: 0.0.0.0
Info : 06/01/2011 | 00:03:19.630 | Main | Default Gateway: 0.0.0.0
Info : 06/01/2011 | 00:03:19.654 | Main | # DNS Servers: 0