From: Miek Gieben Date: Mon, 21 Feb 2005 13:05:51 +0000 (+0000) Subject: the query date is printed of a packet X-Git-Tag: release-0.50~396 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f7df478ce31efa6142f2297f2cea0ecbb6e800ad;p=thirdparty%2Fldns.git the query date is printed of a packet --- diff --git a/host2str.c b/host2str.c index 37398682..c555abf3 100644 --- a/host2str.c +++ b/host2str.c @@ -937,6 +937,10 @@ ldns_pkt2buffer_str(ldns_buffer *output, ldns_pkt *pkt) if (ldns_pkt_answerfrom(pkt)) { ldns_buffer_printf(output, ";; SERVER: %s\n", ldns_pkt_answerfrom(pkt)); } + if (ldns_pkt_when(pkt)) { + /* \n included in when buffer, see ctime(3) */ + ldns_buffer_printf(output, ";; WHEN: %s", ldns_pkt_when(pkt)); + } ldns_buffer_printf(output, ";; MSG SIZE rcvd: %d\n", (int)ldns_pkt_size(pkt)); } else { return ldns_buffer_status(output); diff --git a/ldns/packet.h b/ldns/packet.h index 74441b34..93624736 100644 --- a/ldns/packet.h +++ b/ldns/packet.h @@ -68,6 +68,7 @@ struct ldns_struct_pkt /** \brief the size in bytes of the pkt */ uint16_t _answersize; char *_answerfrom; + char *_when; /** \brief query duration */ uint32_t _querytime; /** \brief the packet size */ @@ -125,6 +126,7 @@ uint16_t ldns_pkt_ancount(ldns_pkt *); uint16_t ldns_pkt_nscount(ldns_pkt *); uint16_t ldns_pkt_arcount(ldns_pkt *); char *ldns_pkt_answerfrom(ldns_pkt *packet); +char *ldns_pkt_when(ldns_pkt *packet); uint32_t ldns_pkt_querytime(ldns_pkt *); size_t ldns_pkt_size(ldns_pkt *); @@ -150,6 +152,7 @@ void ldns_pkt_set_arcount(ldns_pkt *, uint16_t); void ldns_pkt_set_answerfrom(ldns_pkt *, char *); void ldns_pkt_set_querytime(ldns_pkt *, uint32_t); void ldns_pkt_set_size(ldns_pkt *, size_t); +void ldns_pkt_set_when(ldns_pkt *, char *); /** * Allocates and initializes a ldns_pkt structure diff --git a/net.c b/net.c index 57531a16..148013d1 100644 --- a/net.c +++ b/net.c @@ -104,12 +104,13 @@ ldns_send(ldns_resolver *r, ldns_pkt *query_pkt) reply = ldns_send_udp(qb, ns, ns_len); } gettimeofday(&tv_e, NULL); - + if (reply) { ldns_pkt_set_querytime(reply, ((tv_e.tv_sec - tv_s.tv_sec) * 1000) + (tv_e.tv_usec - tv_s.tv_usec) / 1000); ldns_pkt_set_answerfrom(reply, ldns_rdf2str(ns_array[i])); + ldns_pkt_set_when(reply, ctime((time_t*)&tv_s.tv_sec)); break; } } diff --git a/packet.c b/packet.c index c105a04d..e57ef5bb 100644 --- a/packet.c +++ b/packet.c @@ -150,6 +150,12 @@ ldns_pkt_answerfrom(ldns_pkt *packet) return packet->_answerfrom; } +char * +ldns_pkt_when(ldns_pkt *packet) +{ + return packet->_when; +} + uint16_t ldns_pkt_xxcount(ldns_pkt *packet, ldns_pkt_section s) { @@ -280,6 +286,13 @@ ldns_pkt_set_answerfrom(ldns_pkt *packet, char *answerfrom) packet->_answerfrom = answerfrom; } +void +ldns_pkt_set_when(ldns_pkt *packet, char *when) +{ + /* TODO if exists free? */ + packet->_when = when; +} + void ldns_pkt_set_size(ldns_pkt *packet, size_t s) { @@ -350,6 +363,7 @@ ldns_pkt_new() ldns_pkt_set_size(packet, 0); ldns_pkt_set_querytime(packet, 0); ldns_pkt_set_answerfrom(packet, NULL); + ldns_pkt_set_when(packet, NULL); return packet; }