无法关闭套接字选项 IPV6_V6ONLY
我正在尝试关闭套接字选项 IPV6_V6ONLY。
int no = 0;
setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&no, sizeof(no));
为什么上面的操作会失败并显示 errno 22 (EINVAL)?
这是在 OS X 上。当 no
为 1 时它也不起作用。设置其他套接字选项也有效,例如例子
int yes = 1;
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *)&yes, sizeof(yes));
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));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
看起来 *BSD 派生操作系统不允许设置或清除此选项。
我在 FreeBSD 8.X 上看到了同样的行为。套接字为 100% AF_INET6。
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.
对于
fd
,您对socket()
的调用是什么样的?如果第一个参数(协议族)不是AF_INET6
(或PF_INET6
),则此调用不适用。What did your call to
socket()
look like forfd
? If the first parameter, the protocol family, wasn'tAF_INET6
(orPF_INET6
), then this call isn't applicable.确保您在
setsockopt()
之后调用此选项。Make sure you are calling
bind()
aftersetsockopt()
for this option.另一件可能导致失败的事情是做得太晚了,似乎在 Linux 上至少必须在绑定套接字之前完成。
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.