Browse Source

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
pull/727/head
tim-le 8 years ago
committed by Max Lv
parent
commit
ad17d91b42
2 changed files with 2 additions and 0 deletions
  1. 1
      src/netutils.c
  2. 1
      src/server.c

1
src/netutils.c

@ -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
src/server.c

@ -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);

Loading…
Cancel
Save