4 * Copyright (C) 2009 Internet Systems Consortium, Inc. ("ISC")
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
20 static const char rcsid
[] = "Id: ns_rdata.c,v 1.2 2009/01/23 23:49:15 tbox Exp";
23 #include "port_before.h"
26 #include <sys/types.h>
28 #include <netinet/in.h>
29 #include <arpa/nameser.h>
35 #include "port_after.h"
39 rdata += n, rdlen -= n; \
44 nrdata += n, nrdsiz -= n, nrdlen += n; \
47 #define UNPACK_DNAME \
51 if ((n = ns_name_unpack2(msg,eom,rdata,nrdata,nrdsiz,&t))<0) {\
60 #define UNPACK_SOME(x) \
63 if ((size_t)n > rdlen || (size_t)n > nrdsiz) { \
67 memcpy(nrdata, rdata, n); \
68 CONSUME_SRC; CONSUME_DST; \
71 #define UNPACK_REST(x) \
74 if ((size_t)n != rdlen) { \
78 memcpy(nrdata, rdata, n); \
79 CONSUME_SRC; CONSUME_DST; \
83 ns_rdata_unpack(const u_char
*msg
, const u_char
*eom
,
84 ns_type type
, const u_char
*rdata
, size_t rdlen
,
85 u_char
*nrdata
, size_t nrdsiz
)
92 UNPACK_REST(NS_INADDRSZ
);
95 UNPACK_REST(NS_IN6ADDRSZ
);
109 UNPACK_SOME(NS_INT32SZ
* 5);
114 UNPACK_SOME(NS_INT16SZ
);
118 UNPACK_SOME(NS_INT16SZ
);
123 UNPACK_SOME(NS_INT16SZ
* 3);
142 #define EQUAL_CONSUME \
144 rdata1 += n, rdlen1 -= n; \
145 rdata2 += n, rdlen2 -= n; \
148 #define EQUAL_DNAME \
152 if (rdlen1 != rdlen2) \
154 n = ns_name_eq(rdata1, rdlen1, rdata2, rdlen2); \
161 #define EQUAL_SOME(x) \
165 if (n > rdlen1 || n > rdlen2) { \
169 if (memcmp(rdata1, rdata2, n) != 0) \
175 ns_rdata_equal(ns_type type
,
176 const u_char
*rdata1
, size_t rdlen1
,
177 const u_char
*rdata2
, size_t rdlen2
)
190 /* "There can be only one." --Highlander */
195 EQUAL_SOME(NS_INT16SZ
);
199 EQUAL_SOME(NS_INT16SZ
);
204 EQUAL_SOME(NS_INT16SZ
* 3);
216 if (rdlen1
!= 0 || rdlen2
!= 0)
221 #define REFERS_DNAME \
225 n = ns_name_eq(rdata, rdlen, nname, NS_MAXNNAME); \
230 n = dn_skipname(rdata, rdata + rdlen); \
236 #define REFERS_SOME(x) \
248 ns_rdata_refers(ns_type type
,
249 const u_char
*rdata
, size_t rdlen
,
265 REFERS_SOME(NS_INT32SZ
* 5);
270 REFERS_SOME(NS_INT16SZ
);
274 REFERS_SOME(NS_INT16SZ
);
279 REFERS_SOME(NS_INT16SZ
* 3);