Browse Source

Avoid udp server reuse port

Nick Peng 6 years ago
parent
commit
dcede4ffaa
1 changed files with 6 additions and 4 deletions
  1. 6 4
      src/dns_server.c

+ 6 - 4
src/dns_server.c

@@ -2318,13 +2318,15 @@ static int _dns_create_socket(const char *host_ip, int type)
 		goto errout;
 	}
 
-	if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) != 0) {
-		tlog(TLOG_ERROR, "set socket opt failed.");
-		goto errout;
+	if (type == SOCK_STREAM) {
+		if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) != 0) {
+			tlog(TLOG_ERROR, "set socket opt failed.");
+			goto errout;
+		}
 	}
 
 	if (bind(fd, gai->ai_addr, gai->ai_addrlen) != 0) {
-		tlog(TLOG_ERROR, "bind failed.\n");
+		tlog(TLOG_ERROR, "bind service failed, %s\n", strerror(errno));
 		goto errout;
 	}