• 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 cable unplug/Network failure
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Detecting cable unplug/Network failure


  • Subject: Re: Detecting cable unplug/Network failure
  • From: Peter Sichel <email@hidden>
  • Date: Mon, 2 Mar 2009 13:18:13 -0500

On Mar 2, 2009, at 12:27 PM, David García wrote:

I'm quite new in Mac programming, and I've found some problems where I got stuck in the network. The matter is that, I need to know when there's a physical network error (most immediate cable being unplugged)....

I would like to get some advice in the best way to solve that.

It sounds like you want to be notified when an interface goes down or comes back up. In Mac OS X, there are a couple ways you might do this. One way is to open a PF_SYSTEM socket and request to be notified of the desired Kernel Events. You'll probably want a helper tool that can run with root privileges to open your kernel event socket and then use BSD descriptor passing to pass it back to your application.


        // assume we are executing as SUID root
        // get a raw kernel event socket
        newfd = socket(PF_SYSTEM, SOCK_RAW, SYSPROTO_EVENT);

        if ( SendFD(STDOUT_FILENO, newfd ) == 0 ) {
            perror( "failed to send fd" );
            return 1;
        }
        close(newfd);	// we're done with descriptor

Once you have one of these, you can get kernel event messages <sys/ kern_event.h> like KEV_DL_IF_DETACHING or KEV_DL_LINK_OFF as defined in <net/if.h>.

The other way which is probably easier is to use the System Configuration Framework and ask to be notified when certain keys change like the IPv4 address list. It turns out this is a pretty reasonable way to be notified when interfaces come and go since the callback will tell you what changed. Apple published some sample code on this a while ago which I vaguely recall was part of the MoreSCF collection.

<http://developer.apple.com/samplecode/Networking/index-date.html>

Kind Regards,

- Peter Sichel
  Sustainable Softworks
  http://www.sustworks.com

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Detecting cable unplug/Network failure
      • From: james woodyatt <email@hidden>
References: 
 >Detecting cable unplug/Network failure (From: David García <email@hidden>)

  • Prev by Date: Detecting cable unplug/Network failure
  • Next by Date: Re: Detecting cable unplug/Network failure
  • Previous by thread: Detecting cable unplug/Network failure
  • Next by thread: Re: Detecting cable unplug/Network failure
  • Index(es):
    • Date
    • Thread