summaryrefslogtreecommitdiff
path: root/src/libknot/packet/response.c
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2013-02-18 12:38:51 +0100
committerOndřej Surý <ondrej@sury.org>2013-02-18 12:38:51 +0100
commit2729227efaac366293e70770b6e82e7e775a2605 (patch)
treec93797ba617a3e0b0e6fcee14cc0ea5a13b37fcc /src/libknot/packet/response.c
parent818bb653bebc90f28ea74a14eb1972fbcd172972 (diff)
downloadknot-2729227efaac366293e70770b6e82e7e775a2605.tar.gz
Imported Upstream version 1.2~rc2upstream/1.2_rc2
Diffstat (limited to 'src/libknot/packet/response.c')
-rw-r--r--src/libknot/packet/response.c37
1 files changed, 23 insertions, 14 deletions
diff --git a/src/libknot/packet/response.c b/src/libknot/packet/response.c
index c6a1a09..476c6b3 100644
--- a/src/libknot/packet/response.c
+++ b/src/libknot/packet/response.c
@@ -903,7 +903,8 @@ int knot_response_init(knot_packet_t *response)
/*----------------------------------------------------------------------------*/
int knot_response_init_from_query(knot_packet_t *response,
- knot_packet_t *query)
+ knot_packet_t *query,
+ int copy_question)
{
if (response == NULL || query == NULL) {
@@ -913,21 +914,29 @@ int knot_response_init_from_query(knot_packet_t *response,
// copy the header from the query
memcpy(&response->header, &query->header, sizeof(knot_header_t));
- // copy the Question section (but do not copy the QNAME)
- memcpy(&response->question, &query->question,
- sizeof(knot_question_t));
-
int err = 0;
- // put the qname into the compression table
- // TODO: get rid of the numeric constants
- if ((err = knot_response_store_dname_pos(&response->compression,
- response->question.qname, 0, 12, 12, 0)) != KNOT_EOK) {
- return err;
- }
+ /*! \todo Constant. */
+ size_t to_copy = 12;
+
+ if (copy_question) {
+ // copy the Question section (but do not copy the QNAME)
+ memcpy(&response->question, &query->question,
+ sizeof(knot_question_t));
+
+ // put the qname into the compression table
+ // TODO: get rid of the numeric constants
+ if ((err = knot_response_store_dname_pos(&response->compression,
+ response->question.qname, 0, 12, 12, 0))
+ != KNOT_EOK) {
+ return err;
+ }
- // copy the wireformat of Header and Question from the query
- // TODO: get rid of the numeric constants
- size_t to_copy = 12 + 4 + knot_dname_size(response->question.qname);
+ /*! \todo Constant. */
+ to_copy += 4 + knot_dname_size(response->question.qname);
+ } else {
+ response->header.qdcount = 0;
+ knot_wire_set_qdcount(response->wireformat, 0);
+ }
assert(response->max_size >= to_copy);
memcpy(response->wireformat, query->wireformat, to_copy);