Skip to content
Snippets Groups Projects
Commit 4c5892ef authored by Lubos Slovak's avatar Lubos Slovak
Browse files

response2_init() API function added.

- This function (or its counterpart response2_init_from_query()
  must be called before doing anything with the response, so that
  the header and size is set well.

TODO: response2_set_max_size() must be called before this function.
      Is this OK?

refs #816 @15m
parent aca00483
No related branches found
No related tags found
No related merge requests found
......@@ -782,10 +782,54 @@ static void dnslib_response2_edns_to_wire(dnslib_packet_t *resp)
resp->header.arcount += 1;
}
/*----------------------------------------------------------------------------*/
/*!
* \brief Converts the header structure to wire format.
*
* \note This function also adjusts the position (\a pos) according to
* the size of the converted wire format.
*
* \param[in] header DNS header structure to convert.
* \param[out] pos Position where to put the converted header.
* \param[out] size Size of the wire format of the header in bytes.
*/
static void dnslib_response2_header_to_wire(const dnslib_header_t *header,
uint8_t **pos, size_t *size)
{
dnslib_wire_set_id(*pos, header->id);
dnslib_wire_set_flags1(*pos, header->flags1);
dnslib_wire_set_flags2(*pos, header->flags2);
dnslib_wire_set_qdcount(*pos, header->qdcount);
dnslib_wire_set_ancount(*pos, header->ancount);
dnslib_wire_set_nscount(*pos, header->nscount);
dnslib_wire_set_arcount(*pos, header->arcount);
*pos += DNSLIB_WIRE_HEADER_SIZE;
*size += DNSLIB_WIRE_HEADER_SIZE;
}
/*----------------------------------------------------------------------------*/
/* API functions */
/*----------------------------------------------------------------------------*/
int dnslib_response2_init(dnslib_packet_t *response)
{
if (response->max_size < DNSLIB_WIRE_HEADER_SIZE) {
return DNSLIB_ESPACE;
}
// set the qr bit to 1
dnslib_wire_flags_set_qr(&response->header.flags1);
uint8_t *pos = response->wireformat;
dnslib_response2_header_to_wire(&response->header, &pos,
&response->size);
return DNSLIB_EOK;
}
/*----------------------------------------------------------------------------*/
int dnslib_response2_init_from_query(dnslib_packet_t *response,
dnslib_packet_t *query)
{
......
......@@ -29,6 +29,8 @@
static const short DNSLIB_MAX_RESPONSE_SIZE = 512;
/*----------------------------------------------------------------------------*/
int dnslib_response2_init(dnslib_packet_t *response);
/*!
* \brief Initializes response from the given query.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment