xref: /openbsd/usr.bin/dig/lib/dns/rdata/generic/mr_9.c (revision 1fb015a8)
15185a700Sflorian /*
25185a700Sflorian  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
35185a700Sflorian  *
45185a700Sflorian  * Permission to use, copy, modify, and/or distribute this software for any
55185a700Sflorian  * purpose with or without fee is hereby granted, provided that the above
65185a700Sflorian  * copyright notice and this permission notice appear in all copies.
75185a700Sflorian  *
85185a700Sflorian  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
95185a700Sflorian  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
105185a700Sflorian  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
115185a700Sflorian  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
125185a700Sflorian  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
135185a700Sflorian  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
145185a700Sflorian  * PERFORMANCE OF THIS SOFTWARE.
155185a700Sflorian  */
165185a700Sflorian 
17*1fb015a8Sflorian /* $Id: mr_9.c,v 1.11 2020/09/14 08:40:43 florian Exp $ */
185185a700Sflorian 
195185a700Sflorian /* Reviewed: Wed Mar 15 21:30:35 EST 2000 by tale */
205185a700Sflorian 
215185a700Sflorian #ifndef RDATA_GENERIC_MR_9_C
225185a700Sflorian #define RDATA_GENERIC_MR_9_C
235185a700Sflorian 
245185a700Sflorian static inline isc_result_t
totext_mr(ARGS_TOTEXT)255185a700Sflorian totext_mr(ARGS_TOTEXT) {
265185a700Sflorian 	isc_region_t region;
275185a700Sflorian 	dns_name_t name;
285185a700Sflorian 	dns_name_t prefix;
29*1fb015a8Sflorian 	int sub;
305185a700Sflorian 
315185a700Sflorian 	REQUIRE(rdata->type == dns_rdatatype_mr);
325185a700Sflorian 	REQUIRE(rdata->length != 0);
335185a700Sflorian 
345185a700Sflorian 	dns_name_init(&name, NULL);
355185a700Sflorian 	dns_name_init(&prefix, NULL);
365185a700Sflorian 
375185a700Sflorian 	dns_rdata_toregion(rdata, &region);
385185a700Sflorian 	dns_name_fromregion(&name, &region);
395185a700Sflorian 
405185a700Sflorian 	sub = name_prefix(&name, tctx->origin, &prefix);
415185a700Sflorian 
425185a700Sflorian 	return (dns_name_totext(&prefix, sub, target));
435185a700Sflorian }
445185a700Sflorian 
455185a700Sflorian static inline isc_result_t
fromwire_mr(ARGS_FROMWIRE)465185a700Sflorian fromwire_mr(ARGS_FROMWIRE) {
475185a700Sflorian 	dns_name_t name;
485185a700Sflorian 
495185a700Sflorian 	REQUIRE(type == dns_rdatatype_mr);
505185a700Sflorian 
515185a700Sflorian 	UNUSED(type);
525185a700Sflorian 	UNUSED(rdclass);
535185a700Sflorian 
545185a700Sflorian 	dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14);
555185a700Sflorian 
565185a700Sflorian 	dns_name_init(&name, NULL);
575185a700Sflorian 	return (dns_name_fromwire(&name, source, dctx, options, target));
585185a700Sflorian }
595185a700Sflorian 
605185a700Sflorian static inline isc_result_t
towire_mr(ARGS_TOWIRE)615185a700Sflorian towire_mr(ARGS_TOWIRE) {
625185a700Sflorian 	dns_name_t name;
635185a700Sflorian 	dns_offsets_t offsets;
645185a700Sflorian 	isc_region_t region;
655185a700Sflorian 
665185a700Sflorian 	REQUIRE(rdata->type == dns_rdatatype_mr);
675185a700Sflorian 	REQUIRE(rdata->length != 0);
685185a700Sflorian 
695185a700Sflorian 	dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14);
705185a700Sflorian 
715185a700Sflorian 	dns_name_init(&name, offsets);
725185a700Sflorian 	dns_rdata_toregion(rdata, &region);
735185a700Sflorian 	dns_name_fromregion(&name, &region);
745185a700Sflorian 
755185a700Sflorian 	return (dns_name_towire(&name, cctx, target));
765185a700Sflorian }
775185a700Sflorian 
785185a700Sflorian #endif	/* RDATA_GENERIC_MR_9_C */
79