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_LP_107_C 18 #define RDATA_GENERIC_LP_107_C 19 20 #include <string.h> 21 22 static inline isc_result_t 23 totext_lp(ARGS_TOTEXT) { 24 isc_region_t region; 25 dns_name_t name; 26 dns_name_t prefix; 27 int sub; 28 char buf[sizeof("64000")]; 29 unsigned short num; 30 31 REQUIRE(rdata->type == dns_rdatatype_lp); 32 REQUIRE(rdata->length != 0); 33 34 dns_name_init(&name, NULL); 35 dns_name_init(&prefix, NULL); 36 37 dns_rdata_toregion(rdata, ®ion); 38 num = uint16_fromregion(®ion); 39 isc_region_consume(®ion, 2); 40 snprintf(buf, sizeof(buf), "%u", num); 41 RETERR(isc_str_tobuffer(buf, target)); 42 43 RETERR(isc_str_tobuffer(" ", target)); 44 45 dns_name_fromregion(&name, ®ion); 46 sub = name_prefix(&name, tctx->origin, &prefix); 47 return (dns_name_totext(&prefix, sub, target)); 48 } 49 50 static inline isc_result_t 51 fromwire_lp(ARGS_FROMWIRE) { 52 dns_name_t name; 53 isc_region_t sregion; 54 55 REQUIRE(type == dns_rdatatype_lp); 56 57 UNUSED(type); 58 UNUSED(rdclass); 59 60 dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14); 61 62 dns_name_init(&name, NULL); 63 64 isc_buffer_activeregion(source, &sregion); 65 if (sregion.length < 2) 66 return (ISC_R_UNEXPECTEDEND); 67 RETERR(isc_mem_tobuffer(target, sregion.base, 2)); 68 isc_buffer_forward(source, 2); 69 return (dns_name_fromwire(&name, source, dctx, options, target)); 70 } 71 72 static inline isc_result_t 73 towire_lp(ARGS_TOWIRE) { 74 75 REQUIRE(rdata->type == dns_rdatatype_lp); 76 REQUIRE(rdata->length != 0); 77 78 UNUSED(cctx); 79 80 return (isc_mem_tobuffer(target, rdata->data, rdata->length)); 81 } 82 83 #endif /* RDATA_GENERIC_LP_107_C */ 84