This is a creation in Article, where the information may have evolved or changed.
In front of the construction request to send the message, then we have a good look at how to resolve the server-side sent back the response information.
The first is to use the previous program code to send a request, using the grab Bag tool to see what the answer is:
The first part is the statistics of the return information, indicating that the returned packet data contains a problem,5 authoritative answers, and5 additional information. The second part is the content of the question, the third part is the content of authoritative reply, and the other part is the content of the additional information. Further down is the reception of the original data display, one thing to mention here is to reduce the message, the domain Name system uses a compression method to eliminate the duplication of the domain name in the message. With this method, the name of the field or labels that recurs later is replaced by a pointer to the previous position.
pointer Occupancy 2 bytes, in the following format:
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+--+--+--+--+--+--+--+--+--+--+--+--+--
| 1 1| OFFSET |
+--+--+--+--+--+--+--+--+--+--+--+--+--
the first two bits are1. BecauseLablelslimit to no more than thebytes, solabelthe first two bits must be0, which allows the pointer to belabelbe differentiated. (Tenand the oncombine retention for later use) . Offset value(OFFSET)represents the byte pointer from the beginning of the message. Offset is0representsIDthe first byte of a field.
The compression method allows the domain name in the message to be:
- labels sequence ending with 0
- A pointer
- labels sequence at the end of the pointer
Do not understand the next look, I selected this part is a message in the authoritative record, corresponding to the following selection:
first two bytes' C0 0c 'It was before it came .Baidu.composition of the pointer,' 00 02 'indicates that the returned type isNs,' 00 01 'indicate that it isInternetAgreement,' A3 00 'is aTTL, ' 00 06 'is followed by the length of the content that tells you behind the6bytes are returned to you.NSinformation, you read backwards6bytes The first returned authoritative record is over, look at the back6What is a byte:' 6e c0 c0 'The meaning of this translation comes to be:3dns+A pointer to the content that isbaidu.com), so we can parse outbaidu.coma piece ofNSRecord isdns.baidu.com. Similar to the latter, there is not much to say.
The original rational analysis of things thoroughly, the next section to talk about how to use code to achieve.