• 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: SCNetworkReachability and unknown hostnames
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: SCNetworkReachability and unknown hostnames


  • Subject: Re: SCNetworkReachability and unknown hostnames
  • From: Allan Nathanson <email@hidden>
  • Date: Sat, 17 Aug 2013 19:16:07 -0400


On Aug 17, 2013, at 3:30 PM, Jens Alfke <email@hidden> wrote:

tl;dr: Using SCNetworkReachabilityCreateWithName, how do I tell the difference between “the device is offline” and “you are online but the hostname couldn’t be found”?

I’ve been using SCNetworkReachabilityCreateWithName() for a while but just ran into an issue with it. If it’s given a hostname that fails to resolve — say “fdsf.fdsd” or “moseyard.com” — it reports that the host is unreachable by returning an empty set of flags (0).

Which is true as far as it goes, but I can’t tell it apart from a genuinely-offline state. If the device is offline I want my networking code to wait idly until it’s notified that the host is reachable; but if the user’s entered an incorrect hostname I should return an error right away. Currently my code can’t tell the difference, so if the user makes a typo in a URL’s hostname she’ll probably never get notified of the mistake, just wait forever while nothing happens.

(I’m aware that there are cases where a hostname-not-found error is genuinely transient and it might be appropriate for the app to wait; e.g. if it’s an intranet host that’s only visible when logged into a VPN. But that’s a less common situation.)

It would be nice if SCNetworkReachability could indicate this state somehow, like with a flag indicating “DNS was reachable but your hostname couldn’t be found”, which I can choose to treat as an error. I’ve looked through the header but can’t find anything like this; am I missing something or should I file a Radar?

You are correct that the SCNetworkReachabilityFlags provide no way to differentiate "no network" from "no such host".  If you "need" to know, the best suggestion I could offer would be to use a separate call to SCNetworkReachabilityCreateWithAddress() passing a "struct sockaddr_in *" with an address of INADDR_ANY.  This will return a result driven by the presence of a default route.  Then, you're logic would be something like "if there's no reachability for the specified name and there is no network reachability off of the local host then ...".

We've been hesitant to add more context to the returned SCNetworkReachabilityFlags but filing an enhancement request through Radar can't hurt.

- Allan


 _______________________________________________
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

References: 
 >SCNetworkReachability and unknown hostnames (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: SCNetworkReachability and unknown hostnames
  • Next by Date: bind privileged port
  • Previous by thread: Re: SCNetworkReachability and unknown hostnames
  • Next by thread: bind privileged port
  • Index(es):
    • Date
    • Thread