source: trunk/athena/lib/ares/ares_dns.h @ 16485

Revision 16485, 3.5 KB checked in by ghudson, 24 years ago (diff)
Fix (unused) macros which weren't taking a second argument.
Line 
1/* $Id: ares_dns.h,v 1.3 2001-07-30 12:40:26 ghudson Exp $ */
2
3/* Copyright 1998 by the Massachusetts Institute of Technology.
4 *
5 * Permission to use, copy, modify, and distribute this
6 * software and its documentation for any purpose and without
7 * fee is hereby granted, provided that the above copyright
8 * notice appear in all copies and that both that copyright
9 * notice and this permission notice appear in supporting
10 * documentation, and that the name of M.I.T. not be used in
11 * advertising or publicity pertaining to distribution of the
12 * software without specific, written prior permission.
13 * M.I.T. makes no representations about the suitability of
14 * this software for any purpose.  It is provided "as is"
15 * without express or implied warranty.
16 */
17
18#ifndef ARES__DNS_H
19#define ARES__DNS_H
20
21#define DNS__16BIT(p)                   (((p)[0] << 8) | (p)[1])
22#define DNS__32BIT(p)                   (((p)[0] << 24) | ((p)[1] << 16) | \
23                                         ((p)[2] << 8) | (p)[3])
24#define DNS__SET16BIT(p, v)             (((p)[0] = ((v) >> 8) & 0xff), \
25                                         ((p)[1] = (v) & 0xff))
26#define DNS__SET32BIT(p, v)             (((p)[0] = ((v) >> 24) & 0xff), \
27                                         ((p)[1] = ((v) >> 16) & 0xff), \
28                                         ((p)[2] = ((v) >> 8) & 0xff), \
29                                         ((p)[3] = (v) & 0xff))
30
31/* Macros for parsing a DNS header */
32#define DNS_HEADER_QID(h)               DNS__16BIT(h)
33#define DNS_HEADER_QR(h)                (((h)[2] >> 7) & 0x1)
34#define DNS_HEADER_OPCODE(h)            (((h)[2] >> 3) & 0xf)
35#define DNS_HEADER_AA(h)                (((h)[2] >> 2) & 0x1)
36#define DNS_HEADER_TC(h)                (((h)[2] >> 1) & 0x1)
37#define DNS_HEADER_RD(h)                ((h)[2] & 0x1)
38#define DNS_HEADER_RA(h)                (((h)[3] >> 7) & 0x1)
39#define DNS_HEADER_Z(h)                 (((h)[3] >> 4) & 0x7)
40#define DNS_HEADER_RCODE(h)             ((h)[3] & 0xf)
41#define DNS_HEADER_QDCOUNT(h)           DNS__16BIT((h) + 4)
42#define DNS_HEADER_ANCOUNT(h)           DNS__16BIT((h) + 6)
43#define DNS_HEADER_NSCOUNT(h)           DNS__16BIT((h) + 8)
44#define DNS_HEADER_ARCOUNT(h)           DNS__16BIT((h) + 10)
45
46/* Macros for constructing a DNS header */
47#define DNS_HEADER_SET_QID(h, v)        DNS__SET16BIT(h, v)
48#define DNS_HEADER_SET_QR(h, v)         ((h)[2] |= (((v) & 0x1) << 7))
49#define DNS_HEADER_SET_OPCODE(h, v)     ((h)[2] |= (((v) & 0xf) << 3))
50#define DNS_HEADER_SET_AA(h, v)         ((h)[2] |= (((v) & 0x1) << 2))
51#define DNS_HEADER_SET_TC(h, v)         ((h)[2] |= (((v) & 0x1) << 1))
52#define DNS_HEADER_SET_RD(h, v)         ((h)[2] |= (((v) & 0x1)))
53#define DNS_HEADER_SET_RA(h, v)         ((h)[3] |= (((v) & 0x1) << 7))
54#define DNS_HEADER_SET_Z(h, v)          ((h)[3] |= (((v) & 0x7) << 4))
55#define DNS_HEADER_SET_RCODE(h, v)      ((h)[3] |= (((v) & 0xf)))
56#define DNS_HEADER_SET_QDCOUNT(h, v)    DNS__SET16BIT((h) + 4, v)
57#define DNS_HEADER_SET_ANCOUNT(h, v)    DNS__SET16BIT((h) + 6, v)
58#define DNS_HEADER_SET_NSCOUNT(h, v)    DNS__SET16BIT((h) + 8, v)
59#define DNS_HEADER_SET_ARCOUNT(h, v)    DNS__SET16BIT((h) + 10, v)
60
61/* Macros for parsing the fixed part of a DNS question */
62#define DNS_QUESTION_TYPE(q)            DNS__16BIT(q)
63#define DNS_QUESTION_CLASS(q)           DNS__16BIT((q) + 2)
64
65/* Macros for constructing the fixed part of a DNS question */
66#define DNS_QUESTION_SET_TYPE(q, v)     DNS__SET16BIT(q, v)
67#define DNS_QUESTION_SET_CLASS(q, v)    DNS__SET16BIT((q) + 2, v)
68
69/* Macros for parsing the fixed part of a DNS resource record */
70#define DNS_RR_TYPE(r)                  DNS__16BIT(r)
71#define DNS_RR_CLASS(r)                 DNS__16BIT((r) + 2)
72#define DNS_RR_TTL(r)                   DNS__32BIT((r) + 4)
73#define DNS_RR_LEN(r)                   DNS__16BIT((r) + 8)
74
75/* Macros for constructing the fixed part of a DNS resource record */
76#define DNS_RR_SET_TYPE(r, v)           DNS__SET16BIT(r, v)
77#define DNS_RR_SET_CLASS(r, v)          DNS__SET16BIT((r) + 2, v)
78#define DNS_RR_SET_TTL(r, v)            DNS__SET32BIT((r) + 4, v)
79#define DNS_RR_SET_LEN(r, v)            DNS__SET16BIT((r) + 8, v)
80
81#endif /* ARES__DNS_H */
Note: See TracBrowser for help on using the repository browser.