You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ta...@apache.org on 2022/11/28 21:33:13 UTC

[qpid-proton-dotnet] branch main updated: PROTON-2656 Try to parse address strings as IP address values first

This is an automated email from the ASF dual-hosted git repository.

tabish pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-proton-dotnet.git


The following commit(s) were added to refs/heads/main by this push:
     new 010aced  PROTON-2656 Try to parse address strings as IP address values first
010aced is described below

commit 010aced388f3cbc73a03065d4c3e8e668263fd3c
Author: Timothy Bish <ta...@gmail.com>
AuthorDate: Mon Nov 28 16:31:37 2022 -0500

    PROTON-2656 Try to parse address strings as IP address values first
    
    Instead of going into DNS lookup APIs for all string address values we can
    first attempt a parse to see if we have a raw IP Address and simply use
    the value given as what was intended.
---
 src/Proton.Client/Client/Transport/TcpTransport.cs | 35 ++++++++++++++--------
 src/Proton.TestPeer/Network/PeerTcpClient.cs       |  8 +++++
 2 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/src/Proton.Client/Client/Transport/TcpTransport.cs b/src/Proton.Client/Client/Transport/TcpTransport.cs
index b9d73e6..f8748d8 100644
--- a/src/Proton.Client/Client/Transport/TcpTransport.cs
+++ b/src/Proton.Client/Client/Transport/TcpTransport.cs
@@ -248,24 +248,33 @@ namespace Apache.Qpid.Proton.Client.Transport
 
       private static IPAddress ResolveIPAddress(string address)
       {
-         IPHostEntry entry = Dns.GetHostEntry(address);
-         IPAddress result = default;
-
-         foreach (IPAddress ipAddress in entry.AddressList)
+         // If we can parse the address then we do that as that is what the caller requested
+         // instead of looking up host entries etc.
+         if (IPAddress.TryParse(address, out IPAddress parsed) && parsed.AddressFamily == AddressFamily.InterNetwork)
+         {
+            return parsed;
+         }
+         else
          {
-            if (ipAddress.AddressFamily == AddressFamily.InterNetwork)
+            IPHostEntry entry = Dns.GetHostEntry(address);
+            IPAddress result = default;
+
+            foreach (IPAddress ipAddress in entry.AddressList)
+            {
+               if (ipAddress.AddressFamily == AddressFamily.InterNetwork)
+               {
+                  result = ipAddress;
+               }
+            }
+
+            if (result == default(IPAddress))
             {
-               result = ipAddress;
+               throw new IOException(
+                  string.Format("Could not resolve a remote address from the given host: {0}", address));
             }
-         }
 
-         if (result == default(IPAddress))
-         {
-            throw new IOException(
-               string.Format("Could not resolve a remote address from the given host: {0}", address));
+            return result;
          }
-
-         return result;
       }
 
       private void CheckConnected(IProtonBuffer output)
diff --git a/src/Proton.TestPeer/Network/PeerTcpClient.cs b/src/Proton.TestPeer/Network/PeerTcpClient.cs
index 465581a..846a1fb 100644
--- a/src/Proton.TestPeer/Network/PeerTcpClient.cs
+++ b/src/Proton.TestPeer/Network/PeerTcpClient.cs
@@ -48,6 +48,14 @@ namespace Apache.Qpid.Proton.Test.Driver.Network
       {
          this.address = address;
 
+         if (IPAddress.TryParse(address, out IPAddress parsedAddress))
+         {
+            if (parsedAddress.AddressFamily == AddressFamily.InterNetwork)
+            {
+               return Connect(new IPEndPoint(parsedAddress, port));
+            }
+         }
+
          IPHostEntry entry = Dns.GetHostEntry(address);
          foreach (IPAddress ipAddress in entry.AddressList)
          {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org