2 * Copyright (c) 1996,1999 by Internet Software Consortium.
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
9 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
10 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
11 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
12 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
13 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
14 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
19 * Modified by Hotbird64 for use with vlmcs.
23 #define CONFIG "config.h"
27 #ifdef DNS_PARSER_INTERNAL
32 #include <sys/types.h>
43 #define NS_GET16_VLMCSD(s, cp) do { \
44 (s) = GET_UA16BE(cp); \
48 #define NS_GET32_VLMCSD(l, cp) do { \
49 (l) = GET_UA32BE(cp); \
53 #define RETERR(err) do { errno = (err); return (-1); } while (0)
57 static void setsection_vlmcsd(ns_msg_vlmcsd
*msg
, ns_sect_vlmcsd sect
);
60 static int dn_skipname_vlmcsd(const unsigned char *s
, const unsigned char *end
)
62 const unsigned char *p
;
64 if (!*p
) return p
-s
+1;
66 {if (p
+1<end
) return p
-s
+2;
72 ns_skiprr_vlmcsd(const uint8_t *ptr
, const uint8_t *eom
, ns_sect_vlmcsd section
, int count
) {
73 const uint8_t *optr
= ptr
;
75 for ((void)NULL
; count
> 0; count
--) {
78 b
= dn_skipname_vlmcsd(ptr
, eom
);
81 ptr
+= b
/*Name*/ + NS_INT16SZ
/*Type*/ + NS_INT16SZ
/*Class*/;
82 if (section
!= ns_s_qd_vlmcsd
) {
83 if (ptr
+ NS_INT32SZ
+ NS_INT16SZ
> eom
)
85 ptr
+= NS_INT32SZ
/*TTL*/;
86 NS_GET16_VLMCSD(rdlength
, ptr
);
87 ptr
+= rdlength
/*RData*/;
96 ns_initparse_vlmcsd(const uint8_t *msg
, int msglen
, ns_msg_vlmcsd
*handle
) {
97 const uint8_t *eom
= msg
+ msglen
;
100 memset(handle
, 0x5e, sizeof *handle
);
103 if (msg
+ NS_INT16SZ
> eom
)
105 NS_GET16_VLMCSD(handle
->_id
, msg
);
106 if (msg
+ NS_INT16SZ
> eom
)
108 NS_GET16_VLMCSD(handle
->_flags
, msg
);
109 for (i
= 0; i
< ns_s_max_vlmcsd
; i
++) {
110 if (msg
+ NS_INT16SZ
> eom
)
112 NS_GET16_VLMCSD(handle
->_counts
[i
], msg
);
114 for (i
= 0; i
< ns_s_max_vlmcsd
; i
++)
115 if (handle
->_counts
[i
] == 0)
116 handle
->_sections
[i
] = NULL
;
118 int b
= ns_skiprr_vlmcsd(msg
, eom
, (ns_sect_vlmcsd
)i
,
123 handle
->_sections
[i
] = msg
;
129 setsection_vlmcsd(handle
, ns_s_max_vlmcsd
);
134 ns_parserr_vlmcsd(ns_msg_vlmcsd
*handle
, ns_sect_vlmcsd section
, int rrnum
, ns_rr_vlmcsd
*rr
) {
137 /* Make section right. */
138 if (section
>= ns_s_max_vlmcsd
)
140 if (section
!= handle
->_sect
)
141 setsection_vlmcsd(handle
, section
);
143 /* Make rrnum right. */
145 rrnum
= handle
->_rrnum
;
146 if (rrnum
< 0 || rrnum
>= handle
->_counts
[(int)section
])
148 if (rrnum
< handle
->_rrnum
)
149 setsection_vlmcsd(handle
, section
);
150 if (rrnum
> handle
->_rrnum
) {
151 b
= ns_skiprr_vlmcsd(handle
->_msg_ptr
, handle
->_eom
, section
,
152 rrnum
- handle
->_rrnum
);
156 handle
->_msg_ptr
+= b
;
157 handle
->_rrnum
= rrnum
;
161 b
= ns_name_uncompress_vlmcsd(handle
->_msg
, handle
->_eom
,
162 handle
->_msg_ptr
, rr
->name
, NS_MAXDNAME
);
165 handle
->_msg_ptr
+= b
;
166 if (handle
->_msg_ptr
+ NS_INT16SZ
+ NS_INT16SZ
> handle
->_eom
)
168 NS_GET16_VLMCSD(rr
->type
, handle
->_msg_ptr
);
169 NS_GET16_VLMCSD(rr
->rr_class
, handle
->_msg_ptr
);
170 if (section
== ns_s_qd_vlmcsd
) {
175 if (handle
->_msg_ptr
+ NS_INT32SZ
+ NS_INT16SZ
> handle
->_eom
)
177 NS_GET32_VLMCSD(rr
->ttl
, handle
->_msg_ptr
);
178 NS_GET16_VLMCSD(rr
->rdlength
, handle
->_msg_ptr
);
179 if (handle
->_msg_ptr
+ rr
->rdlength
> handle
->_eom
)
181 rr
->rdata
= handle
->_msg_ptr
;
182 handle
->_msg_ptr
+= rr
->rdlength
;
184 if (++handle
->_rrnum
> handle
->_counts
[(int)section
])
185 setsection_vlmcsd(handle
, (ns_sect_vlmcsd
)((int)section
+ 1));
194 setsection_vlmcsd(ns_msg_vlmcsd
*msg
, ns_sect_vlmcsd sect
) {
196 if (sect
== ns_s_max_vlmcsd
) {
198 msg
->_msg_ptr
= NULL
;
201 msg
->_msg_ptr
= msg
->_sections
[(int)sect
];
206 #endif // DNS_PARSER_INTERNAL