fix bugs with when ss-server bind_address enabled (#725)

* SO_REUSEADDR for remote sockfd

avoid  ERROR: bind_to_address: Address already in use

* set addr->sin_port to be 0
This commit is contained in:
tim-le
2016-07-14 18:08:10 -05:00
committed by Max Lv
parent 50f63d345d
commit ad17d91b42
2 changed files with 2 additions and 0 deletions
+1
View File
@@ -91,6 +91,7 @@ int bind_to_address(int socket_fd, const char *host)
if (host != NULL) {
struct cork_ip ip;
struct sockaddr_storage storage;
memset(&storage, 0, sizeof(storage));
if (cork_ip_init(&ip, host) != -1) {
if (ip.version == 4) {
struct sockaddr_in *addr = (struct sockaddr_in *)&storage;
+1
View File
@@ -415,6 +415,7 @@ static remote_t *connect_to_remote(struct addrinfo *res,
#ifdef SO_NOSIGPIPE
setsockopt(sockfd, SOL_SOCKET, SO_NOSIGPIPE, &opt, sizeof(opt));
#endif
setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
remote_t *remote = new_remote(sockfd);