Example #1
0
        void GetHost_End(IAsyncResult ar)
        {
            Connect_SO stateObj = (Connect_SO)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                IPHostEntry host = Dns.EndGetHostByName(ar);
                if (null == host)
                {
                    throw new SocketException(SockErrors.WSAHOST_NOT_FOUND);
                }
                //throw new HostNotFoundException("Unable to resolve host name.");

                EndPoint remoteEP = SocketBase.ConstructEndPoint(host, stateObj.Port);
                _socket.BeginConnect(remoteEP,
                                     new AsyncCallback(Connect_End),
                                     stateObj);
            }
            catch (Exception e)
            {
                stateObj.Exception = e;
                stateObj.SetCompleted();
            }
        }
Example #2
0
        void GetHostByNameCallback(IAsyncResult ar)
        {
            IPHostEntry h;

            h = Dns.EndGetHostByName(ar);
            SubTestValidIPHostEntry(h);
        }
Example #3
0
        public void DnsObsoleteBeginEndGetHostByName_EmptyString_ReturnsHostName()
        {
            IPHostEntry entry = Dns.EndGetHostByName(Dns.BeginGetHostByName("", null, null));

            // DNS labels should be compared as case insensitive for ASCII characters. See RFC 4343.
            Assert.Contains(Dns.GetHostName(), entry.HostName, StringComparison.OrdinalIgnoreCase);
        }
Example #4
0
        public void AsyncGetHostByName()
        {
            IAsyncResult async = Dns.BeginGetHostByName(site1Name, null, null);
            IPHostEntry  entry = Dns.EndGetHostByName(async);

            SubTestValidIPHostEntry(entry);
            Assert.AreEqual("google-public-dns-a.google.com", entry.HostName, "#1");
        }
Example #5
0
        public void DnsObsoleteBeginGetHostByName_IPv4String_ReturnsOnlyGivenIP()
        {
            IAsyncResult asyncObject = Dns.BeginGetHostByName(IPAddress.Loopback.ToString(), null, null);
            IPHostEntry  entry       = Dns.EndGetHostByName(asyncObject);

            Assert.Equal(IPAddress.Loopback.ToString(), entry.HostName);
            Assert.Equal(1, entry.AddressList.Length);
            Assert.Equal(IPAddress.Loopback, entry.AddressList[0]);
        }
Example #6
0
        public void DnsObsoleteBeginGetHostByName_MachineNameWithIPv4_MatchesGetHostByName()
        {
            IAsyncResult asyncObject = Dns.BeginGetHostByName(TestSettings.LocalHost, null, null);
            IPHostEntry  result      = Dns.EndGetHostByName(asyncObject);
            IPHostEntry  entry       = Dns.GetHostByName(TestSettings.LocalHost);

            Assert.Equal(entry.HostName, result.HostName);
            Assert.Equal(entry.AddressList, result.AddressList);
        }
        public void AsyncGetHostByName()
        {
            IAsyncResult r;

            r = Dns.BeginGetHostByName(site1Name, new AsyncCallback(GetHostByNameCallback), null);

            IAsyncResult async = Dns.BeginGetHostByName(site1Name, null, null);
            IPHostEntry  entry = Dns.EndGetHostByName(async);

            SubTestValidIPHostEntry(entry);
            Assert.AreEqual("www.go-mono.com", entry.HostName);
        }
Example #8
0
        public void AsyncGetHostByName()
        {
            IAsyncResult r;

            r = Dns.BeginGetHostByName(site1Name, new AsyncCallback(GetHostByNameCallback), null);

            IAsyncResult async = Dns.BeginGetHostByName(site1Name, null, null);
            IPHostEntry  entry = Dns.EndGetHostByName(async);

            SubTestValidIPHostEntry(entry);
            Assert.IsTrue(entry.HostName == "jenkins.mono-project.com");
        }
        [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotArm64Process), nameof(PlatformDetection.IsThreadingSupported))] // [ActiveIssue("https://github.com/dotnet/runtime/issues/27622")]
        public void DnsObsoleteBeginEndGetHostByName_EmptyString_ReturnsHostName()
        {
            if (PlatformDetection.IsSLES)
            {
                // [ActiveIssue("https://github.com/dotnet/runtime/issues/48751")]
                return;
            }

            IPHostEntry entry = Dns.EndGetHostByName(Dns.BeginGetHostByName("", null, null));

            // DNS labels should be compared as case insensitive for ASCII characters. See RFC 4343.
            Assert.Contains(Dns.GetHostName(), entry.HostName, StringComparison.OrdinalIgnoreCase);
        }
Example #10
0
        public void DnsObsoleteBeginEndGetHostByName_EmptyString_ReturnsHostName()
        {
            if (PlatformDetection.IsSLES ||                                    // [ActiveIssue("https://github.com/dotnet/runtime/issues/55271")]
                PlatformDetection.IsUbuntu1604 || PlatformDetection.IsDebian9) // [ActiveIssue("https://github.com/dotnet/runtime/issues/56295")]
            {
                throw new SkipTestException("Test environment is not configured for this test to work.");
            }

            IPHostEntry entry = Dns.EndGetHostByName(Dns.BeginGetHostByName("", null, null));

            // DNS labels should be compared as case insensitive for ASCII characters. See RFC 4343.
            Assert.Contains(Dns.GetHostName(), entry.HostName, StringComparison.OrdinalIgnoreCase);
        }
Example #11
0
        static internal IPHostEntry EndGetHostByName(IAsyncResult ar)
        {
            IPHostEntry host = null;

            try
            {
                host = Dns.EndGetHostByName(ar);
            }
            catch (Exception)
            {
                host = null;
            }
            return(host);
        }
Example #12
0
        static async Task Main(string[] args)
        {
            var x = await Dns.GetHostAddressesAsync("localhost");

            string hostname = Dns.GetHostName();
            var    y        = Dns.EndGetHostByName(Dns.BeginGetHostByName("", null, null));

            Console.WriteLine("My hostname is '{0}'", hostname);
            Console.WriteLine("My ip addresses are:");
            foreach (var address in Dns.GetHostAddresses(hostname))
            {
                Console.WriteLine("\t{0}", address);
            }
        }
Example #13
0
 private void GetHostByNameCallback(IAsyncResult ar)
 {
     Dns.EndGetHostByName(ar);
     try {
         // can we do something bad here ?
         Assert.IsNotNull(Environment.GetEnvironmentVariable("USERNAME"));
         message = "Expected a SecurityException";
     }
     catch (SecurityException) {
         message = null;
         reset.Set();
     }
     catch (Exception e)
     {
         message = e.ToString();
     }
 }
Example #14
0
    private static void DnsLookupCompleted(IAsyncResult ar)
    {
        IPHostEntry entry = Dns.EndGetHostByName(ar);

        Console.WriteLine("IP Addresses for {0}: ", hostname);
        foreach (IPAddress address in entry.AddressList)
        {
            Console.WriteLine(address.ToString());
        }
        Console.WriteLine("\nAlias names:");
        foreach (string aliasName in entry.Aliases)
        {
            Console.WriteLine(aliasName);
        }
        Console.WriteLine("\nAnd the real hostname:");
        Console.WriteLine(entry.HostName);
    }
Example #15
0
        private void GetHostByNameSink(IAsyncResult result)
        {
            IPHostEntry entry = null;

            try
            {
                entry = Dns.EndGetHostByName(result);
            }
            catch (Exception)
            {
                return;
            }
            object[] asyncState = (object[])result.AsyncState;
            Uri      uri        = (Uri)asyncState[0];
            object   tag        = asyncState[1];

            this.ContinueRequest(new IPEndPoint(entry.AddressList[0], uri.Port), HTTPMessage.UnEscapeString(uri.PathAndQuery), tag, null);
        }
Example #16
0
        public void AsyncGetHostByNameCallback()
        {
            var       evt = new ManualResetEvent(false);
            Exception ex  = null;

            Dns.BeginGetHostByName(site1Name, new AsyncCallback((IAsyncResult ar) =>
            {
                try {
                    IPHostEntry h;
                    h = Dns.EndGetHostByName(ar);
                    SubTestValidIPHostEntry(h);
                } catch (Exception e) {
                    ex = e;
                } finally {
                    evt.Set();
                }
            }), null);

            Assert.IsTrue(evt.WaitOne(TimeSpan.FromSeconds(60)), "Wait");
            Assert.IsNull(ex, "Exception");
        }
Example #17
0
        private void GetHostEntryCallback(IAsyncResult ar)
        {
            IPHostEntry iphostEntry = Dns.EndGetHostByName(ar);

            Array.Sort <IPAddress>(iphostEntry.AddressList, delegate(IPAddress x, IPAddress y)
            {
                if (x.AddressFamily < y.AddressFamily)
                {
                    return(-1);
                }
                if (x.AddressFamily > y.AddressFamily)
                {
                    return(1);
                }
                return(0);
            });
            foreach (IPAddress item in iphostEntry.AddressList)
            {
                this.m_candidateIPAddresses.Enqueue(item);
            }
            this.ConnectInternal();
        }
        private void GetHostEntryCallback(IAsyncResult ar)
        {
            IPHostEntry pHostEntry = Dns.EndGetHostByName(ar);

            Array.Sort <IPAddress>(pHostEntry.AddressList, (IPAddress x, IPAddress y) => {
                if (x.AddressFamily < y.AddressFamily)
                {
                    return(-1);
                }
                if (x.AddressFamily > y.AddressFamily)
                {
                    return(1);
                }
                return(0);
            });
            IPAddress[] addressList = pHostEntry.AddressList;
            for (int i = 0; i < (int)addressList.Length; i++)
            {
                IPAddress pAddress = addressList[i];
                this.m_candidateIPAddresses.Enqueue(pAddress);
            }
            this.ConnectInternal();
        }
Example #19
0
        private void GetHostEntryCallback(IAsyncResult ar)
        {
            IPHostEntry iPHostEntry = Dns.EndGetHostByName(ar);

            Array.Sort <IPAddress>(iPHostEntry.get_AddressList(), delegate(IPAddress x, IPAddress y)
            {
                if (x.get_AddressFamily() < y.get_AddressFamily())
                {
                    return(-1);
                }
                if (x.get_AddressFamily() > y.get_AddressFamily())
                {
                    return(1);
                }
                return(0);
            });
            IPAddress[] addressList = iPHostEntry.get_AddressList();
            for (int i = 0; i < addressList.Length; i++)
            {
                IPAddress iPAddress = addressList[i];
                this.m_candidateIPAddresses.Enqueue(iPAddress);
            }
            this.ConnectInternal();
        }
Example #20
0
        public void DnsObsoleteBeginGetHostByName_BadName_Throws()
        {
            IAsyncResult asyncObject = Dns.BeginGetHostByName("BadName", null, null);

            Assert.ThrowsAny <SocketException>(() => Dns.EndGetHostByName(asyncObject));
        }
Example #21
0
        public void DnsObsoleteBeginEndGetHostByName_EmptyString_ReturnsHostName()
        {
            IPHostEntry entry = Dns.EndGetHostByName(Dns.BeginGetHostByName("", null, null));

            Assert.Contains(Dns.GetHostName(), entry.HostName);
        }
Example #22
0
 public void Deny_EndGetHostByName()
 {
     Dns.EndGetHostByName(null);
 }