Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/net sync with BIND 4.9.7. uses BIND 8.x codebase f...



details:   https://anonhg.NetBSD.org/src/rev/1d782b26eabb
branches:  trunk
changeset: 485346:1d782b26eabb
user:      itojun <itojun%NetBSD.org@localhost>
date:      Tue Apr 25 14:39:00 2000 +0000

description:
sync with BIND 4.9.7.  uses BIND 8.x codebase for dn_expand().
hyphenchar() definition is now fixed to specwise-correct declaration
(only "-" is permitted).  may need more KNF and/or delint.

diffstat:

 lib/libc/net/res_comp.c |  951 ++++++++++++++++++++++++++++++++++-------------
 1 files changed, 686 insertions(+), 265 deletions(-)

diffs (truncated from 1027 to 300 lines):

diff -r 288ae535e516 -r 1d782b26eabb lib/libc/net/res_comp.c
--- a/lib/libc/net/res_comp.c   Tue Apr 25 14:28:13 2000 +0000
+++ b/lib/libc/net/res_comp.c   Tue Apr 25 14:39:00 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: res_comp.c,v 1.17 2000/01/22 22:19:16 mycroft Exp $    */
+/*     $NetBSD: res_comp.c,v 1.18 2000/04/25 14:39:00 itojun Exp $     */
 
 /*-
  * Copyright (c) 1985, 1993
@@ -57,19 +57,20 @@
 #if defined(LIBC_SCCS) && !defined(lint)
 #if 0
 static char sccsid[] = "@(#)res_comp.c 8.1 (Berkeley) 6/4/93";
-static char rcsid[] = "Id: res_comp.c,v 8.12 1997/06/01 20:34:37 vixie Exp ";
+static char rcsid[] = "Id: res_comp.c,v 8.14 1998/05/11 04:19:47 vixie Exp ";
 #else
-__RCSID("$NetBSD: res_comp.c,v 1.17 2000/01/22 22:19:16 mycroft Exp $");
+__RCSID("$NetBSD: res_comp.c,v 1.18 2000/04/25 14:39:00 itojun Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
 #include <sys/param.h>
+#include <netinet/in.h>
 #include <arpa/nameser.h>
-#include <netinet/in.h>
 
 #include <assert.h>
 #include <ctype.h>
+#include <errno.h>
 #include <resolv.h>
 #include <stdio.h>
 #include <string.h>
@@ -80,9 +81,20 @@
 __weak_alias(dn_comp,__dn_comp)
 #endif
 
-static int dn_find __P((const u_char *, u_char *, u_char **, u_char **));
 static int mklower __P((int));
 
+static int     ns_name_ntop __P((const u_char *, char *, size_t));
+static int     ns_name_pton __P((const char *, u_char *, size_t));
+static int     ns_name_unpack __P((const u_char *, const u_char *,
+                                   const u_char *, u_char *, size_t));
+static int     ns_name_pack __P((const u_char *, u_char *, size_t,
+                                 const u_char **, const u_char **));
+static int     ns_name_uncompress __P((const u_char *, const u_char *,
+                                       const u_char *, char *, size_t));
+static int     ns_name_compress __P((const char *, u_char *, size_t,
+                                     const u_char **, const u_char **));
+static int     ns_name_skip __P((const u_char **, const u_char *));
+
 /*
  * Expand compressed domain name 'comp_dn' to full domain name.
  * 'msg' is a pointer to the begining of the message,
@@ -91,282 +103,51 @@
  * Return size of compressed name or -1 if there was an error.
  */
 int
-dn_expand(msg, eomorig, comp_dn, exp_dn, length)
-       const u_char *msg, *eomorig, *comp_dn;
-       char *exp_dn;
-       int length;
+dn_expand(msg, eom, src, dst, dstsiz)
+       const u_char *msg;
+       const u_char *eom;
+       const u_char *src;
+       char *dst;
+       int dstsiz;
 {
-       register const u_char *cp;
-       register char *dn;
-       register int n, c;
-       char *eom;
-       int len = -1, checked = 0, octets = 0;
-
-       _DIAGASSERT(msg != NULL);
-       _DIAGASSERT(eomorig != NULL);
-       _DIAGASSERT(comp_dn != NULL);
-       _DIAGASSERT(exp_dn != NULL);
+       int n = ns_name_uncompress(msg, eom, src, dst, (size_t)dstsiz);
 
-       dn = exp_dn;
-       cp = comp_dn;
-       eom = exp_dn + length;
-       /*
-        * fetch next label in domain name
-        */
-       while ((n = *cp++) != 0) {
-               /*
-                * Check for indirection
-                */
-               switch (n & INDIR_MASK) {
-               case 0:
-                       octets += (n + 1);
-                       if (octets > MAXCDNAME)
-                               return (-1);
-                       if (dn != exp_dn) {
-                               if (dn >= eom)
-                                       return (-1);
-                               *dn++ = '.';
-                       }
-                       if (dn+n >= eom)
-                               return (-1);
-                       checked += n + 1;
-                       while (--n >= 0) {
-                               if (((c = *cp++) == '.') || (c == '\\')) {
-                                       if (dn + n + 2 >= eom)
-                                               return (-1);
-                                       *dn++ = '\\';
-                               }
-                               *dn++ = c;
-                               if (cp >= eomorig)      /* out of range */
-                                       return (-1);
-                       }
-                       break;
-
-               case INDIR_MASK:
-                       if (len < 0)
-                               len = cp - comp_dn + 1;
-                       cp = msg + (((n & 0x3f) << 8) | (*cp & 0xff));
-                       if (cp < msg || cp >= eomorig)  /* out of range */
-                               return (-1);
-                       checked += 2;
-                       /*
-                        * Check for loops in the compressed name;
-                        * if we've looked at the whole message,
-                        * there must be a loop.
-                        */
-                       if (checked >= eomorig - msg)
-                               return (-1);
-                       break;
-
-               default:
-                       return (-1);                    /* flag error */
-               }
-       }
-       *dn = '\0';
-       if (len < 0)
-               len = cp - comp_dn;
-       return (len);
+       if (n > 0 && dst[0] == '.')
+               dst[0] = '\0';
+       return (n);
 }
 
 /*
- * Compress domain name 'exp_dn' into 'comp_dn'.
+ * Pack domain name 'exp_dn' in presentation form into 'comp_dn'.
  * Return the size of the compressed name or -1.
  * 'length' is the size of the array pointed to by 'comp_dn'.
- * 'dnptrs' is a list of pointers to previous compressed names. dnptrs[0]
- * is a pointer to the beginning of the message. The list ends with NULL.
- * 'lastdnptr' is a pointer to the end of the arrary pointed to
- * by 'dnptrs'. Side effect is to update the list of pointers for
- * labels inserted into the message as we compress the name.
- * If 'dnptr' is NULL, we don't try to compress names. If 'lastdnptr'
- * is NULL, we don't update the list.
  */
 int
-dn_comp(exp_dn, comp_dn, length, dnptrs, lastdnptr)
-       const char *exp_dn;
-       u_char *comp_dn, **dnptrs, **lastdnptr;
-       int length;
+dn_comp(src, dst, dstsiz, dnptrs, lastdnptr)
+       const char *src;
+       u_char *dst;
+       int dstsiz;
+       u_char **dnptrs;
+       u_char **lastdnptr;
 {
-       u_char *cp;
-       const u_char *dn;
-       int c, l;
-       u_char **cpp, **lpp, *sp, *eob;
-       u_char *msg;
-
-       _DIAGASSERT(exp_dn != NULL);
-       _DIAGASSERT(comp_dn != NULL);
-       /* dnptr may be NULL */
-       /* lastdnptr may be NULL */
-
-       dn = (const u_char *)exp_dn;
-       cp = comp_dn;
-       if (length > MAXCDNAME)
-               length = MAXCDNAME;
-       eob = cp + length;
-       lpp = cpp = NULL;
-       if (dnptrs != NULL) {
-               if ((msg = *dnptrs++) != NULL) {
-                       for (cpp = dnptrs; *cpp != NULL; cpp++)
-                               ;
-                       lpp = cpp;      /* end of list to search */
-               }
-       } else
-               msg = NULL;
-       for (c = *dn++; c != '\0'; ) {
-               /* look to see if we can use pointers */
-               if (msg != NULL) {
-                       if ((l = dn_find(dn-1, msg, dnptrs, lpp)) >= 0) {
-                               if (cp+1 >= eob)
-                                       return (-1);
-                               *cp++ = ((u_int32_t)l >> 8) | INDIR_MASK;
-                               *cp++ = l % 256;
-                               return (cp - comp_dn);
-                       }
-                       /* not found, save it */
-                       if (lastdnptr != NULL && cpp < lastdnptr-1) {
-                               *cpp++ = cp;
-                               *cpp = NULL;
-                       }
-               }
-               sp = cp++;      /* save ptr to length byte */
-               do {
-                       if (c == '.') {
-                               c = *dn++;
-                               break;
-                       }
-                       if (c == '\\') {
-                               if ((c = *dn++) == '\0')
-                                       break;
-                       }
-                       if (cp >= eob) {
-                               if (msg != NULL)
-                                       *lpp = NULL;
-                               return (-1);
-                       }
-                       *cp++ = c;
-               } while ((c = *dn++) != '\0');
-               /* catch trailing '.'s but not '..' */
-               if ((l = cp - sp - 1) == 0 && c == '\0') {
-                       cp--;
-                       break;
-               }
-               if (l <= 0 || l > MAXLABEL) {
-                       if (msg != NULL)
-                               *lpp = NULL;
-                       return (-1);
-               }
-               *sp = l;
-       }
-       if (cp >= eob) {
-               if (msg != NULL)
-                       *lpp = NULL;
-               return (-1);
-       }
-       *cp++ = '\0';
-       return (cp - comp_dn);
+       return (ns_name_compress(src, dst, (size_t)dstsiz,
+                                (const u_char **)dnptrs,
+                                (const u_char **)lastdnptr));
 }
 
 /*
  * Skip over a compressed domain name. Return the size or -1.
  */
 int
-__dn_skipname(comp_dn, eom)
-       const u_char *comp_dn, *eom;
+__dn_skipname(ptr, eom)
+       const u_char *ptr;
+       const u_char *eom;
 {
-       register const u_char *cp;
-       register int n;
-
-       _DIAGASSERT(comp_dn != NULL);
-       _DIAGASSERT(eom != NULL);
-
-       cp = comp_dn;
-       while (cp < eom && (n = *cp++)) {
-               /*
-                * check for indirection
-                */
-               switch (n & INDIR_MASK) {
-               case 0:                 /* normal case, n == len */
-                       cp += n;
-                       continue;
-               case INDIR_MASK:        /* indirection */
-                       cp++;
-                       break;
-               default:                /* illegal type */
-                       return (-1);
-               }
-               break;
-       }
-       if (cp > eom)
-               return (-1);
-       return (cp - comp_dn);
-}
-
-static int
-mklower(ch)
-       register int ch;
-{
-       if (isascii(ch) && isupper(ch))
-               return (tolower(ch));
-       return (ch);
-}
+       const u_char *saveptr = ptr;



Home | Main Index | Thread Index | Old Index