Skip to content

Commit

Permalink
dns监听身份检测
Browse files Browse the repository at this point in the history
  • Loading branch information
xljiulang committed Aug 30, 2021
1 parent e354e80 commit 762b6b0
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions FastGithub.Dns/DnsOverUdpServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,20 @@ public void Bind(IPAddress address, int port)
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;
}
}

/// <summary>
Expand Down

0 comments on commit 762b6b0

Please sign in to comment.