bind address for connect

This commit is contained in:
Vladimir Goncharov
2024-08-22 15:49:50 +07:00
parent a863c35ce3
commit c793ec8e1c
3 changed files with 51 additions and 8 deletions

View File

@@ -390,6 +390,27 @@ static int connect_remote(const struct sockaddr *remote_addr, bool bApplyConnect
VPRINT("Not setting MSS. Port %u is out of MSS port range.",port)
}
}
// if no bind address specified - address family will be 0 in params_connect_bindX
if(remote_addr->sa_family == params.connect_bind4.sin_family)
{
if (bind(remote_fd, (struct sockaddr *)&params.connect_bind4, sizeof(struct sockaddr_in)) == -1)
{
perror("bind on connect");
close(remote_fd);
return -1;
}
}
else if(remote_addr->sa_family == params.connect_bind6.sin6_family)
{
if (bind(remote_fd, (struct sockaddr *)&params.connect_bind6, sizeof(struct sockaddr_in6)) == -1)
{
perror("bind on connect");
close(remote_fd);
return -1;
}
}
if (connect(remote_fd, remote_addr, remote_addr->sa_family == AF_INET ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6)) < 0)
{
if(errno != EINPROGRESS)