From 14c2e4b64b2bd6189d06d858bf4898d3a9f5a6e4 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Mon, 13 May 2024 19:49:40 +0200 Subject: socket: Create an IPv4 compatible IPv6 socket when NULL is passed to socket_create --- src/socket.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/socket.c b/src/socket.c index d4dedd1..3375e5b 100644 --- a/src/socket.c +++ b/src/socket.c @@ -463,6 +463,7 @@ int socket_create(const char* addr, uint16_t port) { int sfd = -1; int yes = 1; + int no = 0; struct addrinfo hints; struct addrinfo *result, *rp; char portstr[8]; @@ -514,7 +515,7 @@ int socket_create(const char* addr, uint16_t port) #if defined(AF_INET6) && defined(IPV6_V6ONLY) if (rp->ai_family == AF_INET6) { - if (setsockopt(sfd, IPPROTO_IPV6, IPV6_V6ONLY, (void*)&yes, sizeof(int)) == -1) { + if (setsockopt(sfd, IPPROTO_IPV6, IPV6_V6ONLY, (addr) ? (void*)&yes : (void*)&no, sizeof(int)) == -1) { perror("setsockopt() IPV6_V6ONLY"); } } -- cgit v1.1-32-gdbae