CN113556268A - Method for realizing tcping - Google Patents
Method for realizing tcping Download PDFInfo
- Publication number
- CN113556268A CN113556268A CN202110833423.1A CN202110833423A CN113556268A CN 113556268 A CN113556268 A CN 113556268A CN 202110833423 A CN202110833423 A CN 202110833423A CN 113556268 A CN113556268 A CN 113556268A
- Authority
- CN
- China
- Prior art keywords
- tcping
- packet
- socket
- syn
- server end
- 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.)
- Granted
Links
- 238000000034 method Methods 0.000 title claims abstract description 35
- 230000000903 blocking effect Effects 0.000 claims description 6
- 238000004806 packaging method and process Methods 0.000 claims description 4
- 238000004891 communication Methods 0.000 description 3
- 238000010586 diagram Methods 0.000 description 3
- 238000005516 engineering process Methods 0.000 description 2
- 238000012790 confirmation Methods 0.000 description 1
- 239000004744 fabric Substances 0.000 description 1
Images
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)
- Environmental & Geological Engineering (AREA)
- Computer Security & Cryptography (AREA)
- Data Exchanges In Wide-Area Networks (AREA)
Abstract
The invention discloses a tcping implementation method, which utilizes the existing TCP three-way handshake function in a Linux inner core, and utilizes the characteristic of automatic package of the Linux inner core to automatically send a SYN packet to an opposite Server after calling a connect function for the first time of the three-way handshake without automatically combining the SYN packet; in the second time of the three-way handshake, the Linux kernel can automatically process the SYN + ACK packet replied by the Server end of the other side, and functions such as recv and the like are not needed to receive the packet replied by the Server end and analyze the data packet; the Timeout not replied by the server end is processed, and a result can be directly obtained from a return value of a connect function; if the round trip time RTT is successful, the round trip time RTT can be directly obtained, and if the round trip time RTT is failed, the reason of the failure can be obtained, so that 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 TCP establishes connection, it needs to complete through three-way handshake protocol, and after the active side sends out SYN connection request, it waits for the opposite side to reply SYN + ACK, and makes ACK confirmation for the SYN of the opposite side. The method for establishing the connection by three-way handshake can effectively prevent the occurrence of wrong connection. By utilizing the first two communications of the three-way handshake, 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 is calculated, and the round trip time RTT of the tcping can be obtained; and whether the opposite side replies with the SYN + ACK data packet or not can obtain whether the tcping is unblocked at the time.
When the existing method realizes tcping on Linux, the message of the SYN connection request is automatically combined according to the given parameters of the address, the port and the like of the receiving party and is sent to the receiving party, at the moment, the receiving party replies a SYN + ACK data packet, and then the message is analyzed to see whether the SYN + ACK data packet meets the requirement or not. The process of self-packaging and package analysis in the method is complicated.
FIG. 1 shows a prior art four-time tcping completion process; sequence numbers 1, 2 and 3 are tcping times, and the time interval between sequence number 1 and sequence number 2 is the round trip time RTT of tcping times. After the tcping process of sequence number 1 and sequence number 2 is completed, the local active disconnection, the RST packet sending sequence number 3 requests to disconnect, and a tcping process is completed.
Disclosure of Invention
The invention aims to provide a tcping implementation method, which utilizes the existing TCP three-way handshake function in a linux kernel, avoids the processes of self-packaging and packet analysis, is easy to implement codes and solves the problems in the background technology.
In order to achieve the purpose, the invention provides the following technical scheme:
a method for realizing tcping comprises the following steps:
firstly, judging whether a host name Hostname input by a user is an effective IP address, and if not, performing domain name resolution to obtain the IP address after the domain name resolution.
The socket's connection parameters are then initialized, and the IP and Port are placed into the socket addr _ in struct variables in preparation for the subsequent connect function call.
Then entering while large loop, and as long as the current connection times are less than the preset value, doing the specific action of tcping.
In each tcping process, firstly creating a socket of the TCP, and setting the attribute of the socket as a byte STREAM socket SOCK _ STREAM; then setting the timeout of the sending and receiving of the socket, calling a connect function to connect the server in a blocking mode, if the connection is successful, returning the connect function to 0, and because the connection is performed in a blocking mode, the execution time of the connect function is the round trip time RTT of single tcping; otherwise, an error code errno is returned, the 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 on connecting the Server.
Compared with the prior art, the invention has the advantages that:
1. in the first time of the three-way handshake, the characteristics of Linux kernel automatic package are utilized to call the connect function and then automatically send the SYN packet to the opposite Server end, and the SYN packet does not need to be automatically combined, thereby reducing a lot of code amount.
2. In the second time of the three-way handshake, the Linux kernel can automatically process the SYN + ACK packet replied by the opposite Server end, and functions such as recv and the like are not needed to receive the packet replied by the Server end and analyze the data packet, so that the code amount is greatly reduced.
3. In the second time of the three-way handshake, a Linux inner core is utilized to automatically process a SYN + ACK packet replied by the opposite Server end, and the Timeout which is not replied after the Timeout of the Server end is processed, so that a result can be directly obtained from a return value of a connect function; if the round trip time RTT is successful, the round trip time RTT can be directly obtained, and if the round trip time RTT is failed, the reason of the failure can be obtained, so that redundant judgment logic is omitted.
Drawings
FIG. 1 is a schematic diagram of packet capture in an implementation process of a conventional tcping technology.
FIG. 2 is a schematic diagram of a packet capture by tcping in the method of the present invention.
FIG. 3 is a schematic diagram of the implementation of tcping in accordance with the present invention.
Detailed Description
The technical solution of the present patent will be described in further detail with reference to the following embodiments.
The first embodiment,
Referring to fig. 3, a tcping implementation method utilizes the existing TCP three-way handshake function in the linux kernel, which avoids the process of self-packaging and packet parsing, and is easy to implement a code, and includes the following steps:
and judging whether the host name Hostname input by the user is an effective IP or not, and if not, performing domain name resolution to obtain the IP after the domain name resolution.
The socket's connection parameters are initialized, and the IP and Port are placed into the socket addr _ in fabric variables in preparation for the subsequent connect function call.
Entering while large loop, and performing the specific action of tcping as long as the current connection times are less than the 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 SOCK _ STREAM; then setting the timeout of the sending and receiving of the socket, calling a connect function to connect the server in a blocking mode, if the connection is successful, returning the connect function to 0, and because the connection is performed in a blocking mode, the execution time of the connect function is the round trip time RTT of single tcping; otherwise, an error code errno is returned, the specific error reason can be checked according to the errno, and finally the socket is dropped by close.
And after the preset connection times are finished, counting the result of tcping to obtain the packet loss rate and the average time spent on connecting the Server.
As shown in fig. 2, the four-time tcping packet capturing process designed in this patent is performed, where sequence 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 for starting TCP connection, the packets with sequence numbers 1, 2, and 3 are automatically completed by Linux Kernel, and do not need to be automatically packaged and analyzed, and the time interval between sequence number 1 and sequence number 2 is the round trip time RTT of one-time tcping; when the handshake process is completed, the TCP connections are broken by the packets with sequence numbers 4, 5, 6, and 7, and a tcping process is completed.
Example two
The difference between this embodiment and the first embodiment is that when a socket is established, the attribute of the socket is set as an original socket, socket _ RAW, and a SYN packet is grouped by itself and sent to an IP and Port of a Server, and then the content of the original socket is received, and the content of the received packet is analyzed to see whether the packet is a valid SYN + ACK packet in a three-way handshake of TCP connection; if legal, this time tcping succeeds, otherwise fails.
Although 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 can be made without departing from the spirit of the present patent within the knowledge of those skilled in the art.
Claims (3)
1. A method for realizing tcping utilizes the existing TCP three-way handshake function in linux kernel, avoids the process of self-packaging and analyzing packets, and is characterized in that,
in the first time of the three-way handshake, the characteristics of Linux kernel automatic package are utilized to call the connect function and then automatically send the SYN packet to the opposite Server end without self-combination of the SYN packet;
in the second time of the three-way handshake, the Linux kernel can automatically process the SYN + ACK packet replied by the Server end of the other side, and functions such as recv and the like are 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, a Linux inner core is utilized to automatically process a SYN + ACK packet replied by the opposite Server end, and the Timeout which is not replied after the Timeout of the Server end is processed, so that a result can be directly obtained from a return value of a connect function; if the round trip time RTT is successful, the round trip time RTT can be directly obtained, and if the round trip time RTT is failed, the reason of the failure can be obtained, so that redundant judgment logic is omitted.
2. The method for implementing tcping according to claim 1, wherein the method comprises the following steps:
judging whether the host name Hostname input by the user is an effective IP or not, and if not, performing domain name resolution to obtain the IP after the domain name resolution;
initializing the connection parameters of socket, putting IP and Port into the variables of the socket addr _ in structure body, and preparing for the calling of the following connect function;
entering while large circulation, and performing a specific action of tcping as long as the current connection times are less 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 on connecting the Server.
3. The method for implementing tcping of claim 2, wherein in each tcping process, a socket of TCP is created first, and an attribute of the socket is set as a byte STREAM socket _ STREAM; then setting the timeout of the sending and receiving of the socket, calling a connect function to connect the server in a blocking mode, if the connection is successful, returning the connect function to 0, and because the connection is performed in a blocking mode, the execution time of the connect function is the round trip time RTT of single tcping; otherwise, an error code errno is returned, the 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 true CN113556268A (en) | 2021-10-26 |
CN113556268B 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 (8)
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 |
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 |
-
2021
- 2021-07-23 CN CN202110833423.1A patent/CN113556268B/en active Active
Patent Citations (8)
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 |
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 (5)
Title |
---|
傅佳芳 等: ""Ping 技术研究"", 《微型电脑应用》, vol. 23, no. 6, pages 1 - 3 * |
傅佳芳;赵保华;: "Ping技术研究", 微型电脑应用, no. 06 * |
老王不让用: "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的网络聊天系统设计", 现代电子技术, no. 03 * |
Also Published As
Publication number | Publication date |
---|---|
CN113556268B (en) | 2023-12-26 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
JP4611593B2 (en) | Method and apparatus for performing network operations | |
CN110809905B (en) | Method and system for using remote subscriber identity module at device | |
CN109639712B (en) | Method and system for preventing DDOS attack | |
US20060221946A1 (en) | Connection establishment on a tcp offload engine | |
CN112165447B (en) | WAF equipment-based network security monitoring method, system and electronic device | |
CN108234087B (en) | Data transmission method and sending end | |
EP3525421B1 (en) | Data transmission method and apparatus | |
CN109922144B (en) | Method and apparatus for processing data | |
CN101247261A (en) | Method and apparatus for preventing DDos attack | |
US20200379834A1 (en) | Covertly storing a payload of data within a network | |
US8825804B2 (en) | Method and system for avoiding an unintentional time-out for communications in a client-proxy-server environment | |
JP3872977B2 (en) | Method, system, and packet data serving node for mobile IP registration of a mobile node | |
CN112637149B (en) | Data communication method between asymmetric security policy partitions | |
CN113765976A (en) | Communication method and system | |
CN110166479B (en) | Method for improving UDP (user Datagram protocol) sending efficiency of transmission 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 | |
WO2024159952A1 (en) | Bidirectional forwarding detection method and apparatus, and electronic device and readable storage medium | |
CN106302361A (en) | A kind of method and apparatus preventing network attack | |
CN113556268A (en) | Method for realizing tcping | |
CN109714135B (en) | Data packet transmission method and device | |
CN117336346A (en) | IPPBX and PMS docking state conversion method, terminal equipment and medium | |
US20040001490A1 (en) | Method of verifying number of sessions of computer stack | |
CN109413037B (en) | Modbus service processing method and device | |
WO2024045857A1 (en) | Data transmission method and apparatus |
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 |