diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2022-08-30 11:57:30 +0200 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2022-08-30 11:57:30 +0200 |
commit | c7a2516f5b39046d113a5bb80b64500faadcef8a (patch) | |
tree | 4853bea8fa804151ac004a127984342558cdc7cd | |
parent | update command names (diff) | |
download | cimple-c7a2516f5b39046d113a5bb80b64500faadcef8a.tar.gz cimple-c7a2516f5b39046d113a5bb80b64500faadcef8a.zip |
net: bind to IPv6
This makes sure we use the dual-stack feature to support both IPv4 and
IPv6.
Diffstat (limited to '')
-rw-r--r-- | src/net.c | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -17,7 +17,7 @@ int net_bind(const char *port) int socket_fd, ret = 0; memset(&hints, 0, sizeof(hints)); - hints.ai_family = AF_UNSPEC; + hints.ai_family = AF_INET6; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_PASSIVE; @@ -35,8 +35,16 @@ int net_bind(const char *port) } static const int yes = 1; + static const int no = 0; + + if (it->ai_family == AF_INET6) { + if (setsockopt(socket_fd, IPPROTO_IPV6, IPV6_V6ONLY, &no, sizeof(no)) < 0) { + print_errno("setsockopt"); + goto close_socket; + } + } - if (setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) == -1) { + if (setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0) { print_errno("setsockopt"); goto close_socket; } |