1 /* Convert a DNS domain name from presentation to wire format.
2 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (c) 1996,1999 by Internet Software Consortium.
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
15 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #include <arpa/nameser.h>
20 #include <shlib-compat.h>
22 /* Converts an ASCII string into an encoded domain name as per
23 RFC1035. Returns -1 if it fails, 1 if string was fully qualified,
24 0 is string was not fully qualified. Enforces label and domain
27 ___ns_name_pton (const char *src
, unsigned char *dst
, size_t dstsiz
)
29 unsigned char *label
, *bp
, *eom
;
37 while ((c
= *src
++) != 0)
41 if ('0' <= c
&& c
<= '9')
44 if ((c
= *src
++) == 0 || c
< '0' || c
> '9')
46 __set_errno (EMSGSIZE
);
50 if ((c
= *src
++) == 0 || c
< '0' || c
> '9')
52 __set_errno (EMSGSIZE
);
58 __set_errno (EMSGSIZE
);
73 if ((c
& NS_CMPRSFLGS
) != 0) /* Label too big. */
75 __set_errno (EMSGSIZE
);
80 __set_errno (EMSGSIZE
);
84 /* Fully qualified ? */
91 __set_errno (EMSGSIZE
);
96 if ((bp
- dst
) > MAXCDNAME
)
98 __set_errno (EMSGSIZE
);
103 if (c
== 0 || *src
== '.')
105 __set_errno (EMSGSIZE
);
113 __set_errno (EMSGSIZE
);
116 *bp
++ = (unsigned char) c
;
118 if (escaped
) /* Trailing backslash. */
120 __set_errno (EMSGSIZE
);
123 c
= (bp
- label
- 1);
124 if ((c
& NS_CMPRSFLGS
) != 0) /* Label too big. */
126 __set_errno (EMSGSIZE
);
131 __set_errno (EMSGSIZE
);
139 __set_errno (EMSGSIZE
);
144 if ((bp
- dst
) > MAXCDNAME
) /* src too big. */
146 __set_errno (EMSGSIZE
);
151 versioned_symbol (libc
, ___ns_name_pton
, ns_name_pton
, GLIBC_2_34
);
152 versioned_symbol (libc
, ___ns_name_pton
, __ns_name_pton
, GLIBC_PRIVATE
);
153 libc_hidden_ver (___ns_name_pton
, __ns_name_pton
)
155 #if OTHER_SHLIB_COMPAT (libresolv, GLIBC_2_9, GLIBC_2_34)
156 compat_symbol (libresolv
, ___ns_name_pton
, ns_name_pton
, GLIBC_2_9
);