Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

AsyncResolverDNSMacros.h

Go to the documentation of this file.
00001 /*  AsyncResolverError.h - DNS parsing macros
00002     Copyright (C) 2004 Mark Weaver
00003     Written by Mark Weaver <mark@npsl.co.uk>
00004 
00005     Part of the Open-Win32 library.
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Library General Public License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public
00017     License along with this library; if not, write to the
00018     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019     Boston, MA  02111-1307, USA.
00020 */
00021 
00022 /* Copyright 1998 by the Massachusetts Institute of Technology.
00023  *
00024  * Permission to use, copy, modify, and distribute this
00025  * software and its documentation for any purpose and without
00026  * fee is hereby granted, provided that the above copyright
00027  * notice appear in all copies and that both that copyright
00028  * notice and this permission notice appear in supporting
00029  * documentation, and that the name of M.I.T. not be used in
00030  * advertising or publicity pertaining to distribution of the
00031  * software without specific, written prior permission.
00032  * M.I.T. makes no representations about the suitability of
00033  * this software for any purpose.  It is provided "as is"
00034  * without express or implied warranty.
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 /* Macros for parsing a DNS header */
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 /* Macros for constructing a DNS header */
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 /* Macros for parsing the fixed part of a DNS question */
00085 #define DNS_QUESTION_TYPE(q)            DNS__16BIT(q)
00086 #define DNS_QUESTION_CLASS(q)           DNS__16BIT((q) + 2)
00087 
00088 /* Macros for constructing the fixed part of a DNS question */
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 /* Macros for parsing the fixed part of a DNS resource record */
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 /* Macros for constructing the fixed part of a DNS resource record */
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 /* OW32_AsyncResolverDNSMacros_h */

Generated on Sun Jun 5 01:29:17 2005 for OW32 by  doxygen 1.3.9.1