コード例 #1
0
        public NetworkReachability(IPAddress localAddress, IPAddress remoteAddress)
        {
            if (localAddress == null && remoteAddress == null)
            {
                throw new ArgumentException("At least one address is required");
            }

            if (localAddress == null)
            {
                var remote = new sockaddr_in(remoteAddress);

                handle = SCNetworkReachabilityCreateWithAddressPair(IntPtr.Zero, IntPtr.Zero, ref remote);
            }
            else if (remoteAddress == null)
            {
                var local = new sockaddr_in(localAddress);

                handle = SCNetworkReachabilityCreateWithAddressPair(IntPtr.Zero, ref local, IntPtr.Zero);
            }
            else
            {
                var local  = new sockaddr_in(localAddress);
                var remote = new sockaddr_in(remoteAddress);

                handle = SCNetworkReachabilityCreateWithAddressPair(IntPtr.Zero, ref local, ref remote);
            }

            if (handle == IntPtr.Zero)
            {
                throw SystemConfigurationException.FromMostRecentCall();
            }
        }
コード例 #2
0
        public NetworkReachability(string address)
        {
            if (address == null)
            {
                throw new ArgumentNullException("address");
            }

            handle = SCNetworkReachabilityCreateWithName(IntPtr.Zero, address);
            if (handle == IntPtr.Zero)
            {
                throw SystemConfigurationException.FromMostRecentCall();
            }
        }
コード例 #3
0
        public NetworkReachability(IPAddress ip)
        {
            if (ip == null)
            {
                throw new ArgumentNullException("ip");
            }

            var s = new sockaddr_in(ip);

            handle = SCNetworkReachabilityCreateWithAddress(IntPtr.Zero, ref s);
            if (handle == IntPtr.Zero)
            {
                throw SystemConfigurationException.FromMostRecentCall();
            }
        }