Closed PonchoPowers closed 5 years ago
Thanks for the feedback. I respectfully disagree that this code requires refactoring.
The code implementation is based on section 4.1.4. Message compression of RFC 1035 DNS standard specification which is what the code is doing.
Any programmer who is trying to edit this code thus requires reading the RFC in advance to understand the implementation. 0xC0 in hex equals 11000000 in binary which the domain name pointer requires as per message compression pointer format:
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| 1 1| OFFSET |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
My point is mainly this, if you define constants for these codes, people will understand the code better.
Take a look at the following for example: https://github.com/isc-projects/bind9/blob/fa03f941027cdcccc060613f773e63701b5baa77/doc/design/dscp
#define ISC_NET_DSCPRECVV6 0x02 /* Can receive sent DSCP value IPv6 */
#define ISC_NET_DSCPSETV4 0x04 /* Can set DSCP on socket IPv4 */
#define ISC_NET_DSCPSETV6 0x08 /* Can set DSCP on socket IPv6 */
#define ISC_NET_DSCPPKTV4 0x10 /* Can set DSCP on per packet IPv4 */
#define ISC_NET_DSCPPKTV6 0x20 /* Can set DSCP on per packet IPv6 */
#define ISC_NET_DSCPALL 0x3f /* All valid flags */
By using ISC_NET_DSCPALL
rather than 0x3f
is much more insightful. And then if needed, you can even comment on what 0x3f
is referring to.
Fair point.
Code such as:
if ((labelLength & 0xC0) == 0xC0)
Should be refactored to make it easier to understand.
What exactly is this code supposed to be doing?