00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00041 #ifndef OW32_AsyncResolverDNSMacros_h
00042 #define OW32_AsyncResolverDNSMacros_h
00043
00044 #define DNS__16BIT(p) (((p)[0] << 8) | (p)[1])
00045 #define DNS__32BIT(p) (((p)[0] << 24) | ((p)[1] << 16) | \
00046 ((p)[2] << 8) | (p)[3])
00047 #define DNS__SET16BIT(p, v) (((p)[0] = (unsigned char)((v) >> 8) & 0xff), \
00048 ((p)[1] = (unsigned char)(v) & 0xff))
00049 #define DNS__SET32BIT(p, v) (((p)[0] = (unsigned char)((v) >> 24) & 0xff), \
00050 ((p)[1] = (unsigned char)((v) >> 16) & 0xff), \
00051 ((p)[2] = (unsigned char)((v) >> 8) & 0xff), \
00052 ((p)[3] = (unsigned char)(v) & 0xff))
00053
00054
00055 #define DNS_HEADER_QID(h) DNS__16BIT(h)
00056 #define DNS_HEADER_QR(h) (((h)[2] >> 7) & 0x1)
00057 #define DNS_HEADER_OPCODE(h) (((h)[2] >> 3) & 0xf)
00058 #define DNS_HEADER_AA(h) (((h)[2] >> 2) & 0x1)
00059 #define DNS_HEADER_TC(h) (((h)[2] >> 1) & 0x1)
00060 #define DNS_HEADER_RD(h) ((h)[2] & 0x1)
00061 #define DNS_HEADER_RA(h) (((h)[3] >> 7) & 0x1)
00062 #define DNS_HEADER_Z(h) (((h)[3] >> 4) & 0x7)
00063 #define DNS_HEADER_RCODE(h) ((h)[3] & 0xf)
00064 #define DNS_HEADER_QDCOUNT(h) DNS__16BIT((h) + 4)
00065 #define DNS_HEADER_ANCOUNT(h) DNS__16BIT((h) + 6)
00066 #define DNS_HEADER_NSCOUNT(h) DNS__16BIT((h) + 8)
00067 #define DNS_HEADER_ARCOUNT(h) DNS__16BIT((h) + 10)
00068
00069
00070 #define DNS_HEADER_SET_QID(h, v) DNS__SET16BIT(h, v)
00071 #define DNS_HEADER_SET_QR(h, v) ((h)[2] |= (((v) & 0x1) << 7))
00072 #define DNS_HEADER_SET_OPCODE(h, v) ((h)[2] |= (((v) & 0xf) << 3))
00073 #define DNS_HEADER_SET_AA(h, v) ((h)[2] |= (((v) & 0x1) << 2))
00074 #define DNS_HEADER_SET_TC(h, v) ((h)[2] |= (((v) & 0x1) << 1))
00075 #define DNS_HEADER_SET_RD(h, v) ((h)[2] |= (((v) & 0x1)))
00076 #define DNS_HEADER_SET_RA(h, v) ((h)[3] |= (((v) & 0x1) << 7))
00077 #define DNS_HEADER_SET_Z(h, v) ((h)[3] |= (((v) & 0x7) << 4))
00078 #define DNS_HEADER_SET_RCODE(h, v) ((h)[3] |= (((v) & 0xf)))
00079 #define DNS_HEADER_SET_QDCOUNT(h, v) DNS__SET16BIT((h) + 4, v)
00080 #define DNS_HEADER_SET_ANCOUNT(h, v) DNS__SET16BIT((h) + 6, v)
00081 #define DNS_HEADER_SET_NSCOUNT(h, v) DNS__SET16BIT((h) + 8, v)
00082 #define DNS_HEADER_SET_ARCOUNT(h, v) DNS__SET16BIT((h) + 10, v)
00083
00084
00085 #define DNS_QUESTION_TYPE(q) DNS__16BIT(q)
00086 #define DNS_QUESTION_CLASS(q) DNS__16BIT((q) + 2)
00087
00088
00089 #define DNS_QUESTION_SET_TYPE(q, v) DNS__SET16BIT(q, v)
00090 #define DNS_QUESTION_SET_CLASS(q, v) DNS__SET16BIT((q) + 2, v)
00091
00092
00093 #define DNS_RR_TYPE(r) DNS__16BIT(r)
00094 #define DNS_RR_CLASS(r) DNS__16BIT((r) + 2)
00095 #define DNS_RR_TTL(r) DNS__32BIT((r) + 4)
00096 #define DNS_RR_LEN(r) DNS__16BIT((r) + 8)
00097
00098
00099 #define DNS_RR_SET_TYPE(r) DNS__SET16BIT(r, v)
00100 #define DNS_RR_SET_CLASS(r) DNS__SET16BIT((r) + 2, v)
00101 #define DNS_RR_SET_TTL(r) DNS__SET32BIT((r) + 4, v)
00102 #define DNS_RR_SET_LEN(r) DNS__SET16BIT((r) + 8, v)
00103
00104 #endif