xref: /openbsd/usr.bin/dig/lib/dns/rdata/in_1/kx_36.c (revision b9558d14)
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.9 2020/02/25 05:00:43 jsg 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 #define RRTYPE_KX_ATTRIBUTES (0)
27 
28 static inline isc_result_t
29 totext_in_kx(ARGS_TOTEXT) {
30 	isc_region_t region;
31 	dns_name_t name;
32 	dns_name_t prefix;
33 	isc_boolean_t sub;
34 	char buf[sizeof("64000")];
35 	unsigned short num;
36 
37 	REQUIRE(rdata->type == dns_rdatatype_kx);
38 	REQUIRE(rdata->rdclass == dns_rdataclass_in);
39 	REQUIRE(rdata->length != 0);
40 
41 	dns_name_init(&name, NULL);
42 	dns_name_init(&prefix, NULL);
43 
44 	dns_rdata_toregion(rdata, &region);
45 	num = uint16_fromregion(&region);
46 	isc_region_consume(&region, 2);
47 	snprintf(buf, sizeof(buf), "%u", num);
48 	RETERR(str_totext(buf, target));
49 
50 	RETERR(str_totext(" ", target));
51 
52 	dns_name_fromregion(&name, &region);
53 	sub = name_prefix(&name, tctx->origin, &prefix);
54 	return (dns_name_totext(&prefix, sub, target));
55 }
56 
57 static inline isc_result_t
58 fromwire_in_kx(ARGS_FROMWIRE) {
59 	dns_name_t name;
60 	isc_region_t sregion;
61 
62 	REQUIRE(type == dns_rdatatype_kx);
63 	REQUIRE(rdclass == dns_rdataclass_in);
64 
65 	UNUSED(type);
66 	UNUSED(rdclass);
67 
68 	dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
69 
70 	dns_name_init(&name, NULL);
71 
72 	isc_buffer_activeregion(source, &sregion);
73 	if (sregion.length < 2)
74 		return (ISC_R_UNEXPECTEDEND);
75 	RETERR(mem_tobuffer(target, sregion.base, 2));
76 	isc_buffer_forward(source, 2);
77 	return (dns_name_fromwire(&name, source, dctx, options, target));
78 }
79 
80 static inline isc_result_t
81 towire_in_kx(ARGS_TOWIRE) {
82 	dns_name_t name;
83 	dns_offsets_t offsets;
84 	isc_region_t region;
85 
86 	REQUIRE(rdata->type == dns_rdatatype_kx);
87 	REQUIRE(rdata->rdclass == dns_rdataclass_in);
88 	REQUIRE(rdata->length != 0);
89 
90 	dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
91 	dns_rdata_toregion(rdata, &region);
92 	RETERR(mem_tobuffer(target, region.base, 2));
93 	isc_region_consume(&region, 2);
94 
95 	dns_name_init(&name, offsets);
96 	dns_name_fromregion(&name, &region);
97 
98 	return (dns_name_towire(&name, cctx, target));
99 }
100 
101 #endif	/* RDATA_IN_1_KX_36_C */
102