]>
git.saurik.com Git - apple/libinfo.git/blob - dns.subproj/res_comp.c
2 * Copyright (c) 2018 Apple Inc. All rights reserved.
5 * ++Copyright++ 1985, 1993
7 * Copyright (c) 1985, 1993
8 * The Regents of the University of California. All rights reserved.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * Portions Copyright (c) 1993 by Digital Equipment Corporation.
40 * Permission to use, copy, modify, and distribute this software for any
41 * purpose with or without fee is hereby granted, provided that the above
42 * copyright notice and this permission notice appear in all copies, and that
43 * the name of Digital Equipment Corporation not be used in advertising or
44 * publicity pertaining to distribution of the document or software without
45 * specific, written prior permission.
47 * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
48 * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
49 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
50 * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
51 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
52 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
53 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
59 #if defined(LIBC_SCCS) && !defined(lint)
60 static char sccsid
[] = "@(#)res_comp.c 8.1 (Berkeley) 6/4/93";
61 static char rcsid
[] = "$Id: res_comp.c,v 1.4 2003/02/18 17:29:24 majka Exp $";
62 #endif /* LIBC_SCCS and not lint */
64 #include "libinfo_common.h"
66 #include <sys/param.h>
67 #include <netinet/in.h>
72 #include <arpa/nameser_compat.h>
76 * Expand compressed domain name 'comp_dn' to full domain name.
77 * 'msg' is a pointer to the begining of the message,
78 * 'eomorig' points to the first location after the message,
79 * 'exp_dn' is a pointer to a buffer of size 'length' for the result.
80 * Return size of compressed name or -1 if there was an error.
84 dn_expand(const u_char
*msg
, const u_char
*eomorig
, const u_char
*comp_dn
, char *exp_dn
, int length
)
86 register const u_char
*cp
;
90 int len
= -1, checked
= 0;
94 eom
= exp_dn
+ length
;
96 * fetch next label in domain name
100 * Check for indirection
102 switch (n
& INDIR_MASK
) {
113 if ((c
= *cp
++) == '.') {
114 if (dn
+ n
+ 2 >= eom
)
119 if (cp
>= eomorig
) /* out of range */
126 len
= cp
- comp_dn
+ 1;
127 cp
= msg
+ (((n
& 0x3f) << 8) | (*cp
& 0xff));
128 if (cp
< msg
|| cp
>= eomorig
) /* out of range */
132 * Check for loops in the compressed name;
133 * if we've looked at the whole message,
134 * there must be a loop.
136 if (checked
>= eomorig
- msg
)
141 return (-1); /* flag error */
145 for (dn
= exp_dn
; (c
= *dn
) != '\0'; dn
++)
146 if (isascii(c
) && isspace(c
))
154 * Skip over a compressed domain name. Return the size or -1.
158 __dn_skipname(const u_char
*comp_dn
, const u_char
*eom
)
160 register const u_char
*cp
;
164 while (cp
< eom
&& (n
= *cp
++)) {
166 * check for indirection
168 switch (n
& INDIR_MASK
) {
169 case 0: /* normal case, n == len */
172 case INDIR_MASK
: /* indirection */
175 default: /* illegal type */
182 return (cp
- comp_dn
);
186 * Routines to insert/extract short/long's.
191 _getshort(const u_char
*msgp
)
200 _getlong(const u_char
*msgp
)