]>
git.proxmox.com Git - mirror_edk2.git/blob - StdLib/BsdSocketLib/res_comp.c
2 Copyright (c) 1999 - 2014, Intel Corporation. All rights reserved.<BR>
3 This program and the accompanying materials are licensed and made available
4 under the terms and conditions of the BSD License which accompanies this
5 distribution. The full text of the license may be found at
6 http://opensource.org/licenses/bsd-license.php.
8 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
9 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 * Copyright (c) 1985, 1993
13 * The Regents of the University of California. All rights reserved.
15 * Portions copyright (c) 1999, 2000
17 * All rights reserved.
19 * Redistribution and use in source and binary forms, with or without
20 * modification, are permitted provided that the following conditions
23 * 1. Redistributions of source code must retain the above copyright
24 * notice, this list of conditions and the following disclaimer.
26 * 2. Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in the
28 * documentation and/or other materials provided with the distribution.
30 * 3. All advertising materials mentioning features or use of this software
31 * must display the following acknowledgement:
33 * This product includes software developed by the University of
34 * California, Berkeley, Intel Corporation, and its contributors.
36 * 4. Neither the name of University, Intel Corporation, or their respective
37 * contributors may be used to endorse or promote products derived from
38 * this software without specific prior written permission.
40 * THIS SOFTWARE IS PROVIDED BY THE REGENTS, INTEL CORPORATION AND
41 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
42 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
43 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS,
44 * INTEL CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
45 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
47 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
48 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
50 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55 * Portions Copyright (c) 1993 by Digital Equipment Corporation.
57 * Permission to use, copy, modify, and distribute this software for any
58 * purpose with or without fee is hereby granted, provided that the above
59 * copyright notice and this permission notice appear in all copies, and that
60 * the name of Digital Equipment Corporation not be used in advertising or
61 * publicity pertaining to distribution of the document or software without
62 * specific, written prior permission.
64 * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
65 * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
66 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
67 * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
68 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
69 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
70 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
75 * Portions Copyright (c) 1996 by Internet Software Consortium.
77 * Permission to use, copy, modify, and distribute this software for any
78 * purpose with or without fee is hereby granted, provided that the above
79 * copyright notice and this permission notice appear in all copies.
81 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
82 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
83 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
84 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
85 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
86 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
87 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
91 #if defined(LIBC_SCCS) && !defined(lint)
92 static char sccsid
[] = "@(#)res_comp.c 8.1 (Berkeley) 6/4/93";
93 static char orig_rcsid
[] = "From: Id: res_comp.c,v 8.11 1997/05/21 19:31:04 halley Exp $";
94 static char rcsid
[] = "$Id: res_comp.c,v 1.1.1.1 2003/11/19 01:51:35 kyu3 Exp $";
95 #endif /* LIBC_SCCS and not lint */
97 #include <sys/types.h>
98 #include <sys/param.h>
99 #include <netinet/in.h>
100 #include <arpa/nameser.h>
107 #define BIND_4_COMPAT
110 * Expand compressed domain name 'comp_dn' to full domain name.
111 * 'msg' is a pointer to the begining of the message,
112 * 'eomorig' points to the first location after the message,
113 * 'exp_dn' is a pointer to a buffer of size 'length' for the result.
114 * Return size of compressed name or -1 if there was an error.
117 dn_expand(const u_char
*msg
, const u_char
*eom
, const u_char
*src
,
118 char *dst
, int dstsiz
)
120 int n
= ns_name_uncompress(msg
, eom
, src
, dst
, (size_t)dstsiz
);
122 if (n
> 0 && dst
[0] == '.')
128 * Pack domain name 'exp_dn' in presentation form into 'comp_dn'.
129 * Return the size of the compressed name or -1.
130 * 'length' is the size of the array pointed to by 'comp_dn'.
133 dn_comp(const char *src
, u_char
*dst
, int dstsiz
,
134 u_char
**dnptrs
, u_char
**lastdnptr
)
136 return (ns_name_compress(src
, dst
, (size_t)dstsiz
,
137 (const u_char
**)dnptrs
,
138 (const u_char
**)lastdnptr
));
142 * Skip over a compressed domain name. Return the size or -1.
145 dn_skipname(const u_char
*ptr
, const u_char
*eom
) {
146 const u_char
*saveptr
= ptr
;
148 if (ns_name_skip(&ptr
, eom
) == -1)
150 return ((int)(ptr
- saveptr
));
154 * Verify that a domain name uses an acceptable character set.
158 * Note the conspicuous absence of ctype macros in these definitions. On
159 * non-ASCII hosts, we can't depend on string literals or ctype macros to
160 * tell us anything about network-format data. The rest of the BIND system
161 * is not careful about this, but for some reason, we're doing it right here.
164 #define hyphenchar(c) ((c) == 0x2d)
165 #define bslashchar(c) ((c) == 0x5c)
166 #define periodchar(c) ((c) == PERIOD)
167 #define asterchar(c) ((c) == 0x2a)
168 #define alphachar(c) (((c) >= 0x41 && (c) <= 0x5a) \
169 || ((c) >= 0x61 && (c) <= 0x7a))
170 #define digitchar(c) ((c) >= 0x30 && (c) <= 0x39)
172 #define borderchar(c) (alphachar(c) || digitchar(c))
173 #define middlechar(c) (borderchar(c) || hyphenchar(c))
174 #define domainchar(c) ((c) > 0x20 && (c) < 0x7f)
181 int pch
= PERIOD
, ch
= *dn
++;
186 if (periodchar(ch
)) {
188 } else if (periodchar(pch
)) {
191 } else if (periodchar(nch
) || nch
== '\0') {
205 * hostname-like (A, MX, WKS) owners can have "*" as their first label
206 * but must otherwise be as a host name.
213 if (asterchar(dn
[0])) {
214 if (periodchar(dn
[1]))
215 return (res_hnok(dn
+2));
219 return (res_hnok(dn
));
223 * SOA RNAMEs and RP RNAMEs can have any printable character in their first
224 * label, but the rest of the name has to look like a host name.
233 /* "." is a valid missing representation */
237 /* otherwise <label>.<hostname> */
238 while ((ch
= *dn
++) != '\0') {
241 if (!escaped
&& periodchar(ch
))
245 else if (bslashchar(ch
))
249 return (res_hnok(dn
));
254 * This function is quite liberal, since RFC 1034's character sets are only
264 while ((ch
= *dn
++) != '\0')
272 * This module must export the following externally-visible symbols:
277 * Note that one _ comes from C and the others come from us.
279 void __putlong(u_int32_t src
, u_char
*dst
) { ns_put32(src
, dst
); }
280 void __putshort(u_int16_t src
, u_char
*dst
) { ns_put16(src
, dst
); }
281 u_int32_t
_getlong(const u_char
*src
) { return (ns_get32(src
)); }
282 u_int16_t
_getshort(const u_char
*src
) { return (ns_get16(src
)); }
283 #endif /*BIND_4_COMPAT*/