1 /*
2 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
13 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14 * PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 /* $Id: a_1.c,v 1.11 2020/09/14 08:39:12 florian Exp $ */
18
19 /* Reviewed: Thu Mar 16 16:52:50 PST 2000 by bwelling */
20
21 #ifndef RDATA_IN_1_A_1_C
22 #define RDATA_IN_1_A_1_C
23
24 #include <string.h>
25 #include <sys/socket.h>
26
27 static inline isc_result_t
totext_in_a(ARGS_TOTEXT)28 totext_in_a(ARGS_TOTEXT) {
29 isc_region_t region;
30
31 REQUIRE(rdata->type == dns_rdatatype_a);
32 REQUIRE(rdata->rdclass == dns_rdataclass_in);
33 REQUIRE(rdata->length == 4);
34
35 UNUSED(tctx);
36
37 dns_rdata_toregion(rdata, ®ion);
38 return (inet_totext(AF_INET, ®ion, target));
39 }
40
41 static inline isc_result_t
fromwire_in_a(ARGS_FROMWIRE)42 fromwire_in_a(ARGS_FROMWIRE) {
43 isc_region_t sregion;
44 isc_region_t tregion;
45
46 REQUIRE(type == dns_rdatatype_a);
47 REQUIRE(rdclass == dns_rdataclass_in);
48
49 UNUSED(type);
50 UNUSED(dctx);
51 UNUSED(options);
52 UNUSED(rdclass);
53
54 isc_buffer_activeregion(source, &sregion);
55 isc_buffer_availableregion(target, &tregion);
56 if (sregion.length < 4)
57 return (ISC_R_UNEXPECTEDEND);
58 if (tregion.length < 4)
59 return (ISC_R_NOSPACE);
60
61 memmove(tregion.base, sregion.base, 4);
62 isc_buffer_forward(source, 4);
63 isc_buffer_add(target, 4);
64 return (ISC_R_SUCCESS);
65 }
66
67 static inline isc_result_t
towire_in_a(ARGS_TOWIRE)68 towire_in_a(ARGS_TOWIRE) {
69 isc_region_t region;
70
71 REQUIRE(rdata->type == dns_rdatatype_a);
72 REQUIRE(rdata->rdclass == dns_rdataclass_in);
73 REQUIRE(rdata->length == 4);
74
75 UNUSED(cctx);
76
77 isc_buffer_availableregion(target, ®ion);
78 if (region.length < rdata->length)
79 return (ISC_R_NOSPACE);
80 memmove(region.base, rdata->data, rdata->length);
81 isc_buffer_add(target, 4);
82 return (ISC_R_SUCCESS);
83 }
84
85 #endif /* RDATA_IN_1_A_1_C */
86