Commit 4c208bd4 authored by Michael Graff's avatar Michael Graff

add dns_message_peekheader()

parent 544f5611
......@@ -627,6 +627,30 @@ dns_message_puttemprdatalist(dns_message_t *msg, dns_rdatalist_t **item);
* *item == NULL
*/
dns_result_t
dns_message_peekheader(isc_buffer_t *source, dns_messageid_t *idp,
unsigned int *flagsp);
/*
* Assume the remaining region of "source" is a DNS message. Peek into
* it and fill in "*idp" with the message id, and "*flagsp" with the flags.
*
* Requires:
*
* source != NULL
*
* Ensures:
*
* if (idp != NULL) *idp == message id.
*
* if (flagsp != NULL) *flagsp == message flags.
*
* Returns:
*
* DNS_R_SUCCESS -- all is well.
*
* DNS_R_UNEXPECTEDEND -- buffer doesn't contain enough for a header.
*/
ISC_LANG_ENDDECLS
#endif /* DNS_DNS_H */
......@@ -1539,3 +1539,32 @@ dns_message_puttemprdatalist(dns_message_t *msg, dns_rdatalist_t **item)
releaserdatalist(msg, *item);
*item = NULL;
}
dns_result_t
dns_message_peekheader(isc_buffer_t *source, dns_messageid_t *idp,
unsigned int *flagsp)
{
isc_region_t r;
isc_buffer_t buffer;
dns_messageid_t id;
unsigned int flags;
REQUIRE(source != NULL);
buffer = *source;
isc_buffer_remaining(&buffer, &r);
if (r.length < DNS_MESSAGE_HEADERLEN)
return (DNS_R_UNEXPECTEDEND);
id = isc_buffer_getuint16(source);
flags = isc_buffer_getuint16(source);
flags &= DNS_MESSAGE_FLAG_MASK;
if (flagsp != NULL)
*flagsp = flags;
if (idp != NULL)
*idp = id;
return (DNS_R_SUCCESS);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment