Detect FPU by checking CPUID features.
[dragonfly.git] / contrib / bind-9.5.2 / lib / dns / soa.c
blob83a1c1790e3c18c5946312bdf69f2d2dd1ec2edb
1 /*
2 * Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 2000, 2001 Internet Software Consortium.
5 * Permission to use, copy, modify, and/or 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.8 2007/06/19 23:47:16 tbox Exp $ */
20 /*! \file */
22 #include <config.h>
24 #include <isc/util.h>
26 #include <dns/rdata.h>
27 #include <dns/soa.h>
29 static inline isc_uint32_t
30 decode_uint32(unsigned char *p) {
31 return ((p[0] << 24) +
32 (p[1] << 16) +
33 (p[2] << 8) +
34 (p[3] << 0));
37 static inline void
38 encode_uint32(isc_uint32_t val, unsigned char *p) {
39 p[0] = (isc_uint8_t)(val >> 24);
40 p[1] = (isc_uint8_t)(val >> 16);
41 p[2] = (isc_uint8_t)(val >> 8);
42 p[3] = (isc_uint8_t)(val >> 0);
45 static isc_uint32_t
46 soa_get(dns_rdata_t *rdata, int offset) {
47 INSIST(rdata->type == dns_rdatatype_soa);
49 * Locate the field within the SOA RDATA based
50 * on its position relative to the end of the data.
52 * This is a bit of a kludge, but the alternative approach of
53 * using dns_rdata_tostruct() and dns_rdata_fromstruct() would
54 * involve a lot of unnecessary work (like building domain
55 * names and allocating temporary memory) when all we really
56 * want to do is to get 32 bits of fixed-sized data.
58 INSIST(rdata->length >= 20);
59 INSIST(offset >= 0 && offset <= 16);
60 return (decode_uint32(rdata->data + rdata->length - 20 + offset));
63 isc_uint32_t
64 dns_soa_getserial(dns_rdata_t *rdata) {
65 return soa_get(rdata, 0);
67 isc_uint32_t
68 dns_soa_getrefresh(dns_rdata_t *rdata) {
69 return soa_get(rdata, 4);
71 isc_uint32_t
72 dns_soa_getretry(dns_rdata_t *rdata) {
73 return soa_get(rdata, 8);
75 isc_uint32_t
76 dns_soa_getexpire(dns_rdata_t *rdata) {
77 return soa_get(rdata, 12);
79 isc_uint32_t
80 dns_soa_getminimum(dns_rdata_t *rdata) {
81 return soa_get(rdata, 16);
84 static void
85 soa_set(dns_rdata_t *rdata, isc_uint32_t val, int offset) {
86 INSIST(rdata->type == dns_rdatatype_soa);
87 INSIST(rdata->length >= 20);
88 INSIST(offset >= 0 && offset <= 16);
89 encode_uint32(val, rdata->data + rdata->length - 20 + offset);
92 void
93 dns_soa_setserial(isc_uint32_t val, dns_rdata_t *rdata) {
94 soa_set(rdata, val, 0);
96 void
97 dns_soa_setrefresh(isc_uint32_t val, dns_rdata_t *rdata) {
98 soa_set(rdata, val, 4);
100 void
101 dns_soa_setretry(isc_uint32_t val, dns_rdata_t *rdata) {
102 soa_set(rdata, val, 8);
104 void
105 dns_soa_setexpire(isc_uint32_t val, dns_rdata_t *rdata) {
106 soa_set(rdata, val, 12);
108 void
109 dns_soa_setminimum(isc_uint32_t val, dns_rdata_t *rdata) {
110 soa_set(rdata, val, 16);