当前位置: 技术问答>linux和unix
请问RST在什么情况下发送?? 使用TCP socket编程的话是否会引起这种TCP包的发送?
来源: 互联网 发布时间:2015-12-17
本文导语: 请问RST在什么情况下发送?? 使用TCP socket编程的话是否会引起这种TCP包的发送? | 从google上查找到的,主要发生在非正常的TCP连接中.原文如下: RST is an abnormal close, also called "slamming the conne...
请问RST在什么情况下发送?? 使用TCP socket编程的话是否会引起这种TCP包的发送?
|
从google上查找到的,主要发生在非正常的TCP连接中.原文如下:
RST is an abnormal close, also called "slamming the connection shut." It happens under several circumstances, but none of the common ones are documented in the Stevens diagram. Two of these cases you can cause from Winsock: the first method is to set SO_LINGER to 0 with setsockopt() and then call closesocket(). The second method is to call shutdown() with how equal to 2, optionally followed by a closesocket() call.
From the Winsock client level, the two other common RST occurrences are "connection refused" and "remote peer terminated connection." The first happens when you try to connect to a port that isn't open on a remote machine. The second happens as a result of the remote peer using one of the two RST-forcing methods above; alternately, the application could have crashed, and the peer's stack sent out a RST for its connection. Another way this can happen is the remote peer catastrophically crashed, and then after the remote machine came back up, your program sent it a packet which the stack rightfully had no way of delivering, so it replied with a RST packet, because the connection's 5-tuple is now invalid.
Generally speaking, RST signals a problem of some kind: either something bad happened to the connection, or there's a bug somewhere. For example, some firewalls improperly use the RST bit to signal a closed connection. The solution, of course, is to replace the firewall product. :)
RST is an abnormal close, also called "slamming the connection shut." It happens under several circumstances, but none of the common ones are documented in the Stevens diagram. Two of these cases you can cause from Winsock: the first method is to set SO_LINGER to 0 with setsockopt() and then call closesocket(). The second method is to call shutdown() with how equal to 2, optionally followed by a closesocket() call.
From the Winsock client level, the two other common RST occurrences are "connection refused" and "remote peer terminated connection." The first happens when you try to connect to a port that isn't open on a remote machine. The second happens as a result of the remote peer using one of the two RST-forcing methods above; alternately, the application could have crashed, and the peer's stack sent out a RST for its connection. Another way this can happen is the remote peer catastrophically crashed, and then after the remote machine came back up, your program sent it a packet which the stack rightfully had no way of delivering, so it replied with a RST packet, because the connection's 5-tuple is now invalid.
Generally speaking, RST signals a problem of some kind: either something bad happened to the connection, or there's a bug somewhere. For example, some firewalls improperly use the RST bit to signal a closed connection. The solution, of course, is to replace the firewall product. :)
|
1,三路握手完成,连接建立,客户TCP发一个RST.
2,写一个已经关闭的套接口,收到对方发送的RST
2,写一个已经关闭的套接口,收到对方发送的RST
|
看网络编程卷一,很详细
|
TCP SOCKET是会引起的
比如你客户端connect一个服务器未提供服务的端口,服务器会发送RST到客户端;
还有使用close + SO_LINGER
还有重传超时,keepalive等记时器超时。。。。。
TCP/IP illustrated v1 & v2也有介绍
比如你客户端connect一个服务器未提供服务的端口,服务器会发送RST到客户端;
还有使用close + SO_LINGER
还有重传超时,keepalive等记时器超时。。。。。
TCP/IP illustrated v1 & v2也有介绍
|
目的TCP端口不在监听,或端口无法建立连接时(比如在2msl)
看看tcp/ip详解第一卷
看看tcp/ip详解第一卷