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: kx_36.c,v 1.13 2020/09/14 08:40:44 florian Exp $ */
18
19 /* Reviewed: Thu Mar 16 17:24:54 PST 2000 by explorer */
20
21 /* RFC2230 */
22
23 #ifndef RDATA_IN_1_KX_36_C
24 #define RDATA_IN_1_KX_36_C
25
26 static inline isc_result_t
totext_in_kx(ARGS_TOTEXT)27 totext_in_kx(ARGS_TOTEXT) {
28 isc_region_t region;
29 dns_name_t name;
30 dns_name_t prefix;
31 int sub;
32 char buf[sizeof("64000")];
33 unsigned short num;
34
35 REQUIRE(rdata->type == dns_rdatatype_kx);
36 REQUIRE(rdata->rdclass == dns_rdataclass_in);
37 REQUIRE(rdata->length != 0);
38
39 dns_name_init(&name, NULL);
40 dns_name_init(&prefix, NULL);
41
42 dns_rdata_toregion(rdata, ®ion);
43 num = uint16_fromregion(®ion);
44 isc_region_consume(®ion, 2);
45 snprintf(buf, sizeof(buf), "%u", num);
46 RETERR(isc_str_tobuffer(buf, target));
47
48 RETERR(isc_str_tobuffer(" ", target));
49
50 dns_name_fromregion(&name, ®ion);
51 sub = name_prefix(&name, tctx->origin, &prefix);
52 return (dns_name_totext(&prefix, sub, target));
53 }
54
55 static inline isc_result_t
fromwire_in_kx(ARGS_FROMWIRE)56 fromwire_in_kx(ARGS_FROMWIRE) {
57 dns_name_t name;
58 isc_region_t sregion;
59
60 REQUIRE(type == dns_rdatatype_kx);
61 REQUIRE(rdclass == dns_rdataclass_in);
62
63 UNUSED(type);
64 UNUSED(rdclass);
65
66 dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
67
68 dns_name_init(&name, NULL);
69
70 isc_buffer_activeregion(source, &sregion);
71 if (sregion.length < 2)
72 return (ISC_R_UNEXPECTEDEND);
73 RETERR(isc_mem_tobuffer(target, sregion.base, 2));
74 isc_buffer_forward(source, 2);
75 return (dns_name_fromwire(&name, source, dctx, options, target));
76 }
77
78 static inline isc_result_t
towire_in_kx(ARGS_TOWIRE)79 towire_in_kx(ARGS_TOWIRE) {
80 dns_name_t name;
81 dns_offsets_t offsets;
82 isc_region_t region;
83
84 REQUIRE(rdata->type == dns_rdatatype_kx);
85 REQUIRE(rdata->rdclass == dns_rdataclass_in);
86 REQUIRE(rdata->length != 0);
87
88 dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
89 dns_rdata_toregion(rdata, ®ion);
90 RETERR(isc_mem_tobuffer(target, region.base, 2));
91 isc_region_consume(®ion, 2);
92
93 dns_name_init(&name, offsets);
94 dns_name_fromregion(&name, ®ion);
95
96 return (dns_name_towire(&name, cctx, target));
97 }
98
99 #endif /* RDATA_IN_1_KX_36_C */
100