19 static const char rcsid[] =
"$Id: ns_parse.c,v 1.3.2.1 2003/06/27 03:51:42 marka Exp $";
27 #include <sys/types.h>
29 #include <netinet/in.h>
37 # ifdef HAVE_STRINGS_H
47 static void setsection(ns_msg *msg, ns_sect sect);
51 #define RETERR(err) do { errno = (err); return (-1); } while (0)
76 ns_skiprr(
const u_char *ptr,
const u_char *eom, ns_sect section,
int count) {
77 const u_char *optr = ptr;
79 for ((
void)
NULL; count > 0; count--) {
101 const u_char *eom = msg + msglen;
104 memset(handle, 0x5e,
sizeof *handle);
119 if (handle->_counts[i] == 0)
120 handle->_sections[i] =
NULL;
127 handle->_sections[i] = msg;
137 ns_parserr(ns_msg *handle, ns_sect section,
int rrnum, ns_rr *rr) {
142 if ((tmp = section) < 0 || section >=
ns_s_max)
144 if (section != handle->_sect)
145 setsection(handle, section);
149 rrnum = handle->_rrnum;
150 if (rrnum < 0 || rrnum >= handle->_counts[(
int)section])
152 if (rrnum < handle->_rrnum)
153 setsection(handle, section);
154 if (rrnum > handle->_rrnum) {
155 b =
ns_skiprr(handle->_msg_ptr, handle->_eom, section,
156 rrnum - handle->_rrnum);
160 handle->_msg_ptr += b;
161 handle->_rrnum = rrnum;
165 b = dn_expand(handle->_msg, handle->_eom,
169 handle->_msg_ptr += b;
172 NS_GET16(rr->type, handle->_msg_ptr);
173 NS_GET16(rr->rr_class, handle->_msg_ptr);
181 NS_GET32(rr->ttl, handle->_msg_ptr);
182 NS_GET16(rr->rdlength, handle->_msg_ptr);
183 if (handle->_msg_ptr + rr->rdlength > handle->_eom)
185 rr->rdata = handle->_msg_ptr;
186 handle->_msg_ptr += rr->rdlength;
188 if (++handle->_rrnum > handle->_counts[(
int)section])
189 setsection(handle, (ns_sect)((
int)section + 1));
198 setsection(ns_msg *msg, ns_sect sect) {
202 msg->_msg_ptr =
NULL;
205 msg->_msg_ptr = msg->_sections[(int)sect];