From 5074246462deb6dee5e1b786df2a3eac940043fb Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Sun, 16 Jul 2023 14:04:45 +0000 Subject: [PATCH] Listening on IPv6 + IPv4 by default. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4346 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- core/httpd.js | 2 +- src/socket.js.c | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/core/httpd.js b/core/httpd.js index 84529b66..1bb0070c 100644 --- a/core/httpd.js +++ b/core/httpd.js @@ -552,7 +552,7 @@ function handleConnection(client) { } let kBacklog = 8; -let kHost = "0.0.0.0" +let kHost = '::'; let socket = new Socket(); socket.bind(kHost, tildefriends.http_port).then(function(port) { diff --git a/src/socket.js.c b/src/socket.js.c index f11b132b..e6d9adf7 100644 --- a/src/socket.js.c +++ b/src/socket.js.c @@ -413,8 +413,9 @@ JSValue _socket_bind(JSContext* context, JSValueConst this_val, int argc, JSValu socket_resolve_data_t* data = tf_malloc(sizeof(socket_resolve_data_t)); memset(data, 0, sizeof(*data)); - struct addrinfo hints = { - .ai_family = PF_INET, + struct addrinfo hints = + { + .ai_family = AF_UNSPEC, .ai_socktype = SOCK_STREAM, .ai_protocol = IPPROTO_TCP, .ai_flags = 0, @@ -602,7 +603,7 @@ JSValue _socket_accept(JSContext* context, JSValueConst this_val, int argc, JSVa int status = uv_accept((uv_stream_t*)&socket->_socket, (uv_stream_t*)&client->_socket); if (status == 0) { - struct sockaddr_in name = { 0 }; + struct sockaddr_storage name = { 0 }; int namelen = (int)sizeof(name); if (uv_tcp_getpeername(&client->_socket, (struct sockaddr*)&name, &namelen) == 0) {