moonbridge

changeset 329:fb8f86d3703e

Make moonbridge_io.tcplisten(nil, port) accept both IPv6 and IPv4 connections independently of operating system setting; if first argument is non-nil and resolves to an IPv6 address, never accept IPv4 connections
author jbe
date Mon Jan 04 04:09:35 2021 +0100 (6 months ago)
parents 86121074cd91
children 73303a85266f
files moonbridge_io.c
line diff
     1.1 --- a/moonbridge_io.c	Sun Dec 20 20:59:40 2020 +0100
     1.2 +++ b/moonbridge_io.c	Mon Jan 04 04:09:35 2021 +0100
     1.3 @@ -1345,6 +1345,17 @@
     1.4        return 2;
     1.5      }
     1.6    }
     1.7 +  if (addrinfo->ai_family == AF_INET6) {
     1.8 +    const int ipv6onlyval = (host != NULL) ? 1 : 0;
     1.9 +    if (setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, &ipv6onlyval, sizeof(ipv6onlyval))) {
    1.10 +      moonbr_io_prepare_errmsg();
    1.11 +      freeaddrinfo(res);
    1.12 +      close(sock);
    1.13 +      lua_pushnil(L);
    1.14 +      lua_pushfstring(L, "Error while setting IPV6_V6ONLY with setsockopt: %s", errmsg);
    1.15 +      return 2;
    1.16 +    }
    1.17 +  }
    1.18    if (bind(sock, addrinfo->ai_addr, addrinfo->ai_addrlen)) {
    1.19      moonbr_io_prepare_errmsg();
    1.20      freeaddrinfo(res);

Impressum / About Us