From 762b6b01da135c902763037f639313f9fcc68a3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=81=E4=B9=9D?= <366193849@qq.com> Date: Mon, 30 Aug 2021 22:46:50 +0800 Subject: [PATCH] =?UTF-8?q?dns=E7=9B=91=E5=90=AC=E8=BA=AB=E4=BB=BD?= =?UTF-8?q?=E6=A3=80=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FastGithub.Dns/DnsOverUdpServer.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/FastGithub.Dns/DnsOverUdpServer.cs b/FastGithub.Dns/DnsOverUdpServer.cs index 8ad3d94..511cac0 100644 --- a/FastGithub.Dns/DnsOverUdpServer.cs +++ b/FastGithub.Dns/DnsOverUdpServer.cs @@ -55,8 +55,20 @@ namespace FastGithub.Dns const int SIO_UDP_CONNRESET = unchecked((int)0x9800000C); this.socket.IOControl(SIO_UDP_CONNRESET, new byte[4], new byte[4]); } - this.socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); - this.socket.Bind(new IPEndPoint(address, port)); + + try + { + this.socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); + this.socket.Bind(new IPEndPoint(address, port)); + } + catch (SocketException ex) when (ex.SocketErrorCode == SocketError.AccessDenied) + { + if (OperatingSystem.IsLinux()) + { + throw new FastGithubException($"请以root身份运行", ex); + } + throw; + } } ///