TCP同时打开和自连接防止 [英] TCP simultaneous open and self connect prevention

查看:192
本文介绍了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:


  1. 不要使用临时端口的服务器端口。
    同意临时端口范围并在您的计算机上进行配置(请参见临时范围

  2. 检查 connect()是否有人建议这里

  1. Don't use ephemeral ports for server ports. Agree ephemeral port range and configure it on your machines (see ephemeral range)
  2. Check connect() as somebody propose here.

你觉得怎么样?
如何处理此问题?

What do you thinks? How do you handle the issue?

1

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.

当我发现问题的原因时,我对我的工作场所惊讶,人们不熟悉它。轮询服务器通过连接它定期是IMHO常见的做法,
所以怎么是这个问题不是众所周知的。

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同时打开和自连接防止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆