public static bool IsReachableWithoutRequiringConnection (NetworkReachabilityFlags flags) { // Is it reachable with the current network configuration? bool isReachable = (flags & NetworkReachabilityFlags.Reachable) != 0; // Do we need a connection to reach it? bool noConnectionRequired = (flags & NetworkReachabilityFlags.ConnectionRequired) == 0; // Since the network stack will automatically try to get the WAN up, // probe that if ((flags & NetworkReachabilityFlags.IsWWAN) != 0) noConnectionRequired = true; if (isReachable && noConnectionRequired) { Application._networkstate = DataAccessLayer.NetworkState.ConnectedWifi; if (Application._user != null) Application._user.NetworkStatus = DataAccessLayer.NetworkState.ConnectedWifi; } else { Application._networkstate = DataAccessLayer.NetworkState.Disconnected; if (Application._user != null) Application._user.NetworkStatus = DataAccessLayer.NetworkState.Disconnected; } return isReachable && noConnectionRequired; }
static void OnChange(NetworkReachabilityFlags flags) { var h = ReachabilityChanged; if (h != null) { h(null, EventArgs.Empty); } }
static bool IsNetworkAvailable(out NetworkReachabilityFlags flags) { if (defaultRouteReachability == null) { defaultRouteReachability = new NetworkReachability(new IPAddress(0)); defaultRouteReachability.SetNotification(OnChange); defaultRouteReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault); } return defaultRouteReachability.TryGetFlags(out flags) && IsReachableWithoutRequiringConnection(flags); }
public static bool IsReachableWithoutRequiringConnection(NetworkReachabilityFlags flags) { bool isReachable = (flags & NetworkReachabilityFlags.Reachable) != 0; bool noConnectionRequired = (flags & NetworkReachabilityFlags.ConnectionRequired) == 0; if ((flags & NetworkReachabilityFlags.IsWWAN) != 0) noConnectionRequired = true; return isReachable && noConnectionRequired; }
void UpdateReachability (NetworkReachabilityFlags flags, NSImageView icon, NSTextField statusField) { if (flags.HasFlag (NetworkReachabilityFlags.Reachable) && !flags.HasFlag (NetworkReachabilityFlags.ConnectionRequired)) { icon.Image = NSImage.ImageNamed ("connected"); } else { icon.Image = NSImage.ImageNamed ("disconnected"); } statusField.StringValue = flags == 0 ? String.Empty : flags.ToString (); }
/// <summary> /// Checks if reachable without requireing a connection /// </summary> /// <param name="flags"></param> /// <returns></returns> public static bool IsReachableWithoutRequiringConnection (NetworkReachabilityFlags flags) { // Is it reachable with the current network configuration? bool isReachable = (flags & NetworkReachabilityFlags.Reachable) != 0; // Do we need a connection to reach it? bool noConnectionRequired = (flags & NetworkReachabilityFlags.ConnectionRequired) == 0; return isReachable && noConnectionRequired; }
public static bool IsAdHocWiFiNetworkAvailable (out NetworkReachabilityFlags flags) { if (adHocWiFiNetworkReachability == null) { adHocWiFiNetworkReachability = new NetworkReachability(new IPAddress(new byte [] { 169, 254, 0, 0 })); adHocWiFiNetworkReachability.SetNotification(OnChange); adHocWiFiNetworkReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault); } return adHocWiFiNetworkReachability.TryGetFlags(out flags) && IsReachableWithoutRequiringConnection(flags); }
static bool IsNetworkAvailable(out NetworkReachabilityFlags flags) { if (defaultRouteReachability == null) { var ipAddress = new IPAddress(0); defaultRouteReachability = new NetworkReachability(ipAddress.MapToIPv6()); defaultRouteReachability.SetNotification(OnChange); defaultRouteReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault); } return(defaultRouteReachability.TryGetFlags(out flags) && IsReachableWithoutRequiringConnection(flags)); }
static void OnChange (NetworkReachabilityFlags flags) { var h = ReachabilityChanged; if (h != null) h (null, EventArgs.Empty); if (pictureViewController != null) { NetworkStatus internetStatus = Reachability.InternetConnectionStatus(); pictureViewController.UpdateNetwork(internetStatus == NetworkStatus.ReachableViaWiFiNetwork || internetStatus == NetworkStatus.ReachableViaCarrierDataNetwork); } }
private NetworkStatus NetworkStatusHelper(NetworkReachabilityFlags flags) { if (!IsReachableWithoutRequiringConnection(flags)) _networkStatus = NetworkStatus.NotReachable; else if ((flags & NetworkReachabilityFlags.IsWWAN) != 0) _networkStatus = NetworkStatus.ReachableViaCarrierDataNetwork; else _networkStatus = NetworkStatus.ReachableViaWiFiNetwork; return _networkStatus; }
/// <summary> /// Returns network reachability flags and network availability. /// </summary> /// <param name="flags">The network reachability flags.</param> /// <returns>True if network is available, otherwise false.</returns> public static bool IsNetworkAvailable(out NetworkReachabilityFlags flags) { if (defaultRouteReachability == null) { defaultRouteReachability = new NetworkReachability(new IPAddress(0)); defaultRouteReachability.SetCallback(OnChange); defaultRouteReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault); } return(defaultRouteReachability.TryGetFlags(out flags) && IsReachableWithoutRequiringConnection(flags)); }
void CheckLoopbackFlags(NetworkReachabilityFlags flags, string number, bool has_address) { var noFlags = (NetworkReachabilityFlags)0; var otherFlags = (flags & ~(NetworkReachabilityFlags.Reachable | NetworkReachabilityFlags.IsLocalAddress | NetworkReachabilityFlags.IsDirect)); // Different versions of OSes report different flags. Trying to // figure out which OS versions have which flags set turned out to // be a never-ending game of whack-a-mole, so just don't assert // that any specific flags are set. Assert.AreEqual(noFlags, otherFlags, $"#{number} No other flags: {flags.ToString ()}"); }
static void Callback(IntPtr handle, NetworkReachabilityFlags flags, IntPtr info) { GCHandle gch = GCHandle.FromIntPtr(info); var r = gch.Target as NetworkReachability; if (r == null) { return; } r.notification(flags); }
public static bool IsAdHocWiFiNetworkAvailable(out NetworkReachabilityFlags flags) { if (adHocWiFiNetworkReachability == null) { adHocWiFiNetworkReachability = new NetworkReachability(new IPAddress(new byte[] { 169, 254, 0, 0 })); adHocWiFiNetworkReachability.SetNotification(OnChange); adHocWiFiNetworkReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault); } return(adHocWiFiNetworkReachability.TryGetFlags(out flags) && IsReachableWithoutRequiringConnection(flags)); }
/// <summary> /// /// </summary> /// <param name="flags"> /// A <see cref="NetworkReachabilityFlags"/> /// </param> /// <returns> /// A <see cref="System.Boolean"/> /// </returns> private static bool IsAdHocWiFiNetworkAvailable(out NetworkReachabilityFlags flags) { NetworkReachability adHocWiFiNetworkReachability = new NetworkReachability(new IPAddress(new byte [] { 169, 254, 0, 0 })); if (!adHocWiFiNetworkReachability.TryGetFlags(out flags)) { return(false); } return(IsReachable(flags) && IsNoConnectionRequired(flags)); // is reachable without requiring connection. }
private bool IsReachableWithoutRequiredConnection(NetworkReachabilityFlags flags) { bool isReachable = (flags & NetworkReachabilityFlags.Reachable) != 0; bool noConnectionRequired = (flags & NetworkReachabilityFlags.ConnectionRequired) == 0; if ((flags & NetworkReachabilityFlags.IsWWAN) != 0) { noConnectionRequired = true; } return(isReachable && noConnectionRequired); }
private static bool IsNetworkAvailable(out NetworkReachabilityFlags flags) { if (_defaultRouteReachability != null) { return(_defaultRouteReachability.TryGetFlags(out flags) && IsReachableWithoutRequiringConnection(flags)); } _defaultRouteReachability = new NetworkReachability(new IPAddress(0)); _defaultRouteReachability.SetNotification(OnChange); _defaultRouteReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault); return(_defaultRouteReachability.TryGetFlags(out flags) && IsReachableWithoutRequiringConnection(flags)); }
public static bool IsReachableWithoutRequiringConnection(NetworkReachabilityFlags flags) { // Is it reachable with the current network configuration? bool isReachable = (flags & NetworkReachabilityFlags.Reachable) != 0; // Do we need a connection to reach it? bool noConnectionRequired = (flags & NetworkReachabilityFlags.ConnectionRequired) == 0 || (flags & NetworkReachabilityFlags.IsWWAN) != 0; return(isReachable && noConnectionRequired); }
private void FlagsChanged(NetworkReachabilityFlags flags) { if (!ReachabilityKnown || flags != ReachabilityFlags) { ReachabilityFlags = flags; ReachabilityKnown = true; WriteLog.To.Sync.I(Tag, $"{this}: flags <-- {flags}"); var status = flags.HasFlag(NetworkReachabilityFlags.Reachable) && !flags.HasFlag(NetworkReachabilityFlags.InterventionRequired) ? NetworkReachabilityStatus.Reachable : NetworkReachabilityStatus.Unreachable; StatusChanged?.Invoke(this, new NetworkReachabilityChangeEventArgs(status)); } }
// // Returns true if it is possible to reach the AdHoc WiFi network // and optionally provides extra network reachability flags as the // out parameter // public static bool IsAdHocWiFiNetworkAvailable(out NetworkReachabilityFlags flags) { if (_adHocWiFiNetworkReachability == null) { _adHocWiFiNetworkReachability = new NetworkReachability (new IPAddress (new byte[] { 169, 254, 0, 0 })); _adHocWiFiNetworkReachability.SetCallback (OnChange); _adHocWiFiNetworkReachability.Schedule (CFRunLoop.Current, CFRunLoop.ModeDefault); } if (!_adHocWiFiNetworkReachability.TryGetFlags (out flags)) return false; return IsReachableWithoutRequiringConnection (flags); }
void UpdateReachability(NetworkReachabilityFlags flags, NSImageView icon, NSTextField statusField) { if (flags.HasFlag(NetworkReachabilityFlags.Reachable) && !flags.HasFlag(NetworkReachabilityFlags.ConnectionRequired)) { icon.Image = NSImage.ImageNamed("connected"); } else { icon.Image = NSImage.ImageNamed("disconnected"); } statusField.StringValue = flags == 0 ? String.Empty : flags.ToString(); }
public static bool IsNetworkAvailable(out bool connectionRequired, out bool onlyWWAN) { bool flagsAvailable; NetworkReachabilityFlags networkReachabilityFlags = (NetworkReachabilityFlags)0; using (var networkReachability = new NetworkReachability(HostName)) { flagsAvailable = networkReachability.TryGetFlags(out networkReachabilityFlags); } connectionRequired = 0 != (networkReachabilityFlags & NetworkReachabilityFlags.ConnectionRequired); onlyWWAN = 0 != (networkReachabilityFlags & NetworkReachabilityFlags.IsWWAN); return(flagsAvailable && 0 != (networkReachabilityFlags & NetworkReachabilityFlags.Reachable)); }
static bool IsNetworkAvailable(out NetworkReachabilityFlags flags) { if (defaultRouteReachability == null) { defaultRouteReachability = new NetworkReachability(IPAddress.None); defaultRouteReachability.SetNotification(OnChange); defaultRouteReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault); } bool a = defaultRouteReachability.TryGetFlags(out flags); bool b = IsReachableWithoutRequiringConnection(flags); return(a && b); }
private void HandleReachabilityChanged(NetworkReachabilityFlags flags) { Console.WriteLine (flags); var requiresConnection = (flags & NetworkReachabilityFlags.ConnectionRequired) > 0; // It's reachable if Reachable flag is set and no connection is required. reachable = !requiresConnection && (flags & NetworkReachabilityFlags.Reachable) > 0; // Trigger callback. if (this.connectivityChanged != null) { this.connectivityChanged (reachable); } }
public static bool IsReachableWithoutRequiringConnection(NetworkReachabilityFlags flags) { // Is it reachable with the current network configuration? bool isReachable = (flags & NetworkReachabilityFlags.Reachable) != 0; // Do we need a connection to reach it? bool noConnectionRequired = (flags & NetworkReachabilityFlags.ConnectionRequired) == 0 || (flags & NetworkReachabilityFlags.IsWWAN) != 0; // Since the network stack will automatically try to get the WAN up, // probe that return(isReachable && noConnectionRequired); }
static bool IsNetworkAvailable(out NetworkReachabilityFlags flags) { if (defaultRouteReachability == null) { defaultRouteReachability = new NetworkReachability(new IPAddress(0)); defaultRouteReachability.SetNotification(OnChange); defaultRouteReachability.Schedule(CFRunLoop.Main, CFRunLoop.ModeDefault); } if (!defaultRouteReachability.TryGetFlags(out flags)) { return(false); } return(IsReachableWithoutRequiringConnection(flags)); }
public static bool IsReachableWithoutRequiringConnection(NetworkReachabilityFlags flags) { // Is it reachable with the current network configuration? bool isReachable = (flags & NetworkReachabilityFlags.Reachable) != 0; // Do we need a connection to reach it? bool noConnectionRequired = (flags & NetworkReachabilityFlags.ConnectionRequired) == 0; // Since the network stack will automatically try to get the WAN up, probe that if ((flags & NetworkReachabilityFlags.IsWWAN) != 0) noConnectionRequired = true; return isReachable && noConnectionRequired; }
private void ReachablilityCallback(NetworkReachabilityFlags flags) { var connected = flags.HasFlag(NetworkReachabilityFlags.Reachable); if (connected) { GetNetworkSetup(flags); } else { ConnectionState = NetworkConnectionStates.None; } OnConnectivityChanged?.Invoke(this, new EventArgs()); }
private void HandleReachabilityChanged(NetworkReachabilityFlags flags) { Console.WriteLine(flags); var requiresConnection = (flags & NetworkReachabilityFlags.ConnectionRequired) > 0; // It's reachable if Reachable flag is set and no connection is required. reachable = !requiresConnection && (flags & NetworkReachabilityFlags.Reachable) > 0; // Trigger callback. if (this.connectivityChanged != null) { this.connectivityChanged(reachable); } }
/// <summary> /// /// </summary> /// <param name="flags"> /// A <see cref="NetworkReachabilityFlags"/> /// </param> /// <returns> /// A <see cref="System.Boolean"/> /// </returns> private static bool IsNoConnectionRequired(NetworkReachabilityFlags flags) { // Do we need a connection to reach it? bool noConnectionRequired = (flags & NetworkReachabilityFlags.ConnectionRequired) == 0; // Since the network stack will automatically try to get the WAN up, // probe that if ((flags & NetworkReachabilityFlags.IsWWAN) != 0) { noConnectionRequired = true; } return(noConnectionRequired); }
internal static bool IsNetworkAvailable(out NetworkReachabilityFlags flags) { var ip = new IPAddress(0); using (var defaultRouteReachability = new NetworkReachability(ip)) { if (!defaultRouteReachability.TryGetFlags(out flags)) { return(false); } return(IsReachableWithoutRequiringConnection(flags)); } }
private static bool IsNetworkAvailable(out NetworkReachabilityFlags flags) { if (defaultRouteReachability == null) { defaultRouteReachability = new MonoTouch.SystemConfiguration.NetworkReachability(new IPAddress(0)); defaultRouteReachability.SetCallback(OnChange); defaultRouteReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault); } if (!defaultRouteReachability.TryGetFlags(out flags)) { return(false); } return(IsReachableWithoutRequiringConnection(flags)); }
public bool isNetworkAvailable(out NetworkReachabilityFlags flags) { if (defaultReachability == null) { defaultReachability = new NetworkReachability(new System.Net.IPAddress(0)); defaultReachability.SetNotification(OnChange); defaultReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault); } if (!defaultReachability.TryGetFlags(out flags)) { return(false); } return(IsReachableWithoutRequiredConnection(flags)); }
private bool IsNetworkAvailable(out NetworkReachabilityFlags flags) { if (defaultRouteReachability == null) { defaultRouteReachability = new NetworkReachability("www.163.com"); defaultRouteReachability.SetNotification(OnChange); defaultRouteReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault); } if (!defaultRouteReachability.TryGetFlags(out flags)) { return(false); } return(IsReachableWithoutRequiringConnection(flags)); }
private static bool IsNetworkAvaialable(out NetworkReachabilityFlags flags) { if (defaultRouteReachability == null) { defaultRouteReachability = new NetworkReachability(new IPAddress(0)); #warning Need to look at SetNotification instead - ios6 change defaultRouteReachability.SetNotification(OnChange); defaultRouteReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault); } if (defaultRouteReachability.TryGetFlags(out flags)) { return(false); } return(IsReachableWithoutRequiringConnection(flags)); }
public static bool IsAdHocWiFiNetworkAvailable(out NetworkReachabilityFlags flags) { if (adHocWiFiNetworkReachability == null) { adHocWiFiNetworkReachability = new NetworkReachability(new IPAddress(new byte[] {169, 254, 0, 0})); #warning Need to look at SetNotification instead - ios6 change adHocWiFiNetworkReachability.SetNotification(OnChange); adHocWiFiNetworkReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault); } if (!adHocWiFiNetworkReachability.TryGetFlags(out flags)) return false; return IsReachableWithoutRequiringConnection(flags); }
/// <summary> /// Utility method that gets the flags as a string /// </summary> /// <returns> /// The flags as string /// </returns> /// <param name='flags'> /// Flags /// </param> protected string GetFlagsAsString(NetworkReachabilityFlags flags) { return(string.Concat( !HasWWAN ? "X" : flags.HasFlag(NetworkReachabilityFlags.IsWWAN) ? "W" : "-", flags.HasFlag(NetworkReachabilityFlags.Reachable) ? "R" : "-", " ", flags.HasFlag(NetworkReachabilityFlags.ConnectionRequired) ? "c" : "-", flags.HasFlag(NetworkReachabilityFlags.TransientConnection) ? "t" : "-", flags.HasFlag(NetworkReachabilityFlags.InterventionRequired) ? "i" : "-", flags.HasFlag(NetworkReachabilityFlags.ConnectionOnTraffic) ? "C" : "-", flags.HasFlag(NetworkReachabilityFlags.ConnectionOnDemand) ? "D" : "-", flags.HasFlag(NetworkReachabilityFlags.IsLocalAddress) ? "l" : "-", flags.HasFlag(NetworkReachabilityFlags.IsDirect) ? "d" : "-" )); }
private void ReachablilityCallback(NetworkReachabilityFlags flags) { System.Diagnostics.Debug.WriteLine($"*** {GetType().Name}.ReachablilityCallback - Callback!!"); var connected = flags.HasFlag(NetworkReachabilityFlags.Reachable); if (connected) { GetNetworkSetup(flags); } else { ConnectionState = NetworkConnectionStates.None; } OnConnectivityChanged?.Invoke(this, new EventArgs()); }
bool IsReachableWithoutRequiringConnection(NetworkReachabilityFlags flags) { bool isReachable = (flags & NetworkReachabilityFlags.Reachable) != 0; // Do we need a connection to reach it? bool noConnectionRequired = (flags & NetworkReachabilityFlags.ConnectionRequired) == 0; // Since the network stack will automatically try to get the WAN up, // probe that if ((flags & NetworkReachabilityFlags.IsWWAN) != 0) { noConnectionRequired = true; } return(isReachable && noConnectionRequired); }
// private bool IsNetworkAvailable(out NetworkReachabilityFlags flags) // { // if (defaultRouteReachability == null) // { // defaultRouteReachability = new NetworkReachability(new IPAddress(0)); // defaultRouteReachability.SetCallback(OnChange); // defaultRouteReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault); // } // if (!defaultRouteReachability.TryGetFlags(out flags)) // return false; // return IsReachableWithoutRequiringConnection(flags); // } private bool IsNetworkAvailable(out NetworkReachabilityFlags flags) { if (defaultRouteReachability == null) { defaultRouteReachability = new NetworkReachability(new IPAddress(0)); //SetCallback is depreciated //ORIG: defaultRouteReachability.SetCallback(OnChange); defaultRouteReachability.SetNotification(OnChange); defaultRouteReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault); } if (!defaultRouteReachability.TryGetFlags(out flags)) { return(false); } return(IsReachableWithoutRequiringConnection(flags)); }
private bool IsAdHocWiFiNetworkAvailable(out NetworkReachabilityFlags flags) { if (adHocWiFiNetworkReachability == null) { adHocWiFiNetworkReachability = new NetworkReachability(new IPAddress(new byte[] { 169, 254, 0, 0 })); adHocWiFiNetworkReachability.SetCallback(OnChange); adHocWiFiNetworkReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault); } if (!adHocWiFiNetworkReachability.TryGetFlags(out flags)) { return(false); } return(IsReachableWithoutRequiringConnection(flags)); }
public static bool IsAdHocWiFiNetworkAvailable(out NetworkReachabilityFlags flags) { if (adHocWiFiNetworkReachability == null) { adHocWiFiNetworkReachability = new NetworkReachability(new IPAddress(new byte[] { 169, 254, 0, 0 })); #warning Need to look at SetNotification instead - ios6 change adHocWiFiNetworkReachability.SetCallback(OnChange); adHocWiFiNetworkReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault); } if (!adHocWiFiNetworkReachability.TryGetFlags(out flags)) { return(false); } return(IsReachableWithoutRequiringConnection(flags)); }
void HandleReachabilityChanged(NetworkReachabilityFlags flags) { Console.WriteLine($"Reachability Changed Event with {flags}"); if (flags.HasFlag(NetworkReachabilityFlags.Reachable) && !IsConnected) { Task.Factory.StartNew(async() => await Connect()); } else if (!flags.HasFlag(NetworkReachabilityFlags.Reachable) && IsConnected) { Disconnect(); } else { ConnectionChanged?.Invoke(this, new ConnectionStatusEventArgs(IsConnected)); } }
/// <summary> /// /// </summary> /// <param name="flags"> /// A <see cref="NetworkReachabilityFlags"/> /// </param> /// <returns> /// A <see cref="System.Boolean"/> /// </returns> private static bool IsAdHocWiFiNetworkAvailable(out NetworkReachabilityFlags flags) { NetworkReachability adHocWiFiNetworkReachability = new NetworkReachability (new IPAddress (new byte [] {169,254,0,0})); if (!adHocWiFiNetworkReachability.TryGetFlags (out flags)) return false; return IsReachable (flags) && IsNoConnectionRequired(flags); // is reachable without requiring connection. }
// // Invoked on the main loop when reachability changes // void ReachabilityChanged(NetworkReachabilityFlags flags) { }
/// <summary> /// /// </summary> /// <param name="flags"> /// A <see cref="NetworkReachabilityFlags"/> /// </param> /// <returns> /// A <see cref="System.Boolean"/> /// </returns> private static bool IsNoConnectionRequired(NetworkReachabilityFlags flags) { // Do we need a connection to reach it? bool noConnectionRequired = (flags & NetworkReachabilityFlags.ConnectionRequired) == 0; // Since the network stack will automatically try to get the WAN up, // probe that if ((flags & NetworkReachabilityFlags.IsWWAN) != 0) noConnectionRequired = true; return noConnectionRequired; }
private static bool IsNetworkAvaialable(out NetworkReachabilityFlags flags) { if (defaultRouteReachability == null) { defaultRouteReachability = new NetworkReachability(new IPAddress(0)); #warning Need to look at SetNotification instead - ios6 change defaultRouteReachability.SetNotification(OnChange); defaultRouteReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault); } if (defaultRouteReachability.TryGetFlags(out flags)) return false; return IsReachableWithoutRequiringConnection(flags); }
/// <summary> /// /// </summary> /// <param name="flags"> /// A <see cref="NetworkReachabilityFlags"/> /// </param> /// <returns> /// A <see cref="System.Boolean"/> /// </returns> private static bool IsReachable(NetworkReachabilityFlags flags) { // Is it reachable with the current network configuration? bool isReachable = (flags & NetworkReachabilityFlags.Reachable) != 0; return isReachable; }
public StatusCode GetFlags (out NetworkReachabilityFlags flags) { return SCNetworkReachabilityGetFlags (handle, out flags) == 0 ? StatusCodeError.SCError () : StatusCode.OK; }
static extern bool SCNetworkReachabilityGetFlags (IntPtr reachability, out NetworkReachabilityFlags flags);
/// <summary> /// Checks if network is reachable without requiring connection. /// </summary> /// <param name="flags"> /// The reachability flags. /// </param> /// <returns> /// True if reachable, false if connection is required. /// </returns> public static bool IsReachableWithoutRequiringConnection(NetworkReachabilityFlags flags) { return (flags & NetworkReachabilityFlags.Reachable) != 0 && (((flags & NetworkReachabilityFlags.IsWWAN) != 0) || (flags & NetworkReachabilityFlags.ConnectionRequired) == 0); }
/// <summary> /// /// </summary> /// <param name="flags"> /// A <see cref="NetworkReachabilityFlags"/> /// </param> /// <returns> /// A <see cref="System.Boolean"/> /// </returns> private static bool IsNetworkAvaialable(out NetworkReachabilityFlags flags) { NetworkReachability defaultRouteReachability = new NetworkReachability (new IPAddress (0)); if (defaultRouteReachability.TryGetFlags (out flags)) return false; return IsReachable (flags) && IsNoConnectionRequired(flags); // is reachable without requiring connection. }
static void Callback (IntPtr handle, NetworkReachabilityFlags flags, IntPtr info) { GCHandle gch = GCHandle.FromIntPtr (info); var r = gch.Target as NetworkReachability; if (r == null) return; r.notification (flags); }
public bool TryGetFlags (out NetworkReachabilityFlags flags) { return GetFlags (out flags) == StatusCode.OK; }
static void HandleCallback (IntPtr reachability, NetworkReachabilityFlags flags, IntPtr info) { if (info == IntPtr.Zero) return; var instance = GCHandle.FromIntPtr (info).Target as MacNetworkChange; if (instance == null || instance.flags == flags) return; instance.flags = flags; var addressChanged = instance.networkAddressChanged; if (addressChanged != null) addressChanged (null, EventArgs.Empty); var availabilityChanged = instance.networkAvailabilityChanged; if (availabilityChanged != null) availabilityChanged (null, new NetworkAvailabilityEventArgs (instance.IsAvailable)); }
public void Dispose () { lock (this) { if (handle == IntPtr.Zero) return; if (scheduledWithRunLoop) SCNetworkReachabilityUnscheduleFromRunLoop (handle, CFRunLoopGetMain (), runLoopMode); CFRelease (handle); handle = IntPtr.Zero; callback = null; flags = NetworkReachabilityFlags.None; scheduledWithRunLoop = false; } }
static void ReachabilityChanged(NetworkReachabilityFlags flags) { FAARegistry.flags = flags; haveFlags = true; }
static bool IsNetworkAvailable(out NetworkReachabilityFlags flags) { if (defaultRouteReachability == null) { var data = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 0, 0, 0, 0 }; var ip = new IPAddress(data, 0); defaultRouteReachability = new NetworkReachability(ip); defaultRouteReachability.SetNotification(OnChange); defaultRouteReachability.Schedule(CFRunLoop.Main, CFRunLoop.ModeDefault); } if (!defaultRouteReachability.TryGetFlags(out flags)) return false; return IsReachableWithoutRequiringConnection(flags); }
// // Invoked on the main loop when reachability changes // void ReachabilityChanged(NetworkReachabilityFlags flags) { UpdateStatus (); }
/// <summary> /// Checks ad hoc wifi is available /// </summary> /// <param name="flags"></param> /// <returns></returns> public static bool IsAdHocWiFiNetworkAvailable(out NetworkReachabilityFlags flags) { if (adHocWiFiNetworkReachability == null) { //var ip = IPAddress.Parse("::ffff:169.254.0.0"); var data = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 169, 254, 0, 0 }; var ip = new IPAddress(data, 0); adHocWiFiNetworkReachability = new NetworkReachability(ip); adHocWiFiNetworkReachability.SetNotification(OnChange); adHocWiFiNetworkReachability.Schedule(CFRunLoop.Main, CFRunLoop.ModeDefault); } if (!adHocWiFiNetworkReachability.TryGetFlags(out flags)) return false; return IsReachableWithoutRequiringConnection(flags); }