1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2025-04-03 18:00:08 +03:00

Improve the internal processing of NAT-T hint string

This commit is contained in:
Yihong Wu 2021-12-10 18:04:24 +08:00
parent 918fedb9d4
commit c1d89399e8
12 changed files with 115 additions and 61 deletions

View File

@ -6649,6 +6649,7 @@ void CmEditAccountDlgUpdate(HWND hWnd, CM_ACCOUNT *a)
// Host name // Host name
GetTxtA(hWnd, E_HOSTNAME, a->ClientOption->Hostname, sizeof(a->ClientOption->Hostname)); GetTxtA(hWnd, E_HOSTNAME, a->ClientOption->Hostname, sizeof(a->ClientOption->Hostname));
Trim(a->ClientOption->Hostname); Trim(a->ClientOption->Hostname);
a->ClientOption->HintStr[0] = 0;
if (InStr(a->ClientOption->Hostname, "/tcp")) if (InStr(a->ClientOption->Hostname, "/tcp"))
{ {
@ -7091,10 +7092,17 @@ void CmEditAccountDlgInit(HWND hWnd, CM_ACCOUNT *a)
SetText(hWnd, E_ACCOUNT_NAME, a->ClientOption->AccountName); SetText(hWnd, E_ACCOUNT_NAME, a->ClientOption->AccountName);
// Host name // Host name
SetTextA(hWnd, E_HOSTNAME, a->ClientOption->Hostname); char hostname[MAX_SIZE];
StrCpy(a->old_server_name, sizeof(a->old_server_name), a->ClientOption->Hostname); StrCpy(hostname, sizeof(hostname), a->ClientOption->Hostname);
if (IsEmptyStr(a->ClientOption->HintStr) == false)
{
StrCat(hostname, sizeof(hostname), "/");
StrCat(hostname, sizeof(hostname), a->ClientOption->HintStr);
}
SetTextA(hWnd, E_HOSTNAME, hostname);
StrCpy(a->old_server_name, sizeof(a->old_server_name), hostname);
if (InStr(a->ClientOption->Hostname, "/tcp")) if (InStr(hostname, "/tcp"))
{ {
Check(hWnd, R_DISABLE_NATT, true); Check(hWnd, R_DISABLE_NATT, true);
} }

View File

@ -4315,6 +4315,13 @@ void InRpcClientOption(CLIENT_OPTION *c, PACK *p)
PackGetUniStr(p, "AccountName", c->AccountName, sizeof(c->AccountName)); PackGetUniStr(p, "AccountName", c->AccountName, sizeof(c->AccountName));
PackGetStr(p, "Hostname", c->Hostname, sizeof(c->Hostname)); PackGetStr(p, "Hostname", c->Hostname, sizeof(c->Hostname));
// Extract hint string from hostname
UINT i = SearchStrEx(c->Hostname, "/", 0, false);
if (i != INFINITE)
{
StrCpy(c->HintStr, sizeof(c->HintStr), c->Hostname + i + 1);
c->Hostname[i] = 0;
}
c->Port = PackGetInt(p, "Port"); c->Port = PackGetInt(p, "Port");
c->PortUDP = PackGetInt(p, "PortUDP"); c->PortUDP = PackGetInt(p, "PortUDP");
c->ProxyType = PackGetInt(p, "ProxyType"); c->ProxyType = PackGetInt(p, "ProxyType");
@ -4352,7 +4359,20 @@ void OutRpcClientOption(PACK *p, CLIENT_OPTION *c)
} }
PackAddUniStr(p, "AccountName", c->AccountName); PackAddUniStr(p, "AccountName", c->AccountName);
PackAddStr(p, "Hostname", c->Hostname); // Append hint string to hostname
if (IsEmptyStr(c->HintStr))
{
// No hint
PackAddStr(p, "Hostname", c->Hostname);
}
else
{
char hostname[MAX_SIZE];
StrCpy(hostname, sizeof(hostname), c->Hostname);
StrCat(hostname, sizeof(hostname), "/");
StrCat(hostname, sizeof(hostname), c->HintStr);
PackAddStr(p, "Hostname", hostname);
}
PackAddStr(p, "ProxyName", c->ProxyName); PackAddStr(p, "ProxyName", c->ProxyName);
PackAddStr(p, "ProxyUsername", c->ProxyUsername); PackAddStr(p, "ProxyUsername", c->ProxyUsername);
PackAddStr(p, "ProxyPassword", c->ProxyPassword); PackAddStr(p, "ProxyPassword", c->ProxyPassword);
@ -7027,6 +7047,12 @@ bool CtEnumAccount(CLIENT *c, RPC_CLIENT_ENUM_ACCOUNT *e)
// Server name // Server name
StrCpy(item->ServerName, sizeof(item->ServerName), a->ClientOption->Hostname); StrCpy(item->ServerName, sizeof(item->ServerName), a->ClientOption->Hostname);
// Append hint string to hostname
if (IsEmptyStr(a->ClientOption->HintStr) == false)
{
StrCat(item->ServerName, sizeof(item->ServerName), "/");
StrCat(item->ServerName, sizeof(item->ServerName), a->ClientOption->HintStr);
}
// Proxy type // Proxy type
item->ProxyType = a->ClientOption->ProxyType; item->ProxyType = a->ClientOption->ProxyType;
@ -9219,6 +9245,13 @@ CLIENT_OPTION *CiLoadClientOption(FOLDER *f)
CfgGetUniStr(f, "AccountName", o->AccountName, sizeof(o->AccountName)); CfgGetUniStr(f, "AccountName", o->AccountName, sizeof(o->AccountName));
CfgGetStr(f, "Hostname", o->Hostname, sizeof(o->Hostname)); CfgGetStr(f, "Hostname", o->Hostname, sizeof(o->Hostname));
// Extract hint string from hostname
UINT i = SearchStrEx(o->Hostname, "/", 0, false);
if (i != INFINITE)
{
StrCpy(o->HintStr, sizeof(o->HintStr), o->Hostname + i + 1);
o->Hostname[i] = 0;
}
o->Port = CfgGetInt(f, "Port"); o->Port = CfgGetInt(f, "Port");
o->PortUDP = CfgGetInt(f, "PortUDP"); o->PortUDP = CfgGetInt(f, "PortUDP");
o->ProxyType = CfgGetInt(f, "ProxyType"); o->ProxyType = CfgGetInt(f, "ProxyType");
@ -9761,7 +9794,20 @@ void CiWriteClientOption(FOLDER *f, CLIENT_OPTION *o)
} }
CfgAddUniStr(f, "AccountName", o->AccountName); CfgAddUniStr(f, "AccountName", o->AccountName);
CfgAddStr(f, "Hostname", o->Hostname); // Append hint string to hostname
if (IsEmptyStr(o->HintStr))
{
// No hint
CfgAddStr(f, "Hostname", o->Hostname);
}
else
{
char hostname[MAX_SIZE];
StrCpy(hostname, sizeof(hostname), o->Hostname);
StrCat(hostname, sizeof(hostname), "/");
StrCat(hostname, sizeof(hostname), o->HintStr);
CfgAddStr(f, "Hostname", hostname);
}
CfgAddInt(f, "Port", o->Port); CfgAddInt(f, "Port", o->Port);
CfgAddInt(f, "PortUDP", o->PortUDP); CfgAddInt(f, "PortUDP", o->PortUDP);
CfgAddInt(f, "ProxyType", o->ProxyType); CfgAddInt(f, "ProxyType", o->ProxyType);

View File

@ -2071,7 +2071,7 @@ void TtcThread(THREAD *thread, void *param)
IPToStr(target_host, sizeof(target_host), &ip_ret); IPToStr(target_host, sizeof(target_host), &ip_ret);
} }
s = ConnectEx4(target_host, ttc->Port, 0, ttc->Cancel, NULL, NULL, false, true, &ip_ret); s = ConnectEx4(target_host, ttc->Port, 0, ttc->Cancel, NULL, NULL, false, true, NULL, &ip_ret);
if (s == NULL) if (s == NULL)
{ {
@ -4333,6 +4333,7 @@ UINT PcAccountSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
// Success // Success
t.ClientOption->Port = port; t.ClientOption->Port = port;
StrCpy(t.ClientOption->Hostname, sizeof(t.ClientOption->Hostname), host); StrCpy(t.ClientOption->Hostname, sizeof(t.ClientOption->Hostname), host);
t.ClientOption->HintStr[0] = 0;
StrCpy(t.ClientOption->HubName, sizeof(t.ClientOption->HubName), GetParamStr(o, "HUB")); StrCpy(t.ClientOption->HubName, sizeof(t.ClientOption->HubName), GetParamStr(o, "HUB"));
Zero(&c, sizeof(c)); Zero(&c, sizeof(c));
@ -4400,7 +4401,18 @@ UINT PcAccountGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_NAME"), t.ClientOption->AccountName); CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_NAME"), t.ClientOption->AccountName);
// Host name of the destination VPN Server // Host name of the destination VPN Server
StrToUni(tmp, sizeof(tmp), t.ClientOption->Hostname); if (IsEmptyStr(t.ClientOption->HintStr))
{
StrToUni(tmp, sizeof(tmp), t.ClientOption->Hostname);
}
else
{
char hostname[MAX_SIZE];
StrCpy(hostname, sizeof(hostname), t.ClientOption->Hostname);
StrCat(hostname, sizeof(hostname), "/");
StrCat(hostname, sizeof(hostname), t.ClientOption->HintStr);
StrToUni(tmp, sizeof(tmp), hostname);
}
CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_HOSTNAME"), tmp); CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_HOSTNAME"), tmp);
// The port number to connect to VPN Server // The port number to connect to VPN Server
@ -13117,6 +13129,7 @@ UINT PsCascadeSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
t.ClientOption->Port = port; t.ClientOption->Port = port;
StrCpy(t.ClientOption->Hostname, sizeof(t.ClientOption->Hostname), host); StrCpy(t.ClientOption->Hostname, sizeof(t.ClientOption->Hostname), host);
t.ClientOption->HintStr[0] = 0;
StrCpy(t.ClientOption->HubName, sizeof(t.ClientOption->HubName), GetParamStr(o, "HUB")); StrCpy(t.ClientOption->HubName, sizeof(t.ClientOption->HubName), GetParamStr(o, "HUB"));
Free(host); Free(host);
@ -13223,7 +13236,18 @@ UINT PsCascadeGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_NAME"), t.ClientOption->AccountName); CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_NAME"), t.ClientOption->AccountName);
// Host name of the destination VPN Server // Host name of the destination VPN Server
StrToUni(tmp, sizeof(tmp), t.ClientOption->Hostname); if (IsEmptyStr(t.ClientOption->HintStr))
{
StrToUni(tmp, sizeof(tmp), t.ClientOption->Hostname);
}
else
{
char hostname[MAX_SIZE];
StrCpy(hostname, sizeof(hostname), t.ClientOption->Hostname);
StrCat(hostname, sizeof(hostname), "/");
StrCat(hostname, sizeof(hostname), t.ClientOption->HintStr);
StrToUni(tmp, sizeof(tmp), hostname);
}
CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_HOSTNAME"), tmp); CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_HOSTNAME"), tmp);
// The port number to connect to VPN Server // The port number to connect to VPN Server

View File

@ -64,6 +64,7 @@ struct CLIENT_OPTION
{ {
wchar_t AccountName[MAX_ACCOUNT_NAME_LEN + 1]; // Connection setting name wchar_t AccountName[MAX_ACCOUNT_NAME_LEN + 1]; // Connection setting name
char Hostname[MAX_HOST_NAME_LEN + 1]; // Host name char Hostname[MAX_HOST_NAME_LEN + 1]; // Host name
char HintStr[MAX_HOST_NAME_LEN + 1]; // Hint string for NAT-T
UINT Port; // Port number UINT Port; // Port number
UINT PortUDP; // UDP port number (0: Use only TCP) UINT PortUDP; // UDP port number (0: Use only TCP)
UINT ProxyType; // Type of proxy UINT ProxyType; // Type of proxy

View File

@ -6308,7 +6308,7 @@ SOCK *ClientConnectGetSocket(CONNECTION *c, bool additional_connect)
// If additional_connect == true, follow the IsRUDPSession setting in this session // If additional_connect == true, follow the IsRUDPSession setting in this session
sock = TcpIpConnectEx(hostname, c->ServerPort, sock = TcpIpConnectEx(hostname, c->ServerPort,
(bool *)cancel_flag, c->hWndForUI, &nat_t_err, (additional_connect ? (!sess->IsRUDPSession) : false), (bool *)cancel_flag, c->hWndForUI, &nat_t_err, (additional_connect ? (!sess->IsRUDPSession) : false),
true, &resolved_ip); true, o->HintStr, &resolved_ip);
} }
else else
{ {
@ -6443,24 +6443,24 @@ UINT ProxyCodeToCedar(UINT code)
} }
// TCP connection function // TCP connection function
SOCK *TcpConnectEx3(char *hostname, UINT port, UINT timeout, bool *cancel_flag, void *hWnd, bool no_nat_t, UINT *nat_t_error_code, bool try_start_ssl, IP *ret_ip) SOCK *TcpConnectEx3(char *hostname, UINT port, UINT timeout, bool *cancel_flag, void *hWnd, bool no_nat_t, UINT *nat_t_error_code, bool try_start_ssl, char *hint_str, IP *ret_ip)
{ {
#ifdef OS_WIN32 #ifdef OS_WIN32
if (hWnd == NULL) if (hWnd == NULL)
{ {
#endif // OS_WIN32 #endif // OS_WIN32
return ConnectEx4(hostname, port, timeout, cancel_flag, (no_nat_t ? NULL : VPN_RUDP_SVC_NAME), nat_t_error_code, try_start_ssl, true, ret_ip); return ConnectEx4(hostname, port, timeout, cancel_flag, (no_nat_t ? NULL : VPN_RUDP_SVC_NAME), nat_t_error_code, try_start_ssl, true, hint_str, ret_ip);
#ifdef OS_WIN32 #ifdef OS_WIN32
} }
else else
{ {
return WinConnectEx3((HWND)hWnd, hostname, port, timeout, 0, NULL, NULL, nat_t_error_code, (no_nat_t ? NULL : VPN_RUDP_SVC_NAME), try_start_ssl); return WinConnectEx3((HWND)hWnd, hostname, port, timeout, 0, NULL, NULL, nat_t_error_code, (no_nat_t ? NULL : VPN_RUDP_SVC_NAME), try_start_ssl, hint_str);
} }
#endif // OS_WIN32 #endif // OS_WIN32
} }
// Connect with TCP/IP // Connect with TCP/IP
SOCK *TcpIpConnectEx(char *hostname, UINT port, bool *cancel_flag, void *hWnd, UINT *nat_t_error_code, bool no_nat_t, bool try_start_ssl, IP *ret_ip) SOCK *TcpIpConnectEx(char *hostname, UINT port, bool *cancel_flag, void *hWnd, UINT *nat_t_error_code, bool no_nat_t, bool try_start_ssl, char *hint_str, IP *ret_ip)
{ {
SOCK *s = NULL; SOCK *s = NULL;
UINT dummy_int = 0; UINT dummy_int = 0;
@ -6475,7 +6475,7 @@ SOCK *TcpIpConnectEx(char *hostname, UINT port, bool *cancel_flag, void *hWnd, U
return NULL; return NULL;
} }
s = TcpConnectEx3(hostname, port, 0, cancel_flag, hWnd, no_nat_t, nat_t_error_code, try_start_ssl, ret_ip); s = TcpConnectEx3(hostname, port, 0, cancel_flag, hWnd, no_nat_t, nat_t_error_code, try_start_ssl, hint_str, ret_ip);
if (s == NULL) if (s == NULL)
{ {
return NULL; return NULL;

View File

@ -113,14 +113,14 @@ UINT64 ShortStrToDate64(char *str);
bool ServerAccept(CONNECTION *c); bool ServerAccept(CONNECTION *c);
bool ClientConnect(CONNECTION *c); bool ClientConnect(CONNECTION *c);
SOCK *ClientConnectToServer(CONNECTION *c); SOCK *ClientConnectToServer(CONNECTION *c);
SOCK *TcpIpConnectEx(char *hostname, UINT port, bool *cancel_flag, void *hWnd, UINT *nat_t_error_code, bool no_nat_t, bool try_start_ssl, IP *ret_ip); SOCK *TcpIpConnectEx(char *hostname, UINT port, bool *cancel_flag, void *hWnd, UINT *nat_t_error_code, bool no_nat_t, bool try_start_ssl, char *hint_str, IP *ret_ip);
bool ClientUploadSignature(SOCK *s); bool ClientUploadSignature(SOCK *s);
bool ClientDownloadHello(CONNECTION *c, SOCK *s); bool ClientDownloadHello(CONNECTION *c, SOCK *s);
bool ServerDownloadSignature(CONNECTION *c, char **error_detail_str); bool ServerDownloadSignature(CONNECTION *c, char **error_detail_str);
bool ServerUploadHello(CONNECTION *c); bool ServerUploadHello(CONNECTION *c);
bool ClientUploadAuth(CONNECTION *c); bool ClientUploadAuth(CONNECTION *c);
SOCK *ClientConnectGetSocket(CONNECTION *c, bool additional_connect); SOCK *ClientConnectGetSocket(CONNECTION *c, bool additional_connect);
SOCK *TcpConnectEx3(char *hostname, UINT port, UINT timeout, bool *cancel_flag, void *hWnd, bool no_nat_t, UINT *nat_t_error_code, bool try_start_ssl, IP *ret_ip); SOCK *TcpConnectEx3(char *hostname, UINT port, UINT timeout, bool *cancel_flag, void *hWnd, bool no_nat_t, UINT *nat_t_error_code, bool try_start_ssl, char *hint_str, IP *ret_ip);
UINT ProxyCodeToCedar(UINT code); UINT ProxyCodeToCedar(UINT code);

View File

@ -1329,7 +1329,7 @@ void WinConnectDlgThread(THREAD *thread, void *param)
nat_t_svc_name = d->nat_t_svc_name; nat_t_svc_name = d->nat_t_svc_name;
} }
s = ConnectEx3(d->hostname, d->port, d->timeout, &d->cancel, nat_t_svc_name, &nat_t_error_code, d->try_start_ssl, false); s = ConnectEx4(d->hostname, d->port, d->timeout, &d->cancel, nat_t_svc_name, &nat_t_error_code, d->try_start_ssl, false, d->hint_str, NULL);
d->ret_sock = s; d->ret_sock = s;
d->nat_t_error_code = nat_t_error_code; d->nat_t_error_code = nat_t_error_code;
@ -1397,7 +1397,7 @@ UINT WinConnectDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *
} }
// TCP connection with showing the UI // TCP connection with showing the UI
SOCK *WinConnectEx3(HWND hWnd, char *server, UINT port, UINT timeout, UINT icon_id, wchar_t *caption, wchar_t *info, UINT *nat_t_error_code, char *nat_t_svc_name, bool try_start_ssl) SOCK *WinConnectEx3(HWND hWnd, char *server, UINT port, UINT timeout, UINT icon_id, wchar_t *caption, wchar_t *info, UINT *nat_t_error_code, char *nat_t_svc_name, bool try_start_ssl, char *hint_str)
{ {
wchar_t tmp[MAX_SIZE]; wchar_t tmp[MAX_SIZE];
wchar_t tmp2[MAX_SIZE]; wchar_t tmp2[MAX_SIZE];
@ -1440,6 +1440,7 @@ SOCK *WinConnectEx3(HWND hWnd, char *server, UINT port, UINT timeout, UINT icon_
d.timeout = timeout; d.timeout = timeout;
d.hostname = server; d.hostname = server;
d.port = port; d.port = port;
d.hint_str = hint_str;
StrCpy(d.nat_t_svc_name, sizeof(d.nat_t_svc_name), nat_t_svc_name); StrCpy(d.nat_t_svc_name, sizeof(d.nat_t_svc_name), nat_t_svc_name);
Dialog(hWnd, D_CONNECT, WinConnectDlgProc, &d); Dialog(hWnd, D_CONNECT, WinConnectDlgProc, &d);

View File

@ -331,6 +331,7 @@ typedef struct WINCONNECT_DLG_DATA
char nat_t_svc_name[MAX_SIZE]; char nat_t_svc_name[MAX_SIZE];
UINT nat_t_error_code; UINT nat_t_error_code;
bool try_start_ssl; bool try_start_ssl;
char *hint_str;
} WINCONNECT_DLG_DATA; } WINCONNECT_DLG_DATA;
HBITMAP ResizeBitmap(HBITMAP hSrc, UINT src_x, UINT src_y, UINT dst_x, UINT dst_y); HBITMAP ResizeBitmap(HBITMAP hSrc, UINT src_x, UINT src_y, UINT dst_x, UINT dst_y);
@ -693,7 +694,7 @@ HFONT GetMeiryoFont();
HFONT GetMeiryoFontEx(UINT font_size); HFONT GetMeiryoFontEx(UINT font_size);
HFONT GetMeiryoFontEx2(UINT font_size, bool bold); HFONT GetMeiryoFontEx2(UINT font_size, bool bold);
bool ShowWindowsNetworkConnectionDialog(); bool ShowWindowsNetworkConnectionDialog();
SOCK *WinConnectEx3(HWND hWnd, char *server, UINT port, UINT timeout, UINT icon_id, wchar_t *caption, wchar_t *info, UINT *nat_t_error_code, char *nat_t_svc_name, bool try_start_ssl); SOCK *WinConnectEx3(HWND hWnd, char *server, UINT port, UINT timeout, UINT icon_id, wchar_t *caption, wchar_t *info, UINT *nat_t_error_code, char *nat_t_svc_name, bool try_start_ssl, char *hint_str);
UINT WinConnectDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param); UINT WinConnectDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);
void WinConnectDlgThread(THREAD *thread, void *param); void WinConnectDlgThread(THREAD *thread, void *param);
void NicInfo(UI_NICINFO *info); void NicInfo(UI_NICINFO *info);

View File

@ -524,7 +524,7 @@ SOCK *WpcSockConnectEx(WPC_CONNECT *param, UINT *error_code, UINT timeout, bool
if (param->ProxyType == PROXY_DIRECT) if (param->ProxyType == PROXY_DIRECT)
{ {
sock = TcpConnectEx3(param->HostName, param->Port, timeout, cancel, NULL, true, NULL, false, NULL); sock = TcpConnectEx3(param->HostName, param->Port, timeout, cancel, NULL, true, NULL, false, NULL, NULL);
*error_code = (sock != NULL ? ERR_NO_ERROR : ERR_CONNECT_FAILED); *error_code = (sock != NULL ? ERR_NO_ERROR : ERR_CONNECT_FAILED);
return sock; return sock;
} }
@ -711,7 +711,7 @@ BUF *HttpRequestEx3(URL_DATA *data, INTERNET_SETTING *setting,
else else
{ {
// If the connection is not SSL via HTTP Proxy // If the connection is not SSL via HTTP Proxy
s = TcpConnectEx3(con.ProxyHostName, con.ProxyPort, timeout_connect, cancel, NULL, true, NULL, false, NULL); s = TcpConnectEx3(con.ProxyHostName, con.ProxyPort, timeout_connect, cancel, NULL, true, NULL, false, NULL, NULL);
if (s == NULL) if (s == NULL)
{ {
*error_code = ERR_PROXY_CONNECT_FAILED; *error_code = ERR_PROXY_CONNECT_FAILED;

View File

@ -13979,7 +13979,7 @@ void ConnectThreadForIPv4(THREAD *thread, void *param)
Zero(&p4, sizeof(p4)); Zero(&p4, sizeof(p4));
// p1: TCP // p1: TCP
StrCpy(p1.Hostname, sizeof(p1.Hostname), p->Hostname_Original); StrCpy(p1.Hostname, sizeof(p1.Hostname), p->Hostname);
Copy(&p1.Ip, ip, sizeof(IP)); Copy(&p1.Ip, ip, sizeof(IP));
p1.Port = p->Port; p1.Port = p->Port;
p1.Timeout = p->Timeout; p1.Timeout = p->Timeout;
@ -13989,7 +13989,7 @@ void ConnectThreadForIPv4(THREAD *thread, void *param)
p1.CancelLock = NewLock(); p1.CancelLock = NewLock();
// p2: NAT-T // p2: NAT-T
StrCpy(p2.Hostname, sizeof(p2.Hostname), p->Hostname_Original); StrCpy(p2.Hostname, sizeof(p2.Hostname), p->Hostname);
Copy(&p2.Ip, ip, sizeof(IP)); Copy(&p2.Ip, ip, sizeof(IP));
p2.Port = p->Port; p2.Port = p->Port;
p2.Timeout = p->Timeout; p2.Timeout = p->Timeout;
@ -14002,7 +14002,7 @@ void ConnectThreadForIPv4(THREAD *thread, void *param)
p2.Delay = 30; // Delay by 30ms p2.Delay = 30; // Delay by 30ms
// p3: over ICMP // p3: over ICMP
StrCpy(p3.Hostname, sizeof(p3.Hostname), p->Hostname_Original); StrCpy(p3.Hostname, sizeof(p3.Hostname), p->Hostname);
Copy(&p3.Ip, ip, sizeof(IP)); Copy(&p3.Ip, ip, sizeof(IP));
p3.Port = p->Port; p3.Port = p->Port;
p3.Timeout = p->Timeout; p3.Timeout = p->Timeout;
@ -14013,7 +14013,7 @@ void ConnectThreadForIPv4(THREAD *thread, void *param)
p3.Delay = 200; // Delay by 200ms p3.Delay = 200; // Delay by 200ms
// p4: over DNS // p4: over DNS
StrCpy(p4.Hostname, sizeof(p4.Hostname), p->Hostname_Original); StrCpy(p4.Hostname, sizeof(p4.Hostname), p->Hostname);
Copy(&p4.Ip, ip, sizeof(IP)); Copy(&p4.Ip, ip, sizeof(IP));
p4.Port = p->Port; p4.Port = p->Port;
p4.Timeout = p->Timeout; p4.Timeout = p->Timeout;
@ -14221,7 +14221,7 @@ void ConnectThreadForIPv4(THREAD *thread, void *param)
if (s != INVALID_SOCKET) if (s != INVALID_SOCKET)
{ {
p->Sock = CreateTCPSock(s, false, &current_ip, p->No_Get_Hostname, p->Hostname_Original); p->Sock = CreateTCPSock(s, false, &current_ip, p->No_Get_Hostname, p->Hostname);
break; break;
} }
} }
@ -14308,7 +14308,7 @@ void ConnectThreadForIPv6(THREAD *thread, void *param)
if (s != INVALID_SOCKET) if (s != INVALID_SOCKET)
{ {
p->Sock = CreateTCPSock(s, true, &current_ip, p->No_Get_Hostname, p->Hostname_Original); p->Sock = CreateTCPSock(s, true, &current_ip, p->No_Get_Hostname, p->Hostname);
break; break;
} }
} }
@ -14407,14 +14407,12 @@ SOCK *ConnectEx2(char *hostname, UINT port, UINT timeout, bool *cancel_flag)
} }
SOCK *ConnectEx3(char *hostname, UINT port, UINT timeout, bool *cancel_flag, char *nat_t_svc_name, UINT *nat_t_error_code, bool try_start_ssl, bool no_get_hostname) SOCK *ConnectEx3(char *hostname, UINT port, UINT timeout, bool *cancel_flag, char *nat_t_svc_name, UINT *nat_t_error_code, bool try_start_ssl, bool no_get_hostname)
{ {
return ConnectEx4(hostname, port, timeout, cancel_flag, nat_t_svc_name, nat_t_error_code, try_start_ssl, no_get_hostname, NULL); return ConnectEx4(hostname, port, timeout, cancel_flag, nat_t_svc_name, nat_t_error_code, try_start_ssl, no_get_hostname, NULL, NULL);
} }
SOCK *ConnectEx4(char *hostname, UINT port, UINT timeout, bool *cancel_flag, char *nat_t_svc_name, UINT *nat_t_error_code, bool try_start_ssl, bool no_get_hostname, IP *ret_ip) SOCK *ConnectEx4(char *hostname, UINT port, UINT timeout, bool *cancel_flag, char *nat_t_svc_name, UINT *nat_t_error_code, bool try_start_ssl, bool no_get_hostname, char *hint_str, IP *ret_ip)
{ {
bool dummy = false; bool dummy = false;
bool use_natt = false; bool use_natt = false;
char hostname_original[MAX_SIZE];
char hint_str[MAX_SIZE];
bool force_use_natt = false; bool force_use_natt = false;
UINT dummy_int = 0; UINT dummy_int = 0;
IP dummy_ret_ip; IP dummy_ret_ip;
@ -14442,33 +14440,15 @@ SOCK *ConnectEx4(char *hostname, UINT port, UINT timeout, bool *cancel_flag, cha
ret_ip = &dummy_ret_ip; ret_ip = &dummy_ret_ip;
} }
Zero(hint_str, sizeof(hint_str));
StrCpy(hostname_original, sizeof(hostname_original), hostname);
use_natt = (IsEmptyStr(nat_t_svc_name) ? false : true); use_natt = (IsEmptyStr(nat_t_svc_name) ? false : true);
if (use_natt) if (use_natt)
{ {
// In case of using NAT-T, split host name if the '/' is included in the host name if (IsEmptyStr(hint_str) == false)
UINT i = SearchStrEx(hostname, "/", 0, false);
if (i == INFINITE)
{ {
// Not included
StrCpy(hostname_original, sizeof(hostname_original), hostname);
}
else
{
// Included
StrCpy(hostname_original, sizeof(hostname_original), hostname);
hostname_original[i] = 0;
// Force to use the NAT-T // Force to use the NAT-T
force_use_natt = true; force_use_natt = true;
// Copy the hint string
StrCpy(hint_str, sizeof(hint_str), hostname + i + 1);
if (StrCmpi(hint_str, "tcp") == 0 || StrCmpi(hint_str, "disable") == 0 if (StrCmpi(hint_str, "tcp") == 0 || StrCmpi(hint_str, "disable") == 0
|| StrCmpi(hint_str, "disabled") == 0 || StrCmpi(hint_str, "disabled") == 0
|| StrCmpi(hint_str, "no") == 0 || StrCmpi(hint_str, "none") == 0) || StrCmpi(hint_str, "no") == 0 || StrCmpi(hint_str, "none") == 0)
@ -14479,10 +14459,6 @@ SOCK *ConnectEx4(char *hostname, UINT port, UINT timeout, bool *cancel_flag, cha
} }
} }
} }
else
{
StrCpy(hostname_original, sizeof(hostname_original), hostname);
}
LIST *iplist_v6 = NULL; LIST *iplist_v6 = NULL;
LIST *iplist_v4 = NULL; LIST *iplist_v4 = NULL;
@ -14506,7 +14482,7 @@ SOCK *ConnectEx4(char *hostname, UINT port, UINT timeout, bool *cancel_flag, cha
else else
{ {
// Forward resolution // Forward resolution
if (DnsResolveEx(&iplist_v6, &iplist_v4, hostname_original, 0, cancel_flag) == false) if (DnsResolveEx(&iplist_v6, &iplist_v4, hostname, 0, cancel_flag) == false)
{ {
return NULL; return NULL;
} }
@ -14532,7 +14508,6 @@ SOCK *ConnectEx4(char *hostname, UINT port, UINT timeout, bool *cancel_flag, cha
p6.Port = port; p6.Port = port;
p6.Timeout = timeout; p6.Timeout = timeout;
StrCpy(p6.Hostname, sizeof(p6.Hostname), hostname); StrCpy(p6.Hostname, sizeof(p6.Hostname), hostname);
StrCpy(p6.Hostname_Original, sizeof(p6.Hostname_Original), hostname_original);
p6.No_Get_Hostname = no_get_hostname; p6.No_Get_Hostname = no_get_hostname;
p6.CancelFlag = &cancel_flag2; p6.CancelFlag = &cancel_flag2;
p6.NoDelayFlag = &no_delay_flag; p6.NoDelayFlag = &no_delay_flag;
@ -14551,7 +14526,6 @@ SOCK *ConnectEx4(char *hostname, UINT port, UINT timeout, bool *cancel_flag, cha
p4.Port = port; p4.Port = port;
p4.Timeout = timeout; p4.Timeout = timeout;
StrCpy(p4.Hostname, sizeof(p4.Hostname), hostname); StrCpy(p4.Hostname, sizeof(p4.Hostname), hostname);
StrCpy(p4.Hostname_Original, sizeof(p4.Hostname_Original), hostname_original);
StrCpy(p4.HintStr, sizeof(p4.HintStr), hint_str); StrCpy(p4.HintStr, sizeof(p4.HintStr), hint_str);
p4.No_Get_Hostname = no_get_hostname; p4.No_Get_Hostname = no_get_hostname;
p4.CancelFlag = &cancel_flag2; p4.CancelFlag = &cancel_flag2;

View File

@ -802,7 +802,6 @@ struct CONNECT_SERIAL_PARAM
UINT Port; UINT Port;
UINT Timeout; UINT Timeout;
char Hostname[MAX_SIZE]; char Hostname[MAX_SIZE];
char Hostname_Original[MAX_SIZE];
char HintStr[MAX_SIZE]; char HintStr[MAX_SIZE];
bool No_Get_Hostname; bool No_Get_Hostname;
bool *CancelFlag; bool *CancelFlag;
@ -1084,7 +1083,7 @@ SOCK *Connect(char *hostname, UINT port);
SOCK *ConnectEx(char *hostname, UINT port, UINT timeout); SOCK *ConnectEx(char *hostname, UINT port, UINT timeout);
SOCK *ConnectEx2(char *hostname, UINT port, UINT timeout, bool *cancel_flag); SOCK *ConnectEx2(char *hostname, UINT port, UINT timeout, bool *cancel_flag);
SOCK *ConnectEx3(char *hostname, UINT port, UINT timeout, bool *cancel_flag, char *nat_t_svc_name, UINT *nat_t_error_code, bool try_start_ssl, bool no_get_hostname); SOCK *ConnectEx3(char *hostname, UINT port, UINT timeout, bool *cancel_flag, char *nat_t_svc_name, UINT *nat_t_error_code, bool try_start_ssl, bool no_get_hostname);
SOCK *ConnectEx4(char *hostname, UINT port, UINT timeout, bool *cancel_flag, char *nat_t_svc_name, UINT *nat_t_error_code, bool try_start_ssl, bool no_get_hostname, IP *ret_ip); SOCK *ConnectEx4(char *hostname, UINT port, UINT timeout, bool *cancel_flag, char *nat_t_svc_name, UINT *nat_t_error_code, bool try_start_ssl, bool no_get_hostname, char *hint_str, IP *ret_ip);
SOCKET ConnectTimeoutIPv4(IP *ip, UINT port, UINT timeout, bool *cancel_flag); SOCKET ConnectTimeoutIPv4(IP *ip, UINT port, UINT timeout, bool *cancel_flag);
bool SetSocketBufferSize(SOCKET s, bool send, UINT size); bool SetSocketBufferSize(SOCKET s, bool send, UINT size);
UINT SetSocketBufferSizeWithBestEffort(SOCKET s, bool send, UINT size); UINT SetSocketBufferSizeWithBestEffort(SOCKET s, bool send, UINT size);

View File

@ -12,11 +12,11 @@ SOCK *Internal_ProxyTcpConnect(PROXY_PARAM_IN *param, volatile bool *cancel_flag
#ifdef OS_WIN32 #ifdef OS_WIN32
if (param->Hwnd != NULL) if (param->Hwnd != NULL)
{ {
return WinConnectEx3((HWND)param->Hwnd, param->Hostname, param->Port, param->Timeout, 0, NULL, NULL, NULL, NULL, false); return WinConnectEx3((HWND)param->Hwnd, param->Hostname, param->Port, param->Timeout, 0, NULL, NULL, NULL, NULL, false, NULL);
} }
#endif #endif
return ConnectEx4(param->Hostname, param->Port, param->Timeout, (bool *)cancel_flag, NULL, NULL, false, true, resolved_ip); return ConnectEx4(param->Hostname, param->Port, param->Timeout, (bool *)cancel_flag, NULL, NULL, false, true, NULL, resolved_ip);
} }
// Connect to an HTTP proxy // Connect to an HTTP proxy