2 * Copyright (C) 2012 Reto Guadagnini
4 * Copyright (C) secunet Security Networks AG
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 #include <resolver/rr.h>
20 #include <utils/debug.h>
25 #include "unbound_rr.h"
27 typedef struct private_unbound_rr_t private_unbound_rr_t
;
30 * private data of an unbound_rr_t object.
32 struct private_unbound_rr_t
{
60 * Size of the rdata field in octets
65 * RDATA field (array of bytes in network order)
70 METHOD(rr_t
, get_name
, char *,
71 private_unbound_rr_t
*this)
76 METHOD(rr_t
, get_type
, rr_type_t
,
77 private_unbound_rr_t
*this)
82 METHOD(rr_t
, get_class
, rr_class_t
,
83 private_unbound_rr_t
*this)
88 METHOD(rr_t
, get_ttl
, uint32_t,
89 private_unbound_rr_t
*this)
94 METHOD(rr_t
, get_rdata
, chunk_t
,
95 private_unbound_rr_t
*this)
97 return chunk_create(this->rdata
, this->size
);
100 METHOD(rr_t
, destroy
, void,
101 private_unbound_rr_t
*this)
109 * Described in header.
111 unbound_rr_t
*unbound_rr_create_frm_ldns_rr(ldns_rr
*rr
)
113 private_unbound_rr_t
*this;
121 .get_name
= _get_name
,
122 .get_type
= _get_type
,
123 .get_class
= _get_class
,
125 .get_rdata
= _get_rdata
,
131 this->name
= ldns_rdf2str(ldns_rr_owner(rr
));
134 DBG1(DBG_LIB
, "failed to parse the owner name of a DNS RR");
139 this->type
= (rr_type_t
)ldns_rr_get_type(rr
);
140 this->class = (rr_class_t
)ldns_rr_get_class(rr
);
141 this->ttl
= ldns_rr_ttl(rr
);
142 for(i
= 0; i
< ldns_rr_rd_count(rr
); i
++)
144 this->size
+= ldns_rdf_size(ldns_rr_rdf(rr
, i
));
148 * The ldns library splits the RDATA field of a RR in various rdf.
149 * Here we reassemble these rdf to get the RDATA field of the RR.
151 buf
= ldns_buffer_new(LDNS_MIN_BUFLEN
);
152 /* The buffer will be resized automatically by ldns_rr_rdata2buffer_wire() */
153 status
= ldns_rr_rdata2buffer_wire(buf
, rr
);
155 if (status
!= LDNS_STATUS_OK
)
157 DBG1(DBG_LIB
, "failed to get the RDATA field of a DNS RR");
158 ldns_buffer_free(buf
);
163 this->rdata
= ldns_buffer_export(buf
);
164 ldns_buffer_free(buf
);
166 return &this->public;