Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

ares_dns.h

Go to the documentation of this file.
00001 /* $Id: ares_dns.h,v 1.2 2000/02/17 18:38:16 ghudson Exp $ */
00002 
00003 /* Copyright 1998 by the Massachusetts Institute of Technology.
00004  *
00005  * Permission to use, copy, modify, and distribute this
00006  * software and its documentation for any purpose and without
00007  * fee is hereby granted, provided that the above copyright
00008  * notice appear in all copies and that both that copyright
00009  * notice and this permission notice appear in supporting
00010  * documentation, and that the name of M.I.T. not be used in
00011  * advertising or publicity pertaining to distribution of the
00012  * software without specific, written prior permission.
00013  * M.I.T. makes no representations about the suitability of
00014  * this software for any purpose.  It is provided "as is"
00015  * without express or implied warranty.
00016  *
00017  * CHANGELOG: this file has been modified by Sergio Perez Alcañiz <serpeal@disca.upv.es> 
00018  *            Departamento de Informática de Sistemas y Computadores          
00019  *            Universidad Politécnica de Valencia                             
00020  *            Valencia (Spain)    
00021  *            Date: April 2003                                          
00022  *
00023  */
00024 
00025 #ifndef ARES__DNS_H
00026 #define ARES__DNS_H
00027 
00028 #define DNS__16BIT(p)                   (((p)[0] << 8) | (p)[1])
00029 #define DNS__32BIT(p)                   (((p)[0] << 24) | ((p)[1] << 16) | \
00030                                          ((p)[2] << 8) | (p)[3])
00031 #define DNS__SET16BIT(p, v)             (((p)[0] = ((v) >> 8) & 0xff), \
00032                                          ((p)[1] = (v) & 0xff))
00033 #define DNS__SET32BIT(p, v)             (((p)[0] = ((v) >> 24) & 0xff), \
00034                                          ((p)[1] = ((v) >> 16) & 0xff), \
00035                                          ((p)[2] = ((v) >> 8) & 0xff), \
00036                                          ((p)[3] = (v) & 0xff))
00037 
00038 /* Macros for parsing a DNS header */
00039 #define DNS_HEADER_QID(h)               DNS__16BIT(h)
00040 #define DNS_HEADER_QR(h)                (((h)[2] >> 7) & 0x1)
00041 #define DNS_HEADER_OPCODE(h)            (((h)[2] >> 3) & 0xf)
00042 #define DNS_HEADER_AA(h)                (((h)[2] >> 2) & 0x1)
00043 #define DNS_HEADER_TC(h)                (((h)[2] >> 1) & 0x1)
00044 #define DNS_HEADER_RD(h)                ((h)[2] & 0x1)
00045 #define DNS_HEADER_RA(h)                (((h)[3] >> 7) & 0x1)
00046 #define DNS_HEADER_Z(h)                 (((h)[3] >> 4) & 0x7)
00047 #define DNS_HEADER_RCODE(h)             ((h)[3] & 0xf)
00048 #define DNS_HEADER_QDCOUNT(h)           DNS__16BIT((h) + 4)
00049 #define DNS_HEADER_ANCOUNT(h)           DNS__16BIT((h) + 6)
00050 #define DNS_HEADER_NSCOUNT(h)           DNS__16BIT((h) + 8)
00051 #define DNS_HEADER_ARCOUNT(h)           DNS__16BIT((h) + 10)
00052 
00053 /* Macros for constructing a DNS header */
00054 #define DNS_HEADER_SET_QID(h, v)        DNS__SET16BIT(h, v)
00055 #define DNS_HEADER_SET_QR(h, v)         ((h)[2] |= (((v) & 0x1) << 7))
00056 #define DNS_HEADER_SET_OPCODE(h, v)     ((h)[2] |= (((v) & 0xf) << 3))
00057 #define DNS_HEADER_SET_AA(h, v)         ((h)[2] |= (((v) & 0x1) << 2))
00058 #define DNS_HEADER_SET_TC(h, v)         ((h)[2] |= (((v) & 0x1) << 1))
00059 #define DNS_HEADER_SET_RD(h, v)         ((h)[2] |= (((v) & 0x1)))
00060 #define DNS_HEADER_SET_RA(h, v)         ((h)[3] |= (((v) & 0x1) << 7))
00061 #define DNS_HEADER_SET_Z(h, v)          ((h)[3] |= (((v) & 0x7) << 4))
00062 #define DNS_HEADER_SET_RCODE(h, v)      ((h)[3] |= (((v) & 0xf)))
00063 #define DNS_HEADER_SET_QDCOUNT(h, v)    DNS__SET16BIT((h) + 4, v)
00064 #define DNS_HEADER_SET_ANCOUNT(h, v)    DNS__SET16BIT((h) + 6, v)
00065 #define DNS_HEADER_SET_NSCOUNT(h, v)    DNS__SET16BIT((h) + 8, v)
00066 #define DNS_HEADER_SET_ARCOUNT(h, v)    DNS__SET16BIT((h) + 10, v)
00067 
00068 /* Macros for parsing the fixed part of a DNS question */
00069 #define DNS_QUESTION_TYPE(q)            DNS__16BIT(q)
00070 #define DNS_QUESTION_CLASS(q)           DNS__16BIT((q) + 2)
00071 
00072 /* Macros for constructing the fixed part of a DNS question */
00073 #define DNS_QUESTION_SET_TYPE(q, v)     DNS__SET16BIT(q, v)
00074 #define DNS_QUESTION_SET_CLASS(q, v)    DNS__SET16BIT((q) + 2, v)
00075 
00076 /* Macros for parsing the fixed part of a DNS resource record */
00077 #define DNS_RR_TYPE(r)                  DNS__16BIT(r)
00078 #define DNS_RR_CLASS(r)                 DNS__16BIT((r) + 2)
00079 #define DNS_RR_TTL(r)                   DNS__32BIT((r) + 4)
00080 #define DNS_RR_LEN(r)                   DNS__16BIT((r) + 8)
00081 
00082 /* Macros for constructing the fixed part of a DNS resource record */
00083 #define DNS_RR_SET_TYPE(r)              DNS__SET16BIT(r, v)
00084 #define DNS_RR_SET_CLASS(r)             DNS__SET16BIT((r) + 2, v)
00085 #define DNS_RR_SET_TTL(r)               DNS__SET32BIT((r) + 4, v)
00086 #define DNS_RR_SET_LEN(r)               DNS__SET16BIT((r) + 8, v)
00087 
00088 #endif /* ARES__DNS_H */

Generated on Wed Jan 14 12:58:55 2004 for RTL-lwIP-0.4 by doxygen 1.3.4