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 $ */
24 #include <dns/rdata.h>
27 static inline isc_uint32_t
28 decode_uint32(unsigned char *p
) {
29 return ((p
[0] << 24) +
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);
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
));
62 dns_soa_getserial(dns_rdata_t
*rdata
) {
63 return soa_get(rdata
, 0);
66 dns_soa_getrefresh(dns_rdata_t
*rdata
) {
67 return soa_get(rdata
, 4);
70 dns_soa_getretry(dns_rdata_t
*rdata
) {
71 return soa_get(rdata
, 8);
74 dns_soa_getexpire(dns_rdata_t
*rdata
) {
75 return soa_get(rdata
, 12);
78 dns_soa_getminimum(dns_rdata_t
*rdata
) {
79 return soa_get(rdata
, 16);
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
);
91 dns_soa_setserial(isc_uint32_t val
, dns_rdata_t
*rdata
) {
92 soa_set(rdata
, val
, 0);
95 dns_soa_setrefresh(isc_uint32_t val
, dns_rdata_t
*rdata
) {
96 soa_set(rdata
, val
, 4);
99 dns_soa_setretry(isc_uint32_t val
, dns_rdata_t
*rdata
) {
100 soa_set(rdata
, val
, 8);
103 dns_soa_setexpire(isc_uint32_t val
, dns_rdata_t
*rdata
) {
104 soa_set(rdata
, val
, 12);
107 dns_soa_setminimum(isc_uint32_t val
, dns_rdata_t
*rdata
) {
108 soa_set(rdata
, val
, 16);