From: Miroslav Lichvar Date: Wed, 30 Apr 2025 09:33:38 +0000 (+0200) Subject: socket: open IPv6 socket by default if IPv4 is disabled X-Git-Tag: 4.7-pre1~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ec57de02c7ef512438f5a01ce7805a21388aa244;p=thirdparty%2Fchrony.git socket: open IPv6 socket by default if IPv4 is disabled When no remote and local address is specified, and IPv4 is disabled by the -6 option, open an IPv6 socket. This is used by the Linux-specific timestamping configuration and socket option checking. It enables operation on a system that has no support for IPv4 sockets. --- diff --git a/socket.c b/socket.c index 78e54faf..d08b8657 100644 --- a/socket.c +++ b/socket.c @@ -212,13 +212,25 @@ get_reusable_socket(int type, IPSockAddr *spec) /* ================================================== */ +static int +get_default_inet_domain(void) +{ +#ifdef FEAT_IPV6 + if (!ip4_enabled && ip6_enabled) + return AF_INET6; +#endif + return AF_INET; +} + +/* ================================================== */ + #if defined(SOCK_CLOEXEC) || defined(SOCK_NONBLOCK) static int check_socket_flag(int sock_flag, int fd_flag, int fs_flag) { int sock_fd, fd_flags, fs_flags; - sock_fd = socket(AF_INET, SOCK_DGRAM | sock_flag, 0); + sock_fd = socket(get_default_inet_domain(), SOCK_DGRAM | sock_flag, 0); if (sock_fd < 0) return 0; @@ -526,7 +538,7 @@ open_ip_socket(IPSockAddr *remote_addr, IPSockAddr *local_addr, const char *ifac else if (remote_addr) family = remote_addr->ip_addr.family; else - family = IPADDR_INET4; + family = !ip4_enabled && ip6_enabled ? IPADDR_INET6 : IPADDR_INET4; switch (family) { case IPADDR_INET4: