#include <netdb.h>
#include <arpa/inet.h>
#include <sys/time.h>
+#include <errno.h>
#include "util.h"
+extern int errno;
+
/* send a buffer using tcp */
ldns_pkt *
ldns_sendbuf_tcp(ldns_buffer *buf, int *sockfd, struct sockaddr *dest)
ldns_rdf **ns_array;
ldns_pkt *reply;
ldns_buffer *qb;
+ ldns_rdf *tmp;
ns_array = ldns_resolver_nameservers(r);
reply = NULL;
+ printf("we are in ldns_send()\n");
qb = ldns_buffer_new(MAX_PACKET_SIZE);
if (ldns_pkt2buffer_wire(qb, query_pkt) != LDNS_STATUS_OK) {
+ printf("could not convert to wire fmt\n");
return NULL;
}
+ printf("nameservers %d\n",ldns_resolver_nameserver_count(r));
+
/* loop through all defined nameservers */
for (i = 0; i < ldns_resolver_nameserver_count(r); i++) {
ns_ip = ldns_rdf2native_aaaaa(ns_array[i]);
ns_ip_len = ldns_rdf_size(ns_array[i]);
- ldns_rdf_print(stdout, ns_ip);
+ tmp = ns_array[i];
+
+ ldns_rdf_print(stdout, tmp);
printf("\n");
+ printf("ip address len %d\n", ns_ip_len);
/* query */
reply = ldns_send_udp(qb, ns_ip, ns_ip_len);
- if (!reply) {
+ if (reply) {
+ printf("reply found\n");
break;
}
}
if ((sockfd = socket(to->sa_family, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
+ printf("could not open socket\n");
return NULL;
}
ldns_buffer_capacity(qbin), 0, to, tolen);
if (bytes == -1) {
+ printf("error with sending: %s\n", strerror(errno));
close(sockfd);
return NULL;
}
if ((size_t) bytes != ldns_buffer_capacity(qbin)) {
+ printf("amount mismatch\n");
close(sockfd);
return NULL;
}
/* wait for an response*/
answer = XMALLOC(uint8_t*, MAX_PACKET_SIZE);
if (!answer) {
+ printf("respons alloc error\n");
return NULL;
}
close(sockfd);
if (bytes == -1) {
+ printf("received too little\n");
FREE(answer);
return NULL;
}
if (ldns_wire2pkt(&answer_pkt, answer, (size_t) bytes) !=
LDNS_STATUS_OK) {
+ printf("could not create packet\n");
return NULL;
} else {
return answer_pkt;
class = LDNS_RR_CLASS_IN;
}
if (0 == ldns_resolver_configured(r)) {
+ printf("resolver is not configued\n");
return NULL;
}
if (ldns_rdf_get_type(name) != LDNS_RDF_TYPE_DNAME) {
+ printf("query type is not correct type\n");
return NULL;
}
query_pkt = ldns_pkt_query_new(name, type, class);
if (!query_pkt) {
printf("Failed to generate pkt\n");
- return NULL;
}
/* return NULL on error */