/*
* Copyright (C) 2009 Internet Systems Consortium, Inc. ("ISC")
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/* Add a question (or zone, if it's an update) to a "newmsg" object.
*/
int
ns_newmsg_q(ns_newmsg *handle, ns_nname_ct qname,
ns_type qtype, ns_class qclass)
{
ns_msg *msg = &handle->msg;
u_char *t;
int n;
if (msg->_sect != ns_s_qd) {
errno = ENODEV;
return (-1);
}
t = (u_char *) (unsigned long) msg->_msg_ptr;
if (msg->_rrnum == 0)
msg->_sections[ns_s_qd] = t;
n = ns_name_pack(qname, t, msg->_eom - t,
handle->dnptrs, handle->lastdnptr);
if (n < 0)
return (-1);
t += n;
if (t + QFIXEDSZ >= msg->_eom) {
errno = EMSGSIZE;
return (-1);
}
NS_PUT16(qtype, t);
NS_PUT16(qclass, t);
msg->_msg_ptr = t;
msg->_counts[ns_s_qd] = ++msg->_rrnum;
return (0);
}
/* Add an RR to a "newmsg" object.
*/
int
ns_newmsg_rr(ns_newmsg *handle, ns_sect sect,
ns_nname_ct name, ns_type type,
ns_class rr_class, u_int32_t ttl,
u_int16_t rdlen, const u_char *rdata)
{
ns_msg *msg = &handle->msg;
u_char *t;
int n;
/* Complete a "newmsg" object and return its size for use in write().
* (Note: the "newmsg" object is also made ready for ns_parserr() etc.)
*/
size_t
ns_newmsg_done(ns_newmsg *handle) {
ns_msg *msg = &handle->msg;
ns_sect sect;
u_char *t;