Add BIND 9.2.4rc7.
[dragonfly.git] / contrib / bind-9.2.4rc7 / lib / dns / soa.c
blob1b88efec1411d058da9cccacf7bbaa482de6ec55
1 /*
2 * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 2000, 2001 Internet Software Consortium.
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: soa.c,v 1.3.2.1 2004/03/09 06:11:08 marka Exp $ */
20 #include <config.h>
22 #include <isc/util.h>
24 #include <dns/rdata.h>
25 #include <dns/soa.h>
27 static inline isc_uint32_t
28 decode_uint32(unsigned char *p) {
29 return ((p[0] << 24) +
30 (p[1] << 16) +
31 (p[2] << 8) +
32 (p[3] << 0));
35 static inline void
36 encode_uint32(isc_uint32_t val, unsigned char *p) {
37 p[0] = (isc_uint8_t)(val >> 24);
38 p[1] = (isc_uint8_t)(val >> 16);
39 p[2] = (isc_uint8_t)(val >> 8);
40 p[3] = (isc_uint8_t)(val >> 0);
43 static isc_uint32_t
44 soa_get(dns_rdata_t *rdata, int offset) {
45 INSIST(rdata->type == dns_rdatatype_soa);
47 * Locate the field within the SOA RDATA based
48 * on its position relative to the end of the data.
50 * This is a bit of a kludge, but the alternative approach of
51 * using dns_rdata_tostruct() and dns_rdata_fromstruct() would
52 * involve a lot of unnecessary work (like building domain
53 * names and allocating temporary memory) when all we really
54 * want to do is to get 32 bits of fixed-sized data.
56 INSIST(rdata->length >= 20);
57 INSIST(offset >= 0 && offset <= 16);
58 return (decode_uint32(rdata->data + rdata->length - 20 + offset));
61 isc_uint32_t
62 dns_soa_getserial(dns_rdata_t *rdata) {
63 return soa_get(rdata, 0);
65 isc_uint32_t
66 dns_soa_getrefresh(dns_rdata_t *rdata) {
67 return soa_get(rdata, 4);
69 isc_uint32_t
70 dns_soa_getretry(dns_rdata_t *rdata) {
71 return soa_get(rdata, 8);
73 isc_uint32_t
74 dns_soa_getexpire(dns_rdata_t *rdata) {
75 return soa_get(rdata, 12);
77 isc_uint32_t
78 dns_soa_getminimum(dns_rdata_t *rdata) {
79 return soa_get(rdata, 16);
82 static void
83 soa_set(dns_rdata_t *rdata, isc_uint32_t val, int offset) {
84 INSIST(rdata->type == dns_rdatatype_soa);
85 INSIST(rdata->length >= 20);
86 INSIST(offset >= 0 && offset <= 16);
87 encode_uint32(val, rdata->data + rdata->length - 20 + offset);
90 void
91 dns_soa_setserial(isc_uint32_t val, dns_rdata_t *rdata) {
92 soa_set(rdata, val, 0);
94 void
95 dns_soa_setrefresh(isc_uint32_t val, dns_rdata_t *rdata) {
96 soa_set(rdata, val, 4);
98 void
99 dns_soa_setretry(isc_uint32_t val, dns_rdata_t *rdata) {
100 soa_set(rdata, val, 8);
102 void
103 dns_soa_setexpire(isc_uint32_t val, dns_rdata_t *rdata) {
104 soa_set(rdata, val, 12);
106 void
107 dns_soa_setminimum(isc_uint32_t val, dns_rdata_t *rdata) {
108 soa_set(rdata, val, 16);