Skip to content

Commit

Permalink
socket: Create an IPv4 compatible IPv6 socket when NULL is passed to …
Browse files Browse the repository at this point in the history
…socket_create
  • Loading branch information
nikias committed May 13, 2024
1 parent bbf0c65 commit 14c2e4b
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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");
}
}
Expand Down

0 comments on commit 14c2e4b

Please sign in to comment.