Can't turn off socket option IPV6_V6ONLY

10,429

Solution 1

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.

Solution 2

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.

Solution 3

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

Share:
10,429

Related videos on Youtube

jlstrecker
Author by

jlstrecker

Updated on June 04, 2022

Comments

  • jlstrecker
    jlstrecker almost 2 years

    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)); 
    
  • X-Istence
    X-Istence over 11 years
    FreeBSD since 5.x has disabled IPv4 mapped on IPv6 addresses and thus unless you turn that feature back on by setting the required configuration flag in rc.conf you won't be able to use it.

Related