xref: /openbsd-src/usr.bin/dig/lib/dns/rdata/generic/l32_105.c (revision 99fd087599a8791921855f21bd7e36130f39aadc)
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_L32_105_C
18 #define RDATA_GENERIC_L32_105_C
19 
20 #include <string.h>
21 
22 #include <isc/net.h>
23 
24 static inline isc_result_t
25 totext_l32(ARGS_TOTEXT) {
26 	isc_region_t region;
27 	char buf[sizeof("65000")];
28 	unsigned short num;
29 
30 	REQUIRE(rdata->type == dns_rdatatype_l32);
31 	REQUIRE(rdata->length == 6);
32 
33 	UNUSED(tctx);
34 
35 	dns_rdata_toregion(rdata, &region);
36 	num = uint16_fromregion(&region);
37 	isc_region_consume(&region, 2);
38 	snprintf(buf, sizeof(buf), "%u", num);
39 	RETERR(isc_str_tobuffer(buf, target));
40 
41 	RETERR(isc_str_tobuffer(" ", target));
42 
43 	return (inet_totext(AF_INET, &region, target));
44 }
45 
46 static inline isc_result_t
47 fromwire_l32(ARGS_FROMWIRE) {
48 	isc_region_t sregion;
49 
50 	REQUIRE(type == dns_rdatatype_l32);
51 
52 	UNUSED(type);
53 	UNUSED(options);
54 	UNUSED(rdclass);
55 	UNUSED(dctx);
56 
57 	isc_buffer_activeregion(source, &sregion);
58 	if (sregion.length != 6)
59 		return (DNS_R_FORMERR);
60 	isc_buffer_forward(source, sregion.length);
61 	return (isc_mem_tobuffer(target, sregion.base, sregion.length));
62 }
63 
64 static inline isc_result_t
65 towire_l32(ARGS_TOWIRE) {
66 
67 	REQUIRE(rdata->type == dns_rdatatype_l32);
68 	REQUIRE(rdata->length == 6);
69 
70 	UNUSED(cctx);
71 
72 	return (isc_mem_tobuffer(target, rdata->data, rdata->length));
73 }
74 
75 #endif	/* RDATA_GENERIC_L32_105_C */
76