From 8a42d3c9d4b58d2b81725b87067d5c32bb620710 Mon Sep 17 00:00:00 2001 From: celeron533 Date: Sat, 13 Apr 2019 20:41:58 +0800 Subject: [PATCH] Exception for port assignment When error code is SocketError.AccessDenied/10013(WSAEACCES), the port is reserved by system and you may not find the process name in `netstat`. https://github.com/shadowsocks/shadowsocks-windows/issues/1835#issuecomment-453528715 --- shadowsocks-csharp/Controller/ShadowsocksController.cs | 6 +++++- shadowsocks-csharp/Data/ja.txt | 1 + shadowsocks-csharp/Data/zh_CN.txt | 1 + shadowsocks-csharp/Data/zh_TW.txt | 1 + 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/shadowsocks-csharp/Controller/ShadowsocksController.cs b/shadowsocks-csharp/Controller/ShadowsocksController.cs index 9a9c3a48..b103c17a 100644 --- a/shadowsocks-csharp/Controller/ShadowsocksController.cs +++ b/shadowsocks-csharp/Controller/ShadowsocksController.cs @@ -551,10 +551,14 @@ namespace Shadowsocks.Controller if (e is SocketException) { SocketException se = (SocketException)e; - if (se.SocketErrorCode == SocketError.AccessDenied) + if (se.SocketErrorCode == SocketError.AddressAlreadyInUse) { e = new Exception(I18N.GetString("Port {0} already in use", _config.localPort), e); } + else if (se.SocketErrorCode == SocketError.AccessDenied) + { + e = new Exception(I18N.GetString("Port {0} is reserved by system", _config.localPort), e); + } } Logging.LogUsefulException(e); ReportError(e); diff --git a/shadowsocks-csharp/Data/ja.txt b/shadowsocks-csharp/Data/ja.txt index abba4c7a..690e0d58 100644 --- a/shadowsocks-csharp/Data/ja.txt +++ b/shadowsocks-csharp/Data/ja.txt @@ -118,6 +118,7 @@ Reg Hotkeys At Startup=起動時にホットキーを登録する Shadowsocks Error: {0}=Shadowsocks エラー: {0} Port {0} already in use=ポート番号 {0} は既に使用されています。 +Port {0} is reserved by system= ポート番号 {0} はシステムによって予約されています Invalid server address=サーバーアドレスが無効です。 Illegal port number format=ポート番号のフォーマットが無効です。 Illegal timeout format=タイムアウト値のフォーマットが無効です。 diff --git a/shadowsocks-csharp/Data/zh_CN.txt b/shadowsocks-csharp/Data/zh_CN.txt index 66fb2c14..b26593b0 100644 --- a/shadowsocks-csharp/Data/zh_CN.txt +++ b/shadowsocks-csharp/Data/zh_CN.txt @@ -119,6 +119,7 @@ Reg Hotkeys At Startup=启动时注册快捷键 Shadowsocks Error: {0}=Shadowsocks 错误: {0} Port {0} already in use=端口 {0} 已被占用 +Port {0} is reserved by system=端口 {0} 是系统保留端口 Invalid server address=非法服务器地址 Illegal port number format=非法端口格式 Illegal timeout format=非法超时格式 diff --git a/shadowsocks-csharp/Data/zh_TW.txt b/shadowsocks-csharp/Data/zh_TW.txt index c2157bbb..d4b75ef8 100644 --- a/shadowsocks-csharp/Data/zh_TW.txt +++ b/shadowsocks-csharp/Data/zh_TW.txt @@ -118,6 +118,7 @@ Reg Hotkeys At Startup=啟動時註冊快速鍵 Shadowsocks Error: {0}=Shadowsocks 錯誤: {0} Port {0} already in use=連接埠號碼 {0} 已被使用 +Port {0} is reserved by system=連接埠號碼 {0} 由系統保留 Invalid server address=無效伺服器位址 Illegal port number format=無效連接埠號碼格式 Illegal timeout format=無效逾時格式