Unable to disable socket option IPV6_V6ONLY

I am trying to disable the IPV6_V6ONLY socket option .

int no = 0;     
setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&no, sizeof(no)); 

Why did this fail with error 22 (EINVAL)?

This applies to OS X. It also does not work when it nois 1. Setting other socket parameters works, for example

int yes = 1;
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *)&yes, sizeof(yes)); 
+5
source share
4 answers

What did your call look like socket()for fd? If the first parameter, the protocol family, was not AF_INET6(or PF_INET6), then this call is not applicable.

+4
source

, * BSD . FreeBSD 8.X. 100% AF_INET6.

+5

Make sure you call bind()after setsockopt()for this option.

+3
source

Another thing that can lead to failure is too late, it seems that on Linux, at least, this should be done before the socket is bound.

0
source

All Articles