From: Jelte Jansen Date: Fri, 28 Oct 2005 11:13:44 +0000 (+0000) Subject: added timestamp to packet structure (was only a string) X-Git-Tag: release-1.1.0~647 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=80a030dd1015296cb36360bbc0822f0585c37fab;p=thirdparty%2Fldns.git added timestamp to packet structure (was only a string) --- diff --git a/host2str.c b/host2str.c index 87774a3b..ef7d1a64 100644 --- a/host2str.c +++ b/host2str.c @@ -20,6 +20,7 @@ #include #include #include +#include /* lookup tables for standard DNS stuff */ @@ -911,6 +912,7 @@ ldns_pkt2buffer_str(ldns_buffer *output, ldns_pkt *pkt) ldns_status status = LDNS_STATUS_OK; ldns_lookup_table *lt; char *tmp; + struct timeval time; if (!pkt) { ldns_buffer_printf(output, "null"); @@ -1005,10 +1007,16 @@ ldns_pkt2buffer_str(ldns_buffer *output, ldns_pkt *pkt) ldns_buffer_printf(output, ";; SERVER: %s\n", tmp); LDNS_FREE(tmp); } +#if 0 +/* when will be replyced by timestamp */ if (ldns_pkt_when(pkt)) { /* \n included in when buffer, see ctime(3) */ ldns_buffer_printf(output, ";; WHEN: %s", ldns_pkt_when(pkt)); } +#endif + time = ldns_pkt_timestamp(pkt); + ldns_buffer_printf(output, ";; WHEN: %s", ctime((time_t*)&time)); + 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 d7ad7b1d..13ed6012 100644 --- a/ldns/packet.h +++ b/ldns/packet.h @@ -16,6 +16,7 @@ #include #include #include +#include /* opcodes for pkt's */ enum ldns_enum_pkt_opcode { @@ -79,6 +80,7 @@ struct ldns_struct_pkt uint16_t _answersize; ldns_rdf *_answerfrom; char *_when; + struct timeval timestamp; /** query duration */ uint32_t _querytime; /** the packet size */ @@ -151,6 +153,7 @@ uint16_t ldns_pkt_nscount(const ldns_pkt *p); uint16_t ldns_pkt_arcount(const ldns_pkt *p); ldns_rdf *ldns_pkt_answerfrom(const ldns_pkt *p); char *ldns_pkt_when(const ldns_pkt *p); +struct timeval ldns_pkt_timestamp(const ldns_pkt *p); uint32_t ldns_pkt_querytime(const ldns_pkt *p); size_t ldns_pkt_size(const ldns_pkt *p); ldns_rr *ldns_pkt_tsig(const ldns_pkt *p); @@ -200,6 +203,7 @@ void ldns_pkt_set_answerfrom(ldns_pkt *p, ldns_rdf *r); void ldns_pkt_set_querytime(ldns_pkt *p, uint32_t t); void ldns_pkt_set_size(ldns_pkt *p, size_t s); void ldns_pkt_set_when(ldns_pkt *p, char *w); +void ldns_pkt_set_timestamp(ldns_pkt *p, struct timeval timestamp); void ldns_pkt_set_section_count(ldns_pkt *p, ldns_pkt_section s, uint16_t x); void ldns_pkt_set_tsig(ldns_pkt *p, ldns_rr *t); diff --git a/net.c b/net.c index 7756bd98..b6258d4e 100644 --- a/net.c +++ b/net.c @@ -141,7 +141,8 @@ ldns_send(ldns_pkt **result, ldns_resolver *r, ldns_pkt *query_pkt) ((tv_e.tv_sec - tv_s.tv_sec) * 1000) + (tv_e.tv_usec - tv_s.tv_usec) / 1000); ldns_pkt_set_answerfrom(reply, ns_rand_array[i]); - ldns_pkt_set_when(reply, ctime((time_t*)&tv_s.tv_sec)); + ldns_pkt_set_timestamp(reply, tv_s); +/* ldns_pkt_set_when(reply, ctime((time_t*)&tv_s.tv_sec));*/ ldns_pkt_set_size(reply, reply_size); break; } else { diff --git a/packet.c b/packet.c index ca188d2e..5d2c007f 100644 --- a/packet.c +++ b/packet.c @@ -192,6 +192,12 @@ ldns_pkt_when(const ldns_pkt *packet) return packet->_when; } +struct timeval +ldns_pkt_timestamp(const ldns_pkt *packet) +{ + return packet->timestamp; +} + uint16_t ldns_pkt_edns_udp_size(const ldns_pkt *packet) { @@ -667,17 +673,21 @@ ldns_pkt_set_querytime(ldns_pkt *packet, uint32_t time) void ldns_pkt_set_answerfrom(ldns_pkt *packet, ldns_rdf *answerfrom) { - /* if _answerfrom was set, this is a leak. Callers beware */ packet->_answerfrom = answerfrom; } void ldns_pkt_set_when(ldns_pkt *packet, char *when) { - /* if _when was set, this is a leak. Callers beware */ packet->_when = when; } +void +ldns_pkt_set_timestamp(ldns_pkt *packet, struct timeval timestamp) +{ + packet->timestamp = timestamp; +} + void ldns_pkt_set_size(ldns_pkt *packet, size_t s) {