]>
git.proxmox.com Git - mirror_edk2.git/blob - StdLib/BsdSocketLib/res_comp.c
2 * Copyright (c) 1985, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Portions copyright (c) 1999, 2000
9 * Redistribution and use in source and binary forms, with or without
10 * 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.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
23 * This product includes software developed by the University of
24 * California, Berkeley, Intel Corporation, and its contributors.
26 * 4. Neither the name of University, Intel Corporation, or their respective
27 * contributors may be used to endorse or promote products derived from
28 * this software without specific prior written permission.
30 * THIS SOFTWARE IS PROVIDED BY THE REGENTS, INTEL CORPORATION AND
31 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
32 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
33 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS,
34 * INTEL CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
35 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
36 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
40 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 * Portions Copyright (c) 1993 by Digital Equipment Corporation.
47 * Permission to use, copy, modify, and distribute this software for any
48 * purpose with or without fee is hereby granted, provided that the above
49 * copyright notice and this permission notice appear in all copies, and that
50 * the name of Digital Equipment Corporation not be used in advertising or
51 * publicity pertaining to distribution of the document or software without
52 * specific, written prior permission.
54 * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
55 * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
56 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
57 * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
58 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
59 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
60 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
65 * Portions Copyright (c) 1996 by Internet Software Consortium.
67 * Permission to use, copy, modify, and distribute this software for any
68 * purpose with or without fee is hereby granted, provided that the above
69 * copyright notice and this permission notice appear in all copies.
71 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
72 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
73 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
74 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
75 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
76 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
77 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
81 #if defined(LIBC_SCCS) && !defined(lint)
82 static char sccsid
[] = "@(#)res_comp.c 8.1 (Berkeley) 6/4/93";
83 static char orig_rcsid
[] = "From: Id: res_comp.c,v 8.11 1997/05/21 19:31:04 halley Exp $";
84 static char rcsid
[] = "$Id: res_comp.c,v 1.1.1.1 2003/11/19 01:51:35 kyu3 Exp $";
85 #endif /* LIBC_SCCS and not lint */
87 #include <sys/types.h>
88 #include <sys/param.h>
89 #include <netinet/in.h>
90 #include <arpa/nameser.h>
100 * Expand compressed domain name 'comp_dn' to full domain name.
101 * 'msg' is a pointer to the begining of the message,
102 * 'eomorig' points to the first location after the message,
103 * 'exp_dn' is a pointer to a buffer of size 'length' for the result.
104 * Return size of compressed name or -1 if there was an error.
107 dn_expand(const u_char
*msg
, const u_char
*eom
, const u_char
*src
,
108 char *dst
, int dstsiz
)
110 int n
= ns_name_uncompress(msg
, eom
, src
, dst
, (size_t)dstsiz
);
112 if (n
> 0 && dst
[0] == '.')
118 * Pack domain name 'exp_dn' in presentation form into 'comp_dn'.
119 * Return the size of the compressed name or -1.
120 * 'length' is the size of the array pointed to by 'comp_dn'.
123 dn_comp(const char *src
, u_char
*dst
, int dstsiz
,
124 u_char
**dnptrs
, u_char
**lastdnptr
)
126 return (ns_name_compress(src
, dst
, (size_t)dstsiz
,
127 (const u_char
**)dnptrs
,
128 (const u_char
**)lastdnptr
));
132 * Skip over a compressed domain name. Return the size or -1.
135 dn_skipname(const u_char
*ptr
, const u_char
*eom
) {
136 const u_char
*saveptr
= ptr
;
138 if (ns_name_skip(&ptr
, eom
) == -1)
140 return ((int)(ptr
- saveptr
));
144 * Verify that a domain name uses an acceptable character set.
148 * Note the conspicuous absence of ctype macros in these definitions. On
149 * non-ASCII hosts, we can't depend on string literals or ctype macros to
150 * tell us anything about network-format data. The rest of the BIND system
151 * is not careful about this, but for some reason, we're doing it right here.
154 #define hyphenchar(c) ((c) == 0x2d)
155 #define bslashchar(c) ((c) == 0x5c)
156 #define periodchar(c) ((c) == PERIOD)
157 #define asterchar(c) ((c) == 0x2a)
158 #define alphachar(c) (((c) >= 0x41 && (c) <= 0x5a) \
159 || ((c) >= 0x61 && (c) <= 0x7a))
160 #define digitchar(c) ((c) >= 0x30 && (c) <= 0x39)
162 #define borderchar(c) (alphachar(c) || digitchar(c))
163 #define middlechar(c) (borderchar(c) || hyphenchar(c))
164 #define domainchar(c) ((c) > 0x20 && (c) < 0x7f)
171 int ppch
= '\0', pch
= PERIOD
, ch
= *dn
++;
176 if (periodchar(ch
)) {
178 } else if (periodchar(pch
)) {
181 } else if (periodchar(nch
) || nch
== '\0') {
188 ppch
= pch
, pch
= ch
, ch
= nch
;
194 * hostname-like (A, MX, WKS) owners can have "*" as their first label
195 * but must otherwise be as a host name.
202 if (asterchar(dn
[0])) {
203 if (periodchar(dn
[1]))
204 return (res_hnok(dn
+2));
208 return (res_hnok(dn
));
212 * SOA RNAMEs and RP RNAMEs can have any printable character in their first
213 * label, but the rest of the name has to look like a host name.
222 /* "." is a valid missing representation */
226 /* otherwise <label>.<hostname> */
227 while ((ch
= *dn
++) != '\0') {
230 if (!escaped
&& periodchar(ch
))
234 else if (bslashchar(ch
))
238 return (res_hnok(dn
));
243 * This function is quite liberal, since RFC 1034's character sets are only
253 while ((ch
= *dn
++) != '\0')
261 * This module must export the following externally-visible symbols:
266 * Note that one _ comes from C and the others come from us.
268 void __putlong(u_int32_t src
, u_char
*dst
) { ns_put32(src
, dst
); }
269 void __putshort(u_int16_t src
, u_char
*dst
) { ns_put16(src
, dst
); }
270 u_int32_t
_getlong(const u_char
*src
) { return (ns_get32(src
)); }
271 u_int16_t
_getshort(const u_char
*src
) { return (ns_get16(src
)); }
272 #endif /*BIND_4_COMPAT*/