hinfo_13.c revision 1.6
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: hinfo_13.c,v 1.6 2020/02/24 17:43:52 florian Exp $ */ 18 19/* 20 * Reviewed: Wed Mar 15 16:47:10 PST 2000 by halley. 21 */ 22 23#ifndef RDATA_GENERIC_HINFO_13_C 24#define RDATA_GENERIC_HINFO_13_C 25 26#define RRTYPE_HINFO_ATTRIBUTES (0) 27 28static inline isc_result_t 29totext_hinfo(ARGS_TOTEXT) { 30 isc_region_t region; 31 32 UNUSED(tctx); 33 34 REQUIRE(rdata->type == dns_rdatatype_hinfo); 35 REQUIRE(rdata->length != 0); 36 37 dns_rdata_toregion(rdata, ®ion); 38 RETERR(txt_totext(®ion, ISC_TRUE, target)); 39 RETERR(str_totext(" ", target)); 40 return (txt_totext(®ion, ISC_TRUE, target)); 41} 42 43static inline isc_result_t 44fromwire_hinfo(ARGS_FROMWIRE) { 45 46 REQUIRE(type == dns_rdatatype_hinfo); 47 48 UNUSED(type); 49 UNUSED(dctx); 50 UNUSED(rdclass); 51 UNUSED(options); 52 53 RETERR(txt_fromwire(source, target)); 54 return (txt_fromwire(source, target)); 55} 56 57static inline isc_result_t 58towire_hinfo(ARGS_TOWIRE) { 59 60 UNUSED(cctx); 61 62 REQUIRE(rdata->type == dns_rdatatype_hinfo); 63 REQUIRE(rdata->length != 0); 64 65 return (mem_tobuffer(target, rdata->data, rdata->length)); 66} 67 68 69static inline isc_result_t 70fromstruct_hinfo(ARGS_FROMSTRUCT) { 71 dns_rdata_hinfo_t *hinfo = source; 72 73 REQUIRE(type == dns_rdatatype_hinfo); 74 REQUIRE(source != NULL); 75 REQUIRE(hinfo->common.rdtype == type); 76 REQUIRE(hinfo->common.rdclass == rdclass); 77 78 UNUSED(type); 79 UNUSED(rdclass); 80 81 RETERR(uint8_tobuffer(hinfo->cpu_len, target)); 82 RETERR(mem_tobuffer(target, hinfo->cpu, hinfo->cpu_len)); 83 RETERR(uint8_tobuffer(hinfo->os_len, target)); 84 return (mem_tobuffer(target, hinfo->os, hinfo->os_len)); 85} 86 87static inline isc_result_t 88tostruct_hinfo(ARGS_TOSTRUCT) { 89 dns_rdata_hinfo_t *hinfo = target; 90 isc_region_t region; 91 92 REQUIRE(rdata->type == dns_rdatatype_hinfo); 93 REQUIRE(target != NULL); 94 REQUIRE(rdata->length != 0); 95 96 hinfo->common.rdclass = rdata->rdclass; 97 hinfo->common.rdtype = rdata->type; 98 ISC_LINK_INIT(&hinfo->common, link); 99 100 dns_rdata_toregion(rdata, ®ion); 101 hinfo->cpu_len = uint8_fromregion(®ion); 102 isc_region_consume(®ion, 1); 103 hinfo->cpu = mem_maybedup(region.base, hinfo->cpu_len); 104 if (hinfo->cpu == NULL) 105 return (ISC_R_NOMEMORY); 106 isc_region_consume(®ion, hinfo->cpu_len); 107 108 hinfo->os_len = uint8_fromregion(®ion); 109 isc_region_consume(®ion, 1); 110 hinfo->os = mem_maybedup(region.base, hinfo->os_len); 111 if (hinfo->os == NULL) 112 goto cleanup; 113 114 return (ISC_R_SUCCESS); 115 116 cleanup: 117 free(hinfo->cpu); 118 return (ISC_R_NOMEMORY); 119} 120 121 122 123#endif /* RDATA_GENERIC_HINFO_13_C */ 124