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.10 2020/02/26 18:38:15 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 26 #include <isc/net.h> 27 28 static inline isc_result_t 29 totext_in_a(ARGS_TOTEXT) { 30 isc_region_t region; 31 32 REQUIRE(rdata->type == dns_rdatatype_a); 33 REQUIRE(rdata->rdclass == dns_rdataclass_in); 34 REQUIRE(rdata->length == 4); 35 36 UNUSED(tctx); 37 38 dns_rdata_toregion(rdata, ®ion); 39 return (inet_totext(AF_INET, ®ion, target)); 40 } 41 42 static inline isc_result_t 43 fromwire_in_a(ARGS_FROMWIRE) { 44 isc_region_t sregion; 45 isc_region_t tregion; 46 47 REQUIRE(type == dns_rdatatype_a); 48 REQUIRE(rdclass == dns_rdataclass_in); 49 50 UNUSED(type); 51 UNUSED(dctx); 52 UNUSED(options); 53 UNUSED(rdclass); 54 55 isc_buffer_activeregion(source, &sregion); 56 isc_buffer_availableregion(target, &tregion); 57 if (sregion.length < 4) 58 return (ISC_R_UNEXPECTEDEND); 59 if (tregion.length < 4) 60 return (ISC_R_NOSPACE); 61 62 memmove(tregion.base, sregion.base, 4); 63 isc_buffer_forward(source, 4); 64 isc_buffer_add(target, 4); 65 return (ISC_R_SUCCESS); 66 } 67 68 static inline isc_result_t 69 towire_in_a(ARGS_TOWIRE) { 70 isc_region_t region; 71 72 REQUIRE(rdata->type == dns_rdatatype_a); 73 REQUIRE(rdata->rdclass == dns_rdataclass_in); 74 REQUIRE(rdata->length == 4); 75 76 UNUSED(cctx); 77 78 isc_buffer_availableregion(target, ®ion); 79 if (region.length < rdata->length) 80 return (ISC_R_NOSPACE); 81 memmove(region.base, rdata->data, rdata->length); 82 isc_buffer_add(target, 4); 83 return (ISC_R_SUCCESS); 84 } 85 86 #endif /* RDATA_IN_1_A_1_C */ 87