Re: Detecting network disconnected
Re: Detecting network disconnected
- Subject: Re: Detecting network disconnected
- From: "Justin C. Walker" <email@hidden>
- Date: Thu, 29 May 2003 10:49:15 -0700
On Thursday, May 29, 2003, at 10:04 AM, Larry Gerndt wrote:
When using BSD sockets, what's the right way of detecting that the
user has
disconnected his Mac from the network (i.e. pulled the plug)?
The correct mechanism is SystemConfiguration Framework. You can look
at the scutil code to see examples of how to detect that a network
interface has gone inactive.
A lower-layer mechanism is available, but you would have to do a lot of
filtering and processing to be sure that the event you caught is the
one you want. The SystemConfiguration framework source shows how to do
that.
What I'm seeing is that even when the plug is pulled, the socket
happily
continues allowing writes and when I plug the cable back in, those
writes
succeed. While that is, I'm sure, intended behavior, and is very
useful, it
prevents me from being able to detect that I'm not actually connected.
You are correct. This is exactly the intended behavior. TCP, in
particular, is designed to ride out the destruction of a lot of
infrastructure and keep working. The IP world revolves around routers,
not interfaces, so the disappearance of one interface does not mean
that a path to the destination is not available; and even if one is not
immediately available, the assumption is that one will be along soon.
Determining that "you are connected" is a much higher-layer function
and is not part of IP's functionality. That's the main reason you are
unable to detect this with your approach.
Recent systems will tend to have more than one networking device
available, so "being connected" is a function of the state of all those
devices.
I tried setting a 10-second timeout on the socket writes, but of
course that
timeout never happens because the writes succeed even when the cable is
disconnected.
Yup.
Hope this helps.
Regards,
Justin
--
/~\ The ASCII Justin C. Walker, Curmudgeon-at-Large
\ / Ribbon Campaign
X Help cure HTML Email
/ \
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.