From: Miek Gieben Date: Mon, 31 Jan 2005 12:51:13 +0000 (+0000) Subject: naming and documentation X-Git-Tag: release-0.50~503 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a9eeb4741e12babc737e4f828ce71fd2aefe8dd3;p=thirdparty%2Fldns.git naming and documentation --- diff --git a/ldns/packet.h b/ldns/packet.h index f289fbdc..a38429a4 100644 --- a/ldns/packet.h +++ b/ldns/packet.h @@ -147,8 +147,8 @@ void ldns_pkt_free(ldns_pkt *packet); /** * Creates a query packet for the given name, type, class */ -ldns_pkt * ldns_pkt_query_new(char *name, ldns_rr_type rr_type, ldns_rr_class rr_class); - +ldns_pkt * ldns_pkt_query_new_frm_str(char *, ldns_rr_type, ldns_rr_class); +ldns_pkt * ldns_pkt_query_new(ldns_rdf *, ldns_rr_type, ldns_rr_class); #define MAX_PACKET_SIZE 65535 diff --git a/packet.c b/packet.c index b02431d7..bca7a5ca 100644 --- a/packet.c +++ b/packet.c @@ -332,12 +332,22 @@ ldns_pkt_free(ldns_pkt *packet) } ldns_pkt * -ldns_pkt_query_new(char *name, ldns_rr_type rr_type, ldns_rr_class rr_class) +ldns_pkt_query_new_frm_str(char *name, ldns_rr_type rr_type, ldns_rr_class rr_class) { - ldns_pkt *packet = ldns_pkt_new(); - ldns_rr *question_rr = ldns_rr_new(); + ldns_pkt *packet; + ldns_rr *question_rr; ldns_rdf *name_rdf; + packet = ldns_pkt_new(); + if (!packet) { + return NULL; + } + + question_rr = ldns_rr_new(); + if (!question_rr) { + return NULL; + } + if (rr_type == 0) { rr_type = LDNS_RR_TYPE_A; } @@ -359,3 +369,42 @@ ldns_pkt_query_new(char *name, ldns_rr_type rr_type, ldns_rr_class rr_class) return packet; } + +/** + * Create a packet with a query in it + * \param[in] name the name to query for + * \param[in] type the type to query for + * \param[in] class the class to query for + * \return ldns_pkt* a pointer to the new pkt + */ +ldns_pkt * +ldns_pkt_query_new(ldns_rdf *rr_name, ldns_rr_type rr_type, ldns_rr_class rr_class) +{ + ldns_pkt *packet; + ldns_rr *question_rr; + ldns_rdf *name_rdf; + + packet = ldns_pkt_new(); + if (!packet) { + return NULL; + } + + question_rr = ldns_rr_new(); + if (!question_rr) { + return NULL; + } + + if (rr_type == 0) { + rr_type = LDNS_RR_TYPE_A; + } + if (rr_class == 0) { + rr_class = LDNS_RR_CLASS_IN; + } + + ldns_rr_set_owner(question_rr, rr_name); + ldns_rr_set_type(question_rr, rr_type); + ldns_rr_set_class(question_rr, rr_class); + + ldns_pkt_push_rr(packet, LDNS_SECTION_QUESTION, question_rr); + return packet; +} diff --git a/resolver.c b/resolver.c index d4d4eae1..75581bb4 100644 --- a/resolver.c +++ b/resolver.c @@ -233,7 +233,7 @@ ldns_resolver_send(ldns_resolver *r, ldns_rdf *name, ldns_rr_type type, ldns_rr_ /* prepare a question pkt from the parameters * and then send this */ - /*query_pkt = somesortofconversion2qpkt(name, type, class, flags); * */ + query_pkt = ldns_pkt_query_new(name, type, class); /* return NULL on error */ answer_pkt = ldns_send(*r, query_pkt); diff --git a/run-test5.c b/run-test5.c index a69bad34..31ba2c45 100644 --- a/run-test5.c +++ b/run-test5.c @@ -9,7 +9,7 @@ main(int argc, char **argv) printf("test 5\n"); - packet = ldns_pkt_query_new("www.kanariepiet.com", + packet = ldns_pkt_query_new_frm_str("www.kanariepiet.com", LDNS_RR_TYPE_A, LDNS_RR_CLASS_IN);