int createResponse(struct module_qstate* qstate, sldns_buffer* pkt)
{
	struct msg_parse* prs;
	struct edns_data edns;

	/* parse message */
	prs = (struct msg_parse*) regional_alloc(qstate->env->scratch,
		sizeof(struct msg_parse));
	if(!prs) {
		log_err("createResponse: out of memory on incoming message");
		return 0;
	}

	memset(prs, 0, sizeof(*prs));
	memset(&edns, 0, sizeof(edns));

	sldns_buffer_set_position(pkt, 0);
	if(parse_packet(pkt, prs, qstate->env->scratch) != LDNS_RCODE_NOERROR) {
		verbose(VERB_ALGO, "createResponse: parse error on reply packet");
		return 0;
	}
	/* edns is not examined, but removed from message to help cache */
	if(parse_extract_edns_from_response_msg(prs, &edns, qstate->env->scratch) !=
		LDNS_RCODE_NOERROR)
		return 0;

	/* remove CD-bit, we asked for in case we handle validation ourself */
	prs->flags &= ~BIT_CD;

	/* allocate response dns_msg in region */
	qstate->return_msg = (struct dns_msg*) regional_alloc(qstate->region,
		sizeof(struct dns_msg));
	if(!qstate->return_msg)
		return 0;

	memset(qstate->return_msg, 0, sizeof(*qstate->return_msg));
	if(!parse_create_msg(pkt, prs, NULL, &(qstate->return_msg)->qinfo,
		&(qstate->return_msg)->rep, qstate->region)) {
		log_err("createResponse: malloc failure: allocating incoming dns_msg");
		return 0;
	}

	/* Make sure that the RA flag is set (since the presence of
	* this module means that recursion is available) */
	/* qstate->return_msg->rep->flags |= BIT_RA; */

	/* Clear the AA flag */
	/* FIXME: does this action go here or in some other module? */
	/*qstate->return_msg->rep->flags &= ~BIT_AA; */

	/* make sure QR flag is on */
	/*qstate->return_msg->rep->flags |= BIT_QR; */

	if(verbosity >= VERB_ALGO)
		log_dns_msg("createResponse: packet:", &qstate->return_msg->qinfo,
			qstate->return_msg->rep);

	return 1;
}
int createResponse(struct module_qstate* qstate, sldns_buffer* pkt)
{
	struct msg_parse* prs;
	struct edns_data edns;

	 
	prs = (struct msg_parse*) regional_alloc(qstate->env->scratch,
		sizeof(struct msg_parse));
	if(!prs) {
		log_err("createResponse: out of memory on incoming message");
		return 0;
	}

	memset(prs, 0, sizeof(*prs));
	memset(&edns, 0, sizeof(edns));

	sldns_buffer_set_position(pkt, 0);
	if(parse_packet(pkt, prs, qstate->env->scratch) != LDNS_RCODE_NOERROR) {
		verbose(VERB_ALGO, "createResponse: parse error on reply packet");
		return 0;
	}
	 
	if(parse_extract_edns_from_response_msg(prs, &edns, qstate->env->scratch) !=
		LDNS_RCODE_NOERROR)
		return 0;

	 
	prs->flags &= ~BIT_CD;

	 
	qstate->return_msg = (struct dns_msg*) regional_alloc(qstate->region,
		sizeof(struct dns_msg));
	if(!qstate->return_msg)
		return 0;

	memset(qstate->return_msg, 0, sizeof(*qstate->return_msg));
	if(!parse_create_msg(pkt, prs, NULL, &(qstate->return_msg)->qinfo,
		&(qstate->return_msg)->rep, qstate->region)) {
		log_err("createResponse: malloc failure: allocating incoming dns_msg");
		return 0;
	}

	 
	 

	 
	 
	 

	 
	 

	if(verbosity >= VERB_ALGO)
		log_dns_msg("createResponse: packet:", &qstate->return_msg->qinfo,
			qstate->return_msg->rep);

	return 1;
}