From c593db925f3d15faee3e15e405e5b082f1700b2c Mon Sep 17 00:00:00 2001 From: Shreyas Zare Date: Sun, 10 May 2020 13:35:48 +0530 Subject: [PATCH] WebService: fixed minor issue in GetRequestRemoteEndPoint(). --- DnsServerCore/WebService.cs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/DnsServerCore/WebService.cs b/DnsServerCore/WebService.cs index 2f35a06c..fccbc977 100644 --- a/DnsServerCore/WebService.cs +++ b/DnsServerCore/WebService.cs @@ -535,21 +535,18 @@ namespace DnsServerCore private IPEndPoint GetRequestRemoteEndPoint(HttpListenerRequest request) { - //this is due to mono NullReferenceException issue try { - if (NetUtilities.IsPrivateIP(request.RemoteEndPoint.Address)) + string xRealIp = request.Headers["X-Real-IP"]; + if (IPAddress.TryParse(xRealIp, out IPAddress address)) { - //reverse proxy X-Real-IP header supported only when remote IP address is private - - string xRealIp = request.Headers["X-Real-IP"]; - if (!string.IsNullOrEmpty(xRealIp)) - { - //get the real IP address of the requesting client from X-Real-IP header set in nginx proxy_pass block - return new IPEndPoint(IPAddress.Parse(xRealIp), 0); - } + //get the real IP address of the requesting client from X-Real-IP header set in nginx proxy_pass block + return new IPEndPoint(address, 0); } + if (request.RemoteEndPoint == null) + return new IPEndPoint(IPAddress.Any, 0); + return request.RemoteEndPoint; } catch