• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Detecting network disconnected
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: Detecting network disconnected
      • From: Joshua Graessley <email@hidden>
    • Setting AirPort radio to base station mode
      • From: "Peter Sichel" <email@hidden>
    • Re: Detecting network disconnected
      • From: "Peter Sichel" <email@hidden>
References: 
 >Detecting network disconnected (From: Larry Gerndt <email@hidden>)

  • Prev by Date: res_search result parsing
  • Next by Date: Re: Detecting network disconnected
  • Previous by thread: Detecting network disconnected
  • Next by thread: Re: Detecting network disconnected
  • Index(es):
    • Date
    • Thread