CN113556268B - Method for realizing tcping - Google Patents
Method for realizing tcping Download PDFInfo
- Publication number
- CN113556268B CN113556268B CN202110833423.1A CN202110833423A CN113556268B CN 113556268 B CN113556268 B CN 113556268B CN 202110833423 A CN202110833423 A CN 202110833423A CN 113556268 B CN113556268 B CN 113556268B
- Authority
- CN
- China
- Prior art keywords
- tcping
- socket
- syn
- function
- way handshake
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
- 238000000034 method Methods 0.000 title claims abstract description 32
- 230000000903 blocking effect Effects 0.000 claims description 6
- 238000004891 communication Methods 0.000 description 3
- 238000010586 diagram Methods 0.000 description 3
- 238000005516 engineering process Methods 0.000 description 2
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L43/00—Arrangements for monitoring or testing data switching networks
- H04L43/08—Monitoring or testing based on specific metrics, e.g. QoS, energy consumption or environmental parameters
- H04L43/0805—Monitoring or testing based on specific metrics, e.g. QoS, energy consumption or environmental parameters by checking availability
- H04L43/0811—Monitoring or testing based on specific metrics, e.g. QoS, energy consumption or environmental parameters by checking availability by checking connectivity
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L43/00—Arrangements for monitoring or testing data switching networks
- H04L43/08—Monitoring or testing based on specific metrics, e.g. QoS, energy consumption or environmental parameters
- H04L43/0852—Delays
- H04L43/0864—Round trip delays
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L61/00—Network arrangements, protocols or services for addressing or naming
- H04L61/45—Network directories; Name-to-address mapping
- H04L61/4505—Network directories; Name-to-address mapping using standardised directories; using standardised directory access protocols
- H04L61/4511—Network directories; Name-to-address mapping using standardised directories; using standardised directory access protocols using domain name system [DNS]
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L69/00—Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
- H04L69/16—Implementation or adaptation of Internet protocol [IP], of transmission control protocol [TCP] or of user datagram protocol [UDP]
- H04L69/161—Implementation details of TCP/IP or UDP/IP stack architecture; Specification of modified or new header fields
- H04L69/162—Implementation details of TCP/IP or UDP/IP stack architecture; Specification of modified or new header fields involving adaptations of sockets based mechanisms
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L69/00—Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
- H04L69/16—Implementation or adaptation of Internet protocol [IP], of transmission control protocol [TCP] or of user datagram protocol [UDP]
- H04L69/163—In-band adaptation of TCP data exchange; In-band control procedures
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Computer Security & Cryptography (AREA)
- Environmental & Geological Engineering (AREA)
- Data Exchanges In Wide-Area Networks (AREA)
Abstract
The invention discloses a realization method of tcping, which utilizes the existing TCP three-way handshake function in a Linux kernel, and in the first time of three-way handshake, utilizes the characteristic of automatic package grouping of the Linux kernel, and automatically sends SYN packages to the opposite side Server after calling a connect function without self-combining SYN packages; in the second time of the three-way handshake, the SYN+ACK packet replied by the Server end of the opposite party is automatically processed by utilizing the Linux kernel, and the functions of recv and the like are not needed to receive the packet replied by the Server end and analyze the data packet; the Timeout which is not replied after the Timeout of the server is processed, and a result can be directly obtained from the return value of the connect function; if successful, the round trip time RTT can be directly obtained, the failure can obtain the failure reason of the round trip time RTT, and redundant judgment logic is omitted.
Description
Technical Field
The invention relates to the technical field of communication protocols, in particular to a method for realizing tcping.
Background
TCP is a connection-oriented, reliable, byte stream based transport layer communication protocol. When the TCP establishes connection, the connection needs to be completed through a three-way handshake protocol, and after the initiative side sends out a SYN connection request, the initiative side waits for the reply of SYN+ACK, and the acknowledgement of the SYN of the initiative side is carried out. The method for establishing the connection by the three-way handshake can effectively prevent the occurrence of wrong connection. The round trip time RTT of the tcping can be obtained by utilizing the first two times of communication of the three times of handshake and calculating the time interval between the SYN connection data packet sent by the active party and the SYN+ACK data packet replied by the opposite party; and if the opposite party replies with a SYN+ACK data packet, whether the tcping is smooth or not can be obtained.
When tcping is realized on Linux, the existing method can automatically combine a message of a SYN connection request according to the given parameters such as the address and the port of a receiver and send the message to the receiver, at the moment, the receiver replies a SYN+ACK data packet, and then analyzes the message to see whether the message is the SYN+ACK data packet meeting the requirements. In the method, the processes of self-organizing packages and analyzing the packages are complicated.
Shown in fig. 1 is the four tcping complete process in the prior art; sequence numbers 1, 2 and 3 are one tcping, and the time interval between sequence number 1 and sequence number 2 is the round trip time RTT of one tcping. After the tcping process of the sequence number 1 and the sequence number 2 is completed, the connection is actively disconnected locally, and the RST data packet of the sequence number 3 is sent to request disconnection, so that a tcping process is completed.
Disclosure of Invention
The invention aims to provide a method for realizing tcping, which utilizes the existing TCP three-way handshake function in a linux kernel, avoids the processes of self-grouping packets and analyzing packets, is easy in code realization, and solves the problems in the background technology.
In order to achieve the above purpose, the present invention provides the following technical solutions:
a realization method of tcping comprises the following steps:
firstly, judging whether a host name Hostname input by a user is a valid IP address, if not, performing domain name resolution to obtain an IP address after domain name resolution.
Then initializing the connection parameters of socket, putting IP and Port into the socket addr_in structure variable, and preparing for the subsequent connect function call.
Then, a while large loop is entered, and a specific action of tcping is performed as long as the current connection times are smaller than a preset value.
In each tcping process, firstly creating a socket of the TCP, and setting the attribute of the socket as a byte STREAM socket_stream; setting a timeout for sending and receiving the socket, calling a connect function to connect a server in a blocking mode, and if the connection is successful, returning the connect function to 0, wherein the execution time of the connect function is round trip time RTT of single tcping because of blocking execution; otherwise, an error code errno is returned, a specific error reason can be checked according to the errno, and finally a close function is called to close the socket.
And after the preset connection times are finished, counting the result of tcping to obtain the packet loss rate and the average time spent by the Server on connection.
Compared with the prior art, the invention has the advantages that:
1. in the first time of three-way handshake, the characteristic of automatic package grouping of the Linux kernel is utilized, and after a connect function is called, a SYN package is automatically sent to the opposite side Server end, so that the SYN package is not required to be automatically combined, and a plurality of code quantities are reduced.
2. In the second time of the three-way handshake, the SYN+ACK packet replied by the Server end of the opposite party is automatically processed by utilizing the Linux kernel, and the functions of recv and the like are not needed to receive the packet replied by the Server end and analyze the data packet, so that a lot of code quantity is reduced.
3. In the second time of the three-way handshake, the SYN+ACK packet replied by the Server end of the opposite party is automatically processed by utilizing the Linux kernel, and the Timeout unreflected Timeout of the Server end is processed, so that a result can be directly obtained from the return value of the connect function; if successful, the round trip time RTT can be directly obtained, the failure can obtain the failure reason of the round trip time RTT, and redundant judgment logic is omitted.
Drawings
Fig. 1 is a schematic diagram of packet grabbing in the implementation process of the conventional tcping technology.
FIG. 2 is a schematic diagram of the packet grabbing of tcping in the method of the present invention.
Fig. 3 is a schematic diagram of the implementation of tcping of the present invention.
Detailed Description
The technical scheme of the patent is further described in detail below with reference to the specific embodiments.
Embodiment 1,
Referring to fig. 3, a tcping implementation method utilizes the existing TCP three-way handshake function in the linux kernel, so that the processes of self-grouping packets and analyzing packets are omitted, the implementation of codes is easier, and the method comprises the following steps:
judging whether the host name Hostname input by the user is a valid IP, and if not, performing domain name resolution to obtain the IP after domain name resolution.
Initializing the connection parameters of socket, putting IP and Port into the socket addr_in structure variable, and preparing for the subsequent connect function call.
And entering a while large loop, and performing a specific action of tcping as long as the current connection times are smaller than a preset value.
In each tcping process, firstly creating a socket of the TCP, and setting the attribute of the socket as a byte STREAM socket_stream; setting a timeout for sending and receiving the socket, calling a connect function to connect a server in a blocking mode, and if the connection is successful, returning the connect function to 0, wherein the execution time of the connect function is round trip time RTT of single tcping because of blocking execution; otherwise, an error code errno is returned, a specific error reason can be checked according to the errno, and finally the socket is closed.
And after the preset connection times are finished, counting the result of tcping to obtain the packet loss rate and the average time spent by the Server on connection.
As shown in fig. 2, which is a four-time tcping packet grabbing process designed in the patent, serial numbers 1, 2, 3, 4, 5, 6 and 7 are one-time tcping, it can be seen that the connect function completes the three-time handshake process started by the TCP connection, the packets with serial numbers 1, 2 and 3 are Linux Kernel automatic completion, self-grouping and packet analysis are not needed, and the time interval between serial numbers 1 and 2 is the round trip time RTT of one-time tcping; after the handshake process is completed, the data packets with sequence numbers 4, 5, 6 and 7 break the TCP connection, and a tcping process is completed.
Example two
The difference between the first embodiment and the second embodiment is that when a socket is established, the attribute of the socket is set as an original socket_RAW, the SYN packet of the socket is sent to the IP and Port of the Server, then the content of the original socket is received, and the content of the received packet is analyzed to see whether the received packet is a legal SYN+ACK packet in the three-way handshake of the TCP connection; if it is legal, then this tcping is successful, otherwise it fails.
While the preferred embodiments of the present patent have been described in detail, the present patent is not limited to the above embodiments, and various changes may be made without departing from the spirit of the present patent within the knowledge of one of ordinary skill in the art.
Claims (2)
1. The method for implementing tcping utilizes the existing TCP three-way handshake function in the linux kernel, omits the processes of self-grouping packets and analyzing packets, and is characterized in that,
in the first time of three-way handshake, the characteristic of automatic package grouping of the Linux kernel is utilized, and after a connect function is called, a SYN package is automatically sent to the opposite side Server end, so that the SYN package is not required to be automatically combined;
in the second time of the three-way handshake, the SYN+ACK packet replied by the Server end of the opposite party is automatically processed by utilizing the Linux kernel, and a recv function is not needed to receive the packet replied by the Server end and analyze the data packet;
in the second time of the three-way handshake, the Linux kernel is utilized to automatically process SYN+ACK packets replied by the opposite side Server end, and process Timeout unreflected Timeout of the Server end, so that a result can be directly obtained from the return value of a connect function; if successful, the round trip time RTT can be directly obtained, the failure can obtain the failure reason of the round trip time RTT, and redundant judgment logic is omitted;
the implementation method of tcping comprises the following specific steps:
judging whether the host name Hostname input by the user is a valid IP, if not, performing domain name resolution to obtain the IP after the domain name resolution;
initializing connection parameters of socket, putting IP and Port into a socket addr_in structure body variable, and preparing for subsequent connect function call;
entering a while large cycle, and performing a specific action of tcping as long as the current connection times are smaller than a preset value;
and after the preset connection times are finished, counting the result of tcping to obtain the packet loss rate and the average time spent by the Server on connection.
2. The method according to claim 1, wherein in each tcping process, a socket of TCP is first created, and an attribute of the socket is set to be a byte STREAM socket_stream; setting a timeout for sending and receiving the socket, calling a connect function to connect a server in a blocking mode, and if the connection is successful, returning the connect function to 0, wherein the execution time of the connect function is round trip time RTT of single tcping because of blocking execution; otherwise, an error code errno is returned, a specific error reason can be checked according to the errno, and finally a close function is called to close the socket.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110833423.1A CN113556268B (en) | 2021-07-23 | 2021-07-23 | Method for realizing tcping |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110833423.1A CN113556268B (en) | 2021-07-23 | 2021-07-23 | Method for realizing tcping |
Publications (2)
Publication Number | Publication Date |
---|---|
CN113556268A CN113556268A (en) | 2021-10-26 |
CN113556268B true CN113556268B (en) | 2023-12-26 |
Family
ID=78132542
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202110833423.1A Active CN113556268B (en) | 2021-07-23 | 2021-07-23 | Method for realizing tcping |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN113556268B (en) |
Citations (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101217493A (en) * | 2008-01-08 | 2008-07-09 | 北京大学 | TCP data package transmission method |
US7742415B1 (en) * | 2007-09-26 | 2010-06-22 | The United States Of America As Represented By Secretary Of The Navy | Non-intrusive knowledge suite for evaluation of latencies in IP networks |
CN102769520A (en) * | 2012-07-17 | 2012-11-07 | 西安电子科技大学 | Wireless network congestion control method based on stream control transmission protocol (SCTP) |
CN103064391A (en) * | 2012-12-28 | 2013-04-24 | 广州数控设备有限公司 | Numerical control system long-distance direct numerical control (DNC) control method based on transmission control protocol (TCP) / internet protocol (IP) and linux network program |
CN107635011A (en) * | 2017-10-17 | 2018-01-26 | 上海哎媲媲网络技术有限公司 | A kind of Android platform realizes the system and method for the interior network Transparent Proxy of application |
CN112165537A (en) * | 2020-09-17 | 2021-01-01 | 广州锦行网络科技有限公司 | Virtual IP method for ping reply |
US11070573B1 (en) * | 2018-11-30 | 2021-07-20 | Capsule8, Inc. | Process tree and tags |
Family Cites Families (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20070008884A1 (en) * | 2003-10-08 | 2007-01-11 | Bob Tang | Immediate ready implementation of virtually congestion free guarantedd service capable network |
-
2021
- 2021-07-23 CN CN202110833423.1A patent/CN113556268B/en active Active
Patent Citations (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US7742415B1 (en) * | 2007-09-26 | 2010-06-22 | The United States Of America As Represented By Secretary Of The Navy | Non-intrusive knowledge suite for evaluation of latencies in IP networks |
CN101217493A (en) * | 2008-01-08 | 2008-07-09 | 北京大学 | TCP data package transmission method |
CN102769520A (en) * | 2012-07-17 | 2012-11-07 | 西安电子科技大学 | Wireless network congestion control method based on stream control transmission protocol (SCTP) |
CN103064391A (en) * | 2012-12-28 | 2013-04-24 | 广州数控设备有限公司 | Numerical control system long-distance direct numerical control (DNC) control method based on transmission control protocol (TCP) / internet protocol (IP) and linux network program |
CN107635011A (en) * | 2017-10-17 | 2018-01-26 | 上海哎媲媲网络技术有限公司 | A kind of Android platform realizes the system and method for the interior network Transparent Proxy of application |
US11070573B1 (en) * | 2018-11-30 | 2021-07-20 | Capsule8, Inc. | Process tree and tags |
CN112165537A (en) * | 2020-09-17 | 2021-01-01 | 广州锦行网络科技有限公司 | Virtual IP method for ping reply |
Non-Patent Citations (4)
Title |
---|
"Ping 技术研究";傅佳芳 等;《微型电脑应用》;第23卷(第6期);第1-3节 * |
linux内核协议栈 connect 系统调用Ⅰ之 发送 SYN 包;老王不让用;https://blog.csdn.net/wangquan1992/article/details/108886504;全文 * |
linux内核协议栈 connect 系统调用Ⅱ 之收到 SYN+ACK,发送 ACK_客户端处理synack报文;老王不让用;https://blog.csdn.net/wangquan1992/article/details/108903457;全文 * |
基于Linux的网络聊天系统设计;萧泳东;肖化;;现代电子技术(第03期);全文 * |
Also Published As
Publication number | Publication date |
---|---|
CN113556268A (en) | 2021-10-26 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
JP4611593B2 (en) | Method and apparatus for performing network operations | |
EP2843908B1 (en) | Full-duplex bi-directional communication over a remote procedure call based communications protocol, and applications thereof | |
US20060221946A1 (en) | Connection establishment on a tcp offload engine | |
CN112165447B (en) | WAF equipment-based network security monitoring method, system and electronic device | |
CN109005194B (en) | No-port shadow communication method based on KCP protocol and computer storage medium | |
US10530644B2 (en) | Techniques for establishing a communication connection between two network entities via different network flows | |
CN103475706B (en) | Pseudo-TCP covert communication method based on SYN-ACK two server bounce mode | |
KR20100084118A (en) | Method for improving a tcp data transmission process in case the physical transmission medium is disconnected | |
CN102769520B (en) | Wireless network congestion control method based on stream control transmission protocol (SCTP) | |
CN106453356A (en) | Wireless network bilateral accelerated transmission method and system | |
CN108234087A (en) | Data transmission method and transmitting terminal | |
CN113765976A (en) | Communication method and system | |
CN110753035B (en) | FPGA (field programmable Gate array) ultralow-delay communication transmission method based on TCP (Transmission control protocol) | |
CN115118524A (en) | Interface equipment and free intercommunication data transparent transmission method, system and device of Internet of things | |
CN112559146A (en) | Communication method between client and data terminal server | |
WO2020243249A1 (en) | Covertly storing a payload of data within a network | |
CN110166479B (en) | Method for improving UDP (user Datagram protocol) sending efficiency of transmission system | |
WO2024159952A1 (en) | Bidirectional forwarding detection method and apparatus, and electronic device and readable storage medium | |
CN113556268B (en) | Method for realizing tcping | |
CN110502391A (en) | The grasping means and system of SQL information in a kind of MySQL database | |
CN111654505B (en) | UDP data packet reliable transmission method, system, computer equipment and storage medium | |
CN109714135B (en) | Data packet transmission method and device | |
CN103607311A (en) | System and method for reestablishing TCP connection seamlessly | |
US20140177575A1 (en) | Method for establishing an application session, device and corresponding notification | |
US20040001490A1 (en) | Method of verifying number of sessions of computer stack |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |