mirror of
https://github.com/SoftEtherVPN/SoftEtherVPN.git
synced 2024-12-26 01:59:53 +03:00
Merge pull request #1901 from hiura2023/master
Bind outgoing connection to a specific IP address (avoid illegal access)
This commit is contained in:
commit
6833a7a11d
@ -13689,6 +13689,14 @@ char *PrintError(int ErrorCode)
|
||||
Message = "Cannot assign requested address.";
|
||||
break;
|
||||
|
||||
case WSAEISCONN:
|
||||
Message = "Socket is already connected."; // Added on AUG.10, 2023
|
||||
break;
|
||||
|
||||
case WSAEINVAL:
|
||||
Message = "Invalid argument."; // Added on AUG.10, 2023
|
||||
break;
|
||||
|
||||
default:
|
||||
Message = "";
|
||||
break;
|
||||
@ -13914,16 +13922,20 @@ SOCKET BindConnectTimeoutIPv4(IP* localIP, UINT localport, IP* ip, UINT port, UI
|
||||
if (s != INVALID_SOCKET) {
|
||||
int ier;
|
||||
IP tmpIP;
|
||||
IP *tmpIP2;
|
||||
|
||||
if (localIP == BIND_LOCALIP_NULL) {
|
||||
StrToIP(&tmpIP, "0.0.0.0"); // A NULL address for the argument "localIP" is treated as if "0::0" in IPV4 was specified.
|
||||
localIP = &tmpIP;
|
||||
StrToIP(&tmpIP, "0.0.0.0"); // A NULL address for the argument "localIP" is treated as if "0.0.0.0" in IPV4 was specified.
|
||||
tmpIP2 = &tmpIP;
|
||||
}
|
||||
else {
|
||||
tmpIP2 = localIP;
|
||||
}
|
||||
|
||||
if ((IsZeroIP(localIP) == false) || (localport != 0)) {
|
||||
if ((IsZeroIP(tmpIP2) == false) || (localport != 0)) {
|
||||
|
||||
// Bind the socket
|
||||
if (bind_sock(s, localIP, localport) != 0) {
|
||||
if (bind_sock(s, tmpIP2, localport) != 0) {
|
||||
#ifdef OS_WIN32
|
||||
ier = WSAGetLastError();
|
||||
Debug("IPv4 bind() failed with error: %d %s\n", ier, PrintError(ier));
|
||||
@ -14643,16 +14655,20 @@ void BindConnectThreadForIPv6(THREAD* thread, void* param)
|
||||
if (s != INVALID_SOCKET){
|
||||
int ier;
|
||||
IP tmpIP;
|
||||
IP *tmpIP2;
|
||||
|
||||
if (p->LocalIP == BIND_LOCALIP_NULL) {
|
||||
StrToIP(&tmpIP, "0::0"); // A NULL address for the argument "p->LocalIP" is treated as if "0::0" in IPV6 was specified.
|
||||
p->LocalIP = &tmpIP;
|
||||
tmpIP2 = &tmpIP;
|
||||
}
|
||||
else {
|
||||
tmpIP2 = p->LocalIP;
|
||||
}
|
||||
|
||||
if ((IsZeroIP(p->LocalIP) == false) || (p->LocalPort != 0)){
|
||||
if ((IsZeroIP(tmpIP2) == false) || (p->LocalPort != 0)){
|
||||
|
||||
// Bind the socket
|
||||
if (bind_sock(s, p->LocalIP, p->LocalPort) != 0) {
|
||||
if (bind_sock(s, tmpIP2, p->LocalPort) != 0) {
|
||||
#ifdef OS_WIN32
|
||||
ier = WSAGetLastError();
|
||||
Debug("IPv6 bind() failed with error: %d %s\n", ier, PrintError(ier));
|
||||
|
Loading…
Reference in New Issue
Block a user