I'm trying to turn off the socket option IPV6_V6ONLY.
int no = 0;
setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&no, sizeof(no));
Why does the above fail with errno 22 (EINVAL)?
This is on OS X. It also doesn't work when no
is 1. Setting other socket options works, for example
int yes = 1;
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *)&yes, sizeof(yes));
It looks like *BSD derived OS doesn't allow set nor clear this option. I see the same behavior on FreeBSD 8.X. The socket is 100% AF_INET6.
What did your call to socket()
look like for fd
? If the first parameter, the protocol family, wasn't AF_INET6
(or PF_INET6
), then this call isn't applicable.
Make sure you are calling bind()
after setsockopt()
for this option.
Another thing that can cause this to fail is doing it too late, it seems that on Linux at least it must be done before the socket is bound.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With