Escape characters in communication protocols and escape characters in communication protocols
Escape characters in communication protocols
Purpose: make the communication content more secure and reliable in the communication protocol.
For example: if you need to customize a communication protocol, the most basic thing you need is a frame header and frame tail flag, only the recipient of the communication knows when the communication starts and ends. Assume that the frame header (starting from the communication) is 0x02 (or other) and the end of the frame is 0x03 (or another ), there is no problem at first glance, but imagine that the entire communication process will be damaged if the data between the frame header and the end of the frame is 0x02 or 0x03, because a frame of data has not been transmitted yet, the receiver mistakenly believes that the received frame header or frame tail will re-start receiving data (resulting in the loss of previously received data) or end receiving data (resulting in subsequent data being unable to be received ). Theoretically, both the frame header and the frame end may be in the communication data regardless of the definition, because we should not make any assumptions about the communication data transmitted by users. How can this problem be solved? The Escape Character is used to solve this problem. first look at the following picture:
In this image, a character 0x1B is added, which is defined as an escape character (or another character, 0x02 + User Data + 0x03, but in user data, 0x02 is replaced with 0x1B + 0xE7. If 0x03 appears, it is replaced with 0x1B + 0xE8, in this way, 0x02 and 0x03 will never appear in user data. But what if the data to be transmitted is 0x1B + 0xE7? This also does not matter, because if the user wants to transmit 0x1B, it will also be escaped as 0x1B + 0x00, therefore, if the user really needs to transmit 0x1B + 0xE7, it will also be replaced by 0x1B + 0x00 + 0xE7, which will not cause interference. The result is that if the receiver receives the escape character, it must determine whether the next character is a specific three values. If the next character is a specific three values, special processing is required, this is how escape characters prevent communication errors during communication.
The process of using 0x7d as escape characters in the asynchronous link of the point-to-point PPP protocol
After FCS computation, the transmitter examines the entire frame
Between the two Flag Sequences. Each Flag Sequence, Control Escape
Octet, and any octet which is flagged in the sending Async-Control-
Character-Map (ACCM), is replaced by a two octet sequence consisting
Of the Control Escape octet followed by the original octet
Exclusive-or 'd with hexadecimal 0x20.
This is bit 5 complemented, where the bit positions are numbered
76543210 (the 6th bit as used in ISO numbered 87654321 -- BEWARE
When comparing events ENTs ).
Refreshing ing implementations MUST correctly process all Control Escape
On encryption tion, prior to FCS computation, each octet with value less
Than hexadecimal 0x20 is checked. If it is flagged in the processing ing
ACCM, it is simply removed (it may have been inserted by intervening
Data communications equipment). Each Control Escape octet is also
Removed, and the following octet is exclusive-or 'd with hexadecimal
0x20, unless it is the Flag Sequence (which aborts a frame ).
What is an escape character in c?
Escape characters are a special form of characters in C. Generally, escape characters are used to indicate non-printable control characters in the ASCII character set and special function characters. For example, a single marker (') is used to represent a character constant ('), it is used to represent the double apostrophes (") and backslash (\) of string constants. Escape characters are represented by a backslash \ followed by a character or an octal or hexadecimal number.
Escape Character meaning ASCII code value (decimal)
\ A bell (BEL) 007
\ B backspace (BS) 008
\ F form feed (FF) 012
\ N line feed (LF) 010
\ R press enter (CR) 013
\ T horizontal tabulation (HT) 009
\ V vertical tabulation (VT) 011
\ Backslash 092
\? Question mark character 063
\ 'Single quotes character 039
\ "Double quotation mark character 034
\ 0 NULL character (NULL) 000
\ Ddd any character three octal characters
\ Xhh any character two hexadecimal
When single quotation marks and backslash are used in character constants and double quotation marks and backslash are used in character constants, escape characters must be used to represent them, that is, the backslash must be added before these characters.
The Escape Character \ d Or \ x h can be used in the C program to conveniently and flexibly represent any character. \ D is followed by A slash and followed by three Octal numbers. The value of the three Octal numbers is the corresponding octal a s c I code value. \ X is followed by two hexadecimal numbers. The two hexadecimal numbers correspond to the hexadecimal a s c I code value of the character.
Note the following when using escape characters:
1) only lowercase letters can be used in escape characters. Each escape character can only be considered as one character.
2) The \ v vertical tabulation and the \ f tab have no impact on the screen, but will affect the printer's response.
3) when non-printable characters are used in C Programs, escape characters are usually used.