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_L64_106_C 18 #define RDATA_GENERIC_L64_106_C 19 20 #include <string.h> 21 22 static inline isc_result_t 23 totext_l64(ARGS_TOTEXT) { 24 isc_region_t region; 25 char buf[sizeof("xxxx:xxxx:xxxx:xxxx")]; 26 unsigned short num; 27 28 REQUIRE(rdata->type == dns_rdatatype_l64); 29 REQUIRE(rdata->length == 10); 30 31 UNUSED(tctx); 32 33 dns_rdata_toregion(rdata, ®ion); 34 num = uint16_fromregion(®ion); 35 isc_region_consume(®ion, 2); 36 snprintf(buf, sizeof(buf), "%u", num); 37 RETERR(isc_str_tobuffer(buf, target)); 38 39 RETERR(isc_str_tobuffer(" ", target)); 40 41 snprintf(buf, sizeof(buf), "%x:%x:%x:%x", 42 region.base[0]<<8 | region.base[1], 43 region.base[2]<<8 | region.base[3], 44 region.base[4]<<8 | region.base[5], 45 region.base[6]<<8 | region.base[7]); 46 return (isc_str_tobuffer(buf, target)); 47 } 48 49 static inline isc_result_t 50 fromwire_l64(ARGS_FROMWIRE) { 51 isc_region_t sregion; 52 53 REQUIRE(type == dns_rdatatype_l64); 54 55 UNUSED(type); 56 UNUSED(options); 57 UNUSED(rdclass); 58 UNUSED(dctx); 59 60 isc_buffer_activeregion(source, &sregion); 61 if (sregion.length != 10) 62 return (DNS_R_FORMERR); 63 isc_buffer_forward(source, sregion.length); 64 return (isc_mem_tobuffer(target, sregion.base, sregion.length)); 65 } 66 67 static inline isc_result_t 68 towire_l64(ARGS_TOWIRE) { 69 70 REQUIRE(rdata->type == dns_rdatatype_l64); 71 REQUIRE(rdata->length == 10); 72 73 UNUSED(cctx); 74 75 return (isc_mem_tobuffer(target, rdata->data, rdata->length)); 76 } 77 78 #endif /* RDATA_GENERIC_L64_106_C */ 79