Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.

Commit 49b5fb7

Browse files
committed
use GetHostAddressesAsync
1 parent 6f54d93 commit 49b5fb7

File tree

1 file changed

+2
-13
lines changed

1 file changed

+2
-13
lines changed

src/Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -287,17 +287,8 @@ private async Task<TcpServerConnection> createServerConnection(string remoteHost
287287
var hostname = useUpstreamProxy ? externalProxy.HostName : remoteHostName;
288288
var port = useUpstreamProxy ? externalProxy.Port : remotePort;
289289

290-
IPHostEntry ipHostEntry;
291-
if (IPAddress.TryParse(hostname, out var ipAddress))
292-
{
293-
ipHostEntry = await Dns.GetHostEntryAsync(ipAddress);
294-
}
295-
else
296-
{
297-
ipHostEntry = await Dns.GetHostEntryAsync(hostname);
298-
}
299-
300-
if (ipHostEntry == null || ipHostEntry.AddressList.Length == 0)
290+
var ipAddresses = await Dns.GetHostAddressesAsync(hostname);
291+
if (ipAddresses == null || ipAddresses.Length == 0)
301292
{
302293
throw new Exception($"Could not resolve the hostname {hostname}");
303294
}
@@ -307,8 +298,6 @@ private async Task<TcpServerConnection> createServerConnection(string remoteHost
307298
session.TimeLine["Dns Resolved"] = DateTime.Now;
308299
}
309300

310-
var ipAddresses = ipHostEntry.AddressList;
311-
312301
for (int i = 0; i < ipAddresses.Length; i++)
313302
{
314303
try

0 commit comments

Comments
 (0)