浏览代码

Avoid udp server reuse port

Nick Peng 6 年之前
父节点
当前提交
dcede4ffaa
共有 1 个文件被更改,包括 6 次插入4 次删除
  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;
 		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) {
 	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;
 		goto errout;
 	}
 	}