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 #ifndef RDATA_GENERIC_SINK_40_C 18 #define RDATA_GENERIC_SINK_40_C 19 20 #include <dst/dst.h> 21 22 static inline isc_result_t 23 totext_sink(ARGS_TOTEXT) { 24 isc_region_t sr; 25 char buf[sizeof("255 255 255")]; 26 uint8_t meaning, coding, subcoding; 27 28 REQUIRE(rdata->type == dns_rdatatype_sink); 29 REQUIRE(rdata->length >= 3); 30 31 dns_rdata_toregion(rdata, &sr); 32 33 /* Meaning, Coding and Subcoding */ 34 meaning = uint8_fromregion(&sr); 35 isc_region_consume(&sr, 1); 36 coding = uint8_fromregion(&sr); 37 isc_region_consume(&sr, 1); 38 subcoding = uint8_fromregion(&sr); 39 isc_region_consume(&sr, 1); 40 snprintf(buf, sizeof(buf), "%u %u %u", meaning, coding, subcoding); 41 RETERR(isc_str_tobuffer(buf, target)); 42 43 if (sr.length == 0U) 44 return (ISC_R_SUCCESS); 45 46 /* data */ 47 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) 48 RETERR(isc_str_tobuffer(" (", target)); 49 50 RETERR(isc_str_tobuffer(tctx->linebreak, target)); 51 52 if (tctx->width == 0) /* No splitting */ 53 RETERR(isc_base64_totext(&sr, 60, "", target)); 54 else 55 RETERR(isc_base64_totext(&sr, tctx->width - 2, 56 tctx->linebreak, target)); 57 58 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) 59 RETERR(isc_str_tobuffer(" )", target)); 60 61 return (ISC_R_SUCCESS); 62 } 63 64 static inline isc_result_t 65 fromwire_sink(ARGS_FROMWIRE) { 66 isc_region_t sr; 67 68 REQUIRE(type == dns_rdatatype_sink); 69 70 UNUSED(type); 71 UNUSED(rdclass); 72 UNUSED(dctx); 73 UNUSED(options); 74 75 isc_buffer_activeregion(source, &sr); 76 if (sr.length < 3) 77 return (ISC_R_UNEXPECTEDEND); 78 79 RETERR(isc_mem_tobuffer(target, sr.base, sr.length)); 80 isc_buffer_forward(source, sr.length); 81 return (ISC_R_SUCCESS); 82 } 83 84 static inline isc_result_t 85 towire_sink(ARGS_TOWIRE) { 86 87 REQUIRE(rdata->type == dns_rdatatype_sink); 88 REQUIRE(rdata->length >= 3); 89 90 UNUSED(cctx); 91 92 return (isc_mem_tobuffer(target, rdata->data, rdata->length)); 93 } 94 95 #endif /* RDATA_GENERIC_SINK_40_C */ 96