From: Miek Gieben Date: Wed, 2 Feb 2005 09:47:26 +0000 (+0000) Subject: set the query time in a packet. Next up: answerfrom X-Git-Tag: release-0.50~474 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3bd6955d05ad897123dc8d244d89eefaf60b8e25;p=thirdparty%2Fldns.git set the query time in a packet. Next up: answerfrom --- diff --git a/ldns/packet.h b/ldns/packet.h index a38429a4..e066b25c 100644 --- a/ldns/packet.h +++ b/ldns/packet.h @@ -66,11 +66,11 @@ struct ldns_struct_pkt ldns_hdr *_header; /* extra items needed in a packet */ /** \brief the size in bytes of the pkt */ - uint16_t answersize; + uint16_t _answersize; /** \brief the server ip */ - ldns_rdf *answerfrom; + ldns_rdf *_answerfrom; /** \brief query duration */ - unsigned long querytime; + uint32_t _querytime; /** \brief query data */ /** \brief question section */ ldns_rr_list *_question; diff --git a/net.c b/net.c index 5c1a691a..4b1b51c4 100644 --- a/net.c +++ b/net.c @@ -127,23 +127,23 @@ ldns_send_udp(ldns_buffer *qbin, const struct sockaddr_storage *to, socklen_t to ssize_t bytes; uint8_t *answer; ldns_pkt *answer_pkt; - struct sockaddr_in *to4; - printf("family %d [4=%d %d] [6=%d %d]\n", ((struct sockaddr*)to)->sa_family, - AF_INET, PF_INET, AF_INET6, PF_INET6); - + struct timeval tv_s; + struct timeval tv_e; + + gettimeofday(&tv_s, NULL); + if ((sockfd = socket(((struct sockaddr*)to)->sa_family, SOCK_DGRAM, IPPROTO_UDP)) == -1) { printf("could not open socket\n"); return NULL; } - to4 = (struct sockaddr_in*) to; + bytes = sendto(sockfd, ldns_buffer_begin(qbin), + ldns_buffer_position(qbin), 0, (struct sockaddr *)to, tolen); - printf("port %d len %d\n", - ntohs(to4->sin_port), tolen); + gettimeofday(&tv_e, NULL); + - bytes = sendto(sockfd, ldns_buffer_begin(qbin), - ldns_buffer_position(qbin), 0, (struct sockaddr *)to, tolen); if (bytes == -1) { printf("error with sending: %s\n", strerror(errno)); @@ -182,6 +182,11 @@ ldns_send_udp(ldns_buffer *qbin, const struct sockaddr_storage *to, socklen_t to printf("could not create packet\n"); return NULL; } else { + /* set some extra values in the pkt */ + ldns_pkt_set_querytime(answer_pkt, + ((tv_e.tv_sec - tv_s.tv_sec)*1000) + + ((tv_e.tv_usec - tv_s.tv_usec)/1000)); + return answer_pkt; } } diff --git a/packet.c b/packet.c index fb476d57..c5b671d5 100644 --- a/packet.c +++ b/packet.c @@ -129,6 +129,18 @@ ldns_pkt_additional(ldns_pkt *packet) return packet->_additional; } +ldns_rdf * +ldns_pkt_answerfrom(ldns_pkt *packet) +{ + return packet->_answerfrom; +} + +uint32_t +ldns_pkt_querytime(ldns_pkt *packet) +{ + return packet->_querytime; +} + uint16_t ldns_pkt_xxcount(ldns_pkt *packet, ldns_pkt_section s) { @@ -246,6 +258,18 @@ ldns_pkt_set_arcount(ldns_pkt *packet, uint16_t arcount) packet->_header->_arcount = arcount; } +void +ldns_pkt_set_answerfrom(ldns_pkt *packet, ldns_rdf *answerfrom) +{ + packet->_answerfrom = answerfrom; +} + +void +ldns_pkt_set_querytime(ldns_pkt *packet, uint32_t time) +{ + packet->_querytime = time; +} + /** * push an rr on a packet * \param[in] packet packet to operatore on