From b236115f1ab1988ee4b814d65271aa88b18f5af3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Sat, 14 Aug 2021 12:58:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3port?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server.c b/server.c index 6a593f2..c646a82 100644 --- a/server.c +++ b/server.c @@ -497,12 +497,13 @@ int accept_client(int server_sock) { while(1) { int client_sock = accept(server_sock, (struct sockaddr *)&client_name, &client_name_len); if(client_sock == -1) continue; - uint16_t port = ntohs(client_name.sin_port); #ifdef LISTEN_ON_IPV6 + uint16_t port = ntohs(client_name.sin6_port); struct in6_addr in = client_name.sin6_addr; char str[INET6_ADDRSTRLEN]; // 46 inet_ntop(AF_INET6, &in, str, sizeof(str)); #else + uint16_t port = ntohs(client_name.sin_port); struct in_addr in = client_name.sin_addr; char str[INET_ADDRSTRLEN]; // 16 inet_ntop(AF_INET, &in, str, sizeof(str));