Deleted Added
full compact
19c19
< static const char rcsid[] = "$Id: ns_name.c,v 1.8.18.2 2005/04/27 05:01:08 sra Exp $";
---
> static const char rcsid[] = "$Id: ns_name.c,v 1.11 2009/01/23 19:59:16 each Exp $";
20a21,22
> #include <sys/cdefs.h>
> __FBSDID("$FreeBSD: head/lib/libc/nameser/ns_name.c 269867 2014-08-12 12:36:06Z ume $");
124c126
< return(-1);
---
> return (-1);
136c138
< return(-1);
---
> return (-1);
141c143
< return(-1);
---
> return (-1);
199a202,205
> int
> ns_name_pton(const char *src, u_char *dst, size_t dstsiz) {
> return (ns_name_pton2(src, dst, dstsiz, NULL));
> }
200a207,218
> /*
> * ns_name_pton2(src, dst, dstsiz, *dstlen)
> * Convert a ascii string into an encoded domain name as per RFC1035.
> * return:
> * -1 if it fails
> * 1 if string was fully qualified
> * 0 is string was not fully qualified
> * side effects:
> * fills in *dstlen (if non-NULL)
> * notes:
> * Enforces label and domain length limits.
> */
202,203c220
< ns_name_pton(const char *src, u_char *dst, size_t dstsiz)
< {
---
> ns_name_pton2(const char *src, u_char *dst, size_t dstsiz, size_t *dstlen) {
218c235
< return(-1);
---
> return (-1);
224c241
< return(-1);
---
> return (-1);
232c249
< return(-1);
---
> return (-1);
283a301,302
> if (dstlen != NULL)
> *dstlen = (bp - dst);
320a340,341
> if (dstlen != NULL)
> *dstlen = (bp - dst);
368c389
< if (isupper(c))
---
> if (isascii(c) && isupper(c))
387a409,423
> return (ns_name_unpack2(msg, eom, src, dst, dstsiz, NULL));
> }
>
> /*
> * ns_name_unpack2(msg, eom, src, dst, dstsiz, *dstlen)
> * Unpack a domain name from a message, source may be compressed.
> * return:
> * -1 if it fails, or consumed octets if it succeeds.
> * side effect:
> * fills in *dstlen (if non-NULL).
> */
> int
> ns_name_unpack2(const u_char *msg, const u_char *eom, const u_char *src,
> u_char *dst, size_t dstsiz, size_t *dstlen)
> {
410c446
< return(-1);
---
> return (-1);
452c488,490
< *dstp = '\0';
---
> *dstp++ = 0;
> if (dstlen != NULL)
> *dstlen = dstp - dst;
511c549
< return(-1);
---
> return (-1);
658c696
< return(-1);
---
> return (-1);
678a717,860
> /* Find the number of octets an nname takes up, including the root label.
> * (This is basically ns_name_skip() without compression-pointer support.)
> * ((NOTE: can only return zero if passed-in namesiz argument is zero.))
> */
> ssize_t
> ns_name_length(ns_nname_ct nname, size_t namesiz) {
> ns_nname_ct orig = nname;
> u_int n;
>
> while (namesiz-- > 0 && (n = *nname++) != 0) {
> if ((n & NS_CMPRSFLGS) != 0) {
> errno = EISDIR;
> return (-1);
> }
> if (n > namesiz) {
> errno = EMSGSIZE;
> return (-1);
> }
> nname += n;
> namesiz -= n;
> }
> return (nname - orig);
> }
>
> /* Compare two nname's for equality. Return -1 on error (setting errno).
> */
> int
> ns_name_eq(ns_nname_ct a, size_t as, ns_nname_ct b, size_t bs) {
> ns_nname_ct ae = a + as, be = b + bs;
> int ac, bc;
>
> while (ac = *a, bc = *b, ac != 0 && bc != 0) {
> if ((ac & NS_CMPRSFLGS) != 0 || (bc & NS_CMPRSFLGS) != 0) {
> errno = EISDIR;
> return (-1);
> }
> if (a + ac >= ae || b + bc >= be) {
> errno = EMSGSIZE;
> return (-1);
> }
> if (ac != bc || strncasecmp((const char *) ++a,
> (const char *) ++b, ac) != 0)
> return (0);
> a += ac, b += bc;
> }
> return (ac == 0 && bc == 0);
> }
>
> /* Is domain "A" owned by (at or below) domain "B"?
> */
> int
> ns_name_owned(ns_namemap_ct a, int an, ns_namemap_ct b, int bn) {
> /* If A is shorter, it cannot be owned by B. */
> if (an < bn)
> return (0);
>
> /* If they are unequal before the length of the shorter, A cannot... */
> while (bn > 0) {
> if (a->len != b->len ||
> strncasecmp((const char *) a->base,
> (const char *) b->base, a->len) != 0)
> return (0);
> a++, an--;
> b++, bn--;
> }
>
> /* A might be longer or not, but either way, B owns it. */
> return (1);
> }
>
> /* Build an array of <base,len> tuples from an nname, top-down order.
> * Return the number of tuples (labels) thus discovered.
> */
> int
> ns_name_map(ns_nname_ct nname, size_t namelen, ns_namemap_t map, int mapsize) {
> u_int n;
> int l;
>
> n = *nname++;
> namelen--;
>
> /* Root zone? */
> if (n == 0) {
> /* Extra data follows name? */
> if (namelen > 0) {
> errno = EMSGSIZE;
> return (-1);
> }
> return (0);
> }
>
> /* Compression pointer? */
> if ((n & NS_CMPRSFLGS) != 0) {
> errno = EISDIR;
> return (-1);
> }
>
> /* Label too long? */
> if (n > namelen) {
> errno = EMSGSIZE;
> return (-1);
> }
>
> /* Recurse to get rest of name done first. */
> l = ns_name_map(nname + n, namelen - n, map, mapsize);
> if (l < 0)
> return (-1);
>
> /* Too many labels? */
> if (l >= mapsize) {
> errno = ENAMETOOLONG;
> return (-1);
> }
>
> /* We're on our way back up-stack, store current map data. */
> map[l].base = nname;
> map[l].len = n;
> return (l + 1);
> }
>
> /* Count the labels in a domain name. Root counts, so COM. has two. This
> * is to make the result comparable to the result of ns_name_map().
> */
> int
> ns_name_labels(ns_nname_ct nname, size_t namesiz) {
> int ret = 0;
> u_int n;
>
> while (namesiz-- > 0 && (n = *nname++) != 0) {
> if ((n & NS_CMPRSFLGS) != 0) {
> errno = EISDIR;
> return (-1);
> }
> if (n > namesiz) {
> errno = EMSGSIZE;
> return (-1);
> }
> nname += n;
> namesiz -= n;
> ret++;
> }
> return (ret + 1);
> }
>
809c991
< return(-1);
---
> return (-1);
842c1024
< return(dn - beg);
---
> return (dn - beg);
847c1029
< unsigned char ** dst, unsigned const char *eom)
---
> unsigned char ** dst, unsigned const char *eom)
861c1043
< return(EINVAL);
---
> return (EINVAL);
865c1047
< return(EINVAL);
---
> return (EINVAL);
867c1049
< return(EINVAL);
---
> return (EINVAL);
874c1056
< return(EINVAL);
---
> return (EINVAL);
877c1059
< return(EINVAL);
---
> return (EINVAL);
889c1071
< return(EINVAL);
---
> return (EINVAL);
894c1076
< return(EINVAL);
---
> return (EINVAL);
900c1082
< return(EINVAL);
---
> return (EINVAL);
906c1088
< return(EINVAL);
---
> return (EINVAL);
917c1099
< return(EMSGSIZE);
---
> return (EMSGSIZE);
931c1113
< return(EINVAL);
---
> return (EINVAL);
934c1116
< return(EINVAL);
---
> return (EINVAL);
948c1130
< return(0);
---
> return (0);
959c1141
< return(-1);
---
> return (-1);
966c1148
< return((bitlen + 7 ) / 8 + 1);
---
> return ((bitlen + 7 ) / 8 + 1);
968c1150
< return(-1); /*%< unknwon ELT */
---
> return (-1); /*%< unknwon ELT */
970c1152
< return(l);
---
> return (l);