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;
        }
Ejemplo n.º 2
0
		static void OnChange(NetworkReachabilityFlags flags)
		{
			var h = ReachabilityChanged;
			if (h != null)
			{
				h(null, EventArgs.Empty);
			}
		}
Ejemplo n.º 3
0
		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);
		}
Ejemplo n.º 4
0
    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 ();
		}
Ejemplo n.º 6
0
		/// <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;
		}
Ejemplo n.º 7
0
		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);
		}
Ejemplo n.º 8
0
 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);
     }
 }
Ejemplo n.º 10
0
        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 ()}");
        }
Ejemplo n.º 13
0
        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);
        }
Ejemplo n.º 14
0
        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));
        }
Ejemplo n.º 15
0
        /// <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.
        }
Ejemplo n.º 16
0
        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);
        }
Ejemplo n.º 17
0
 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));
 }
Ejemplo n.º 18
0
        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);
        }
Ejemplo n.º 19
0
 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));
     }
 }
Ejemplo n.º 20
0
    //
    // 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);
    }
Ejemplo n.º 21
0
        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();
        }
Ejemplo n.º 22
0
        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));
        }
Ejemplo n.º 23
0
        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);
			}
        }
Ejemplo n.º 25
0
    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);
    }
Ejemplo n.º 26
0
 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;
        }
Ejemplo n.º 28
0
        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);
            }
        }
Ejemplo n.º 30
0
        /// <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);
        }
Ejemplo n.º 31
0
        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));
 }
Ejemplo n.º 33
0
 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));
 }
Ejemplo n.º 34
0
 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));
 }
Ejemplo n.º 35
0
        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));
        }
Ejemplo n.º 36
0
        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);
        }
Ejemplo n.º 37
0
 /// <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" : "-"
                ));
 }
Ejemplo n.º 38
0
        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));
        }
Ejemplo n.º 41
0
        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));
        }
Ejemplo n.º 42
0
        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));
        }
Ejemplo n.º 43
0
        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));
            }
        }
Ejemplo n.º 44
0
        /// <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.
        }
Ejemplo n.º 45
0
 //
 // Invoked on the main loop when reachability changes
 //
 void ReachabilityChanged(NetworkReachabilityFlags flags)
 {
 }
Ejemplo n.º 46
0
        /// <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;
        }
Ejemplo n.º 47
0
        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);
        }
Ejemplo n.º 48
0
        /// <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;
        }
Ejemplo n.º 49
0
		public StatusCode GetFlags (out NetworkReachabilityFlags flags)
		{
			return SCNetworkReachabilityGetFlags (handle, out flags) == 0 ?
				StatusCodeError.SCError () : StatusCode.OK;
		}
Ejemplo n.º 50
0
		static extern bool SCNetworkReachabilityGetFlags (IntPtr reachability, out NetworkReachabilityFlags flags);
Ejemplo n.º 51
0
 /// <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);
 }
Ejemplo n.º 52
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.
        }
Ejemplo n.º 53
0
		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);
		}
Ejemplo n.º 54
0
		public bool TryGetFlags (out NetworkReachabilityFlags flags)
		{
			return GetFlags (out flags) == StatusCode.OK;
		}
Ejemplo n.º 55
0
		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));
		}
Ejemplo n.º 56
0
		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;
			}
		}
Ejemplo n.º 57
0
 static void ReachabilityChanged(NetworkReachabilityFlags flags)
 {
     FAARegistry.flags = flags;
     haveFlags = true;
 }
Ejemplo n.º 58
0
        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);
        }
Ejemplo n.º 59
0
 //
 // Invoked on the main loop when reachability changes
 //
 void ReachabilityChanged(NetworkReachabilityFlags flags)
 {
     UpdateStatus ();
 }
Ejemplo n.º 60
0
        /// <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);
        }