TCP simultaneous open and self connect prevention(TCP 同时打开和自连接预防)
问题描述
TCP 标准具有同时打开"的特性.
TCP standard has "simultaneous open" feature.
该功能的含义,客户端尝试连接本地端口,当端口来自临时范围,偶尔可以连接到自身(参见这里).
The implication of the feature, client trying to connect to local port, when the port is from ephemeral range, can occasionally connect to itself (see here).
所以客户端认为它连接到服务器,而它实际上连接到自己.另一方面,服务器无法打开它的服务器端口,因为它被客户端占用/窃取了.
So client think it's connected to server, while it actually connected to itself. From other side, server can not open its server port, since it's occupied/stolen by client.
我使用的是 RHEL 5.3,我的客户端不断尝试连接到本地服务器.最终客户端连接到自身.
I'm using RHEL 5.3 and my clients constantly tries to connect to local server. Eventually client connects to itself.
我想阻止这种情况.我看到了该问题的两种可能解决方案:
I want to prevent the situation. I see two possible solutions to the problem:
- 不要将临时端口用于服务器端口.同意临时端口范围并在您的机器上配置它(请参阅临时范围)
- 检查connect(),因为有人建议在这里.
- Don't use ephemeral ports for server ports. Agree ephemeral port range and configure it on your machines (see ephemeral range)
- Check connect() as somebody propose here.
你怎么看?你是如何处理这个问题的?
What do you thinks? How do you handle the issue?
P.S.1
除了我显然在寻找的解决方案,我希望您能分享一下您对这个问题的真实体验.
Except of the solution, which I obviously looking for, I'd like you to share your real life experience with the problem.
当我找到问题的原因时,我对我的工作场所不熟悉的人感到惊讶".通过定期连接轮询服务器是恕我直言的常见做法,所以这个问题是如何不为人所知的.
When I found the cause of the problem, I was "astonished" on my work place people are not familiar with it. Polling server by connecting it periodically is IMHO common practice, so how it's that the problem is not commonly known.
推荐答案
对于服务器,你需要 bind() 套接字到端口.一旦 addr:port 对绑定了套接字,它将不再用于 connect() 中的隐式绑定.
For server you need to bind() socket to port. Once addr:port pair had socket bound, it will no longer be used for implicit binding in connect().
没问题,没问题.
这篇关于TCP 同时打开和自连接预防的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:TCP 同时打开和自连接预防


基础教程推荐
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 从 std::cin 读取密码 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01