Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IPv6 支持有误 #15

Open
wsm25 opened this issue Apr 15, 2024 · 3 comments
Open

IPv6 支持有误 #15

wsm25 opened this issue Apr 15, 2024 · 3 comments

Comments

@wsm25
Copy link

wsm25 commented Apr 15, 2024

表现为 IPv6 端口并未被绑定,无法接收任何来自 IPv6 的请求。

应该是这里的问题:

let addrs: &[SocketAddr] = &[
SocketAddr::new(Ipv4Addr::UNSPECIFIED.into(), port),
SocketAddr::new(Ipv6Addr::UNSPECIFIED.into(), port),
];

let listener: Server = TcpListener::bind(addrs).await?.into();

按照 文档 的说法

If addr yields multiple addresses, bind will be attempted with each of the addresses until one succeeds and returns the listener. If none of the addresses succeed in creating a listener, the error returned from the last attempt (the last address) is returned.

因此事实上只绑定了 v4 端口而并未绑定 v6 端口。

@wsm25
Copy link
Author

wsm25 commented Apr 15, 2024

如果不考虑 Windows 兼容性,只要 bind 一个 Ipv6Addr::UNSPECIFIED 就够了,它会同时接收 v4 请求(Linux 和 Termux 上已测试)。

@XiaoTong6666
Copy link

XiaoTong6666 commented May 29, 2024

感谢,按照您的思路我注释掉了绑定ipv4的代码,之后v6和v4的端口都能使用了docker!启动!

@CsVeryLoveXieWenLi
Copy link

我刚想提交PR和IS,刚好看到有人说了,确实是这样的,或者新增命令行参数判断一下也行。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants