]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
set the query time in a packet. Next up: answerfrom
authorMiek Gieben <miekg@NLnetLabs.nl>
Wed, 2 Feb 2005 09:47:26 +0000 (09:47 +0000)
committerMiek Gieben <miekg@NLnetLabs.nl>
Wed, 2 Feb 2005 09:47:26 +0000 (09:47 +0000)
ldns/packet.h
net.c
packet.c

index a38429a44e86bcb01a1823b8d015a21210035dab..e066b25c2fe99744cfedc4ead12d8474a6819ae3 100644 (file)
@@ -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 5c1a691adeef6e6f6185ff825c4b84307c2005da..4b1b51c4f2d15bba5873da7333e80ae2681bb91c 100644 (file)
--- 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;
        }
 }
index fb476d57323402e8f5a72539ae6b84a291a4c7ad..c5b671d51c4b30132624cd3318fd740e3d330291 100644 (file)
--- 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