local IP address becomes 0.0.0.0

  • Thread starter Thread starter Gianco
  • Start date Start date
G

Gianco

Hello

I written a small application that waits for UDP messages becoming
from the network and it runs in background. The problem is that when
the connector cable is not plugged in the ip address (it's a static
address) becomes 0.0.0.0, this cause problems with the opened sockets.
Is it possible to avoid this problems?

Thanks in advance
Gianco
 
Gianco said:
Hello

I written a small application that waits for UDP messages becoming
from the network and it runs in background. The problem is that when
the connector cable is not plugged in the ip address (it's a static
address) becomes 0.0.0.0, this cause problems with the opened sockets.
Is it possible to avoid this problems?

Thanks in advance
Gianco

Use NotifyAddrChange to get notified the instant the IP address changes.
Basically I rebind all sockets then.

As to me, listening for address changes is a good idea in general,
because it can happen in the real world for a lot reasons (disconnected
cable at the device, IP configuration changes, coming and going of DHCP
availability, ... )

Koen.
 
Wait a minute. You've assigned it a static address and the *static* address
changes to 0.0.0.0 when the cable is unplugged? That's not normal behavior.
What network adapter? What driver? It's normal for the IP to appear as
0.0.0.0 if the device is configured for DHCP and the cable is disconnected,
once the DHCP lease runs out (and maybe it happens earlier than that; I'm
not sure).

Paul T.
 
Thanks for your replies Koen and Paul

Koen do you think I should generate a thread to check when the ip
address is changed and rebind the sockets each time this happens?

Paul, the ip address is static and it changes to 0.0.0.0 when the cable
is unplugged! The driver is the NDS0 (I guess), I use this file and
DeviceIoControl to rebind the adapter

Gianco
 
--- (e-mail address removed) posted on 29-Jan-2005 12:33 (+2
GMT) ---
Thanks for your replies Koen and Paul

Koen do you think I should generate a thread to check when the ip
address is changed and rebind the sockets each time this happens?

Paul, the ip address is static and it changes to 0.0.0.0 when the cable
is unplugged! The driver is the NDS0 (I guess), I use this file and
DeviceIoControl to rebind the adapter

Gianco


Gianco, at first glance it seems the easiest to use NotifyAddrChange as
a blocking call; in that case you'll have to dedicate a seperate thread
for this task. Once the call unblocks, you'll have to decide how to
interact with the rest of your logic to escalate the address change. I
guess you would use an other event for this.

Avoiding this plumbing, I prefer to use NotifyAddrChange in an
asynchronous mode. In that case an event will immediately get signaled
when the address changes; I can then check for this event in whatever
thread, way and timeframe I'd favor.

However, I have not done this last thing from managed code. It implies
some additional complexity as I'm not sure you can access
NotifyAddrChange apart from P/Invoke'ing it.

Koen.
 
I think that Koen has given you a good list of issues to look at. I've
never seen the static IP change in that way, so I suspect that it is, in
fact, not actually changing. If you want to investigate that further, tell
us how you're deciding that the address has changed in this way...

Paul T.
 
Paul said:
I think that Koen has given you a good list of issues to look at. I've
never seen the static IP change in that way, so I suspect that it is, in
fact, not actually changing. If you want to investigate that further, tell
us how you're deciding that the address has changed in this way...

Paul T.

Paul, I spent a minute to figure this out on an Advantech board with
Windows CE 4.2.

I unplugged the ethernet cable from the device's socket. The IP address
was then verified locally, using the network adapter tray app, and
additionally with ipconfig.

Apparently the statically configured IP address *does* change after a
few seconds. To 0.0.0.0 when the cable is disconnected and back to the
configured IP address when it gets reconnected.

Perhaps this does not occur with your set up. Anyway, I wasn't really
aware of this behaviour of *my* set up. Good to know.

Koen.
 
Hmmm. Must be happening when the adapter is being unbound. It's just the
active address, not the stored address that's changing, too. I'll add that
to my list of interesting things...

Paul T.
 
Koen
I'm using an Advantech board too, is this the reason that cause the
problem?

Paul
The ip address changes effectively because if I disconnect the cable
during a communication my system crashes displaying a native error
Gianco
 
I doubt it's really related to the Advantech board; it's perhaps related
to the network driver or adapter configuration.

But honestly, I think this behaviour is okay. Are you really caught off
your guard by the error? What do you mean by 'native error'? Like the
underlying socket is closed? You should really handle that gracefully
because that can happen for several reasons.

Koen.
 
I agree. For all I know, my device is the exception, not the rule and you
should expect the IP to switch to all zeroes when the cable is unplugged.
Your code should be prepared for the network connection to go away
unexpectedly. What, exactly, are you in the process of doing when the
exception is thrown? If you can catch the exception, you should, and handle
it as a network disconnect.

Paul T.
 
Back
Top