]> granicus.if.org Git - php/commitdiff
- Add bindlib_w32 to the PHP tree
authorAndi Gutmans <andi@php.net>
Fri, 31 Mar 2000 09:29:28 +0000 (09:29 +0000)
committerAndi Gutmans <andi@php.net>
Fri, 31 Mar 2000 09:29:28 +0000 (09:29 +0000)
52 files changed:
bindlib_w32/arpa/Makefile [new file with mode: 0644]
bindlib_w32/arpa/inet.h [new file with mode: 0644]
bindlib_w32/arpa/nameser.h [new file with mode: 0644]
bindlib_w32/base64.c [new file with mode: 0644]
bindlib_w32/bindlib.dsp [new file with mode: 0644]
bindlib_w32/bindlib.dsw [new file with mode: 0644]
bindlib_w32/conf/bsdinstall.sh [new file with mode: 0644]
bindlib_w32/conf/copyright [new file with mode: 0644]
bindlib_w32/conf/master/README [new file with mode: 0644]
bindlib_w32/conf/master/named.boo [new file with mode: 0644]
bindlib_w32/conf/master/named.boot [new file with mode: 0644]
bindlib_w32/conf/master/named.boot.master [new file with mode: 0644]
bindlib_w32/conf/master/named.hos [new file with mode: 0644]
bindlib_w32/conf/master/named.hosts [new file with mode: 0644]
bindlib_w32/conf/master/named.loc [new file with mode: 0644]
bindlib_w32/conf/master/named.local [new file with mode: 0644]
bindlib_w32/conf/master/named.rev [new file with mode: 0644]
bindlib_w32/conf/master/namedboot.master [new file with mode: 0644]
bindlib_w32/conf/master/root.cac [new file with mode: 0644]
bindlib_w32/conf/master/root.cache [new file with mode: 0644]
bindlib_w32/conf/options.h [new file with mode: 0644]
bindlib_w32/conf/portability.h [new file with mode: 0644]
bindlib_w32/gethnamaddr.c [new file with mode: 0644]
bindlib_w32/getnetbyaddr.c [new file with mode: 0644]
bindlib_w32/getnetbyname.c [new file with mode: 0644]
bindlib_w32/getnetent.c [new file with mode: 0644]
bindlib_w32/getnetnamadr.c [new file with mode: 0644]
bindlib_w32/herror.c [new file with mode: 0644]
bindlib_w32/hostnamelen.c [new file with mode: 0644]
bindlib_w32/inet_addr.c [new file with mode: 0644]
bindlib_w32/inet_net_ntop.c [new file with mode: 0644]
bindlib_w32/inet_net_pton.c [new file with mode: 0644]
bindlib_w32/inet_neta.c [new file with mode: 0644]
bindlib_w32/inet_ntop.c [new file with mode: 0644]
bindlib_w32/inet_pton.c [new file with mode: 0644]
bindlib_w32/named/pathnames.h [new file with mode: 0644]
bindlib_w32/netdb.h [new file with mode: 0644]
bindlib_w32/nsap_addr.c [new file with mode: 0644]
bindlib_w32/res_comp.c [new file with mode: 0644]
bindlib_w32/res_data.c [new file with mode: 0644]
bindlib_w32/res_debug.c [new file with mode: 0644]
bindlib_w32/res_init.c [new file with mode: 0644]
bindlib_w32/res_mkquery.c [new file with mode: 0644]
bindlib_w32/res_nt_misc.c [new file with mode: 0644]
bindlib_w32/res_query.c [new file with mode: 0644]
bindlib_w32/res_send.c [new file with mode: 0644]
bindlib_w32/resolv.h [new file with mode: 0644]
bindlib_w32/sethostent.c [new file with mode: 0644]
bindlib_w32/sys/Makefile [new file with mode: 0644]
bindlib_w32/sys/bitypes.h [new file with mode: 0644]
bindlib_w32/sys/cdefs.h [new file with mode: 0644]
bindlib_w32/writev.c [new file with mode: 0644]

diff --git a/bindlib_w32/arpa/Makefile b/bindlib_w32/arpa/Makefile
new file mode 100644 (file)
index 0000000..2ebfe2c
--- /dev/null
@@ -0,0 +1,70 @@
+# ++Copyright++ 1993
+# -
+# Copyright (c) 
+#    The Regents of the University of California.  All rights reserved.
+# 
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+# 3. All advertising materials mentioning features or use of this software
+#    must display the following acknowledgement:
+#      This product includes software developed by the University of
+#      California, Berkeley and its contributors.
+# 4. Neither the name of the University nor the names of its contributors
+#    may be used to endorse or promote products derived from this software
+#    without specific prior written permission.
+# 
+# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+# -
+# Portions Copyright (c) 1993 by Digital Equipment Corporation.
+# 
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies, and that
+# the name of Digital Equipment Corporation not be used in advertising or
+# publicity pertaining to distribution of the document or software without
+# specific, written prior permission.
+# 
+# THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+# WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
+# CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+# PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+# SOFTWARE.
+# -
+# --Copyright--
+
+HFILES = inet.h nameser.h
+
+DESTDIR =
+DESTINC = /usr/include
+
+all depend:
+
+clean:
+       rm -f *~ *.BAK *.CKP *.orig
+
+install: ${DESTDIR}${DESTINC}/arpa
+       set -x; for x in ${HFILES}; do \
+               ${INSTALL} -c -m 444 $$x ${DESTDIR}${DESTINC}/arpa/$$x; \
+       done
+
+${DESTDIR}${DESTINC}/arpa:
+       mkdir $@
diff --git a/bindlib_w32/arpa/inet.h b/bindlib_w32/arpa/inet.h
new file mode 100644 (file)
index 0000000..866baf1
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * ++Copyright++ 1983, 1993
+ * -
+ * Copyright (c) 1983, 1993
+ *    The Regents of the University of California.  All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ * 
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+
+/*
+ *     @(#)inet.h      8.1 (Berkeley) 6/2/93
+ *     $Id$
+ */
+
+#ifndef _INET_H_
+#define        _INET_H_
+
+/* External definitions for functions in inet(3) */
+
+#ifndef WINNT
+#include <sys/param.h>
+#if (!defined(BSD)) || (BSD < 199306)
+# include <sys/bitypes.h>
+#else
+# include <sys/types.h>
+#endif
+#else
+#define FD_SETSIZE 512
+#include <winsock.h>
+#endif /* WINNT */
+
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+#ifndef WINNT
+unsigned long   inet_addr __P((const char *));
+#endif
+
+int             inet_aton __P((const char *, struct in_addr *));
+unsigned long   inet_lnaof __P((struct in_addr));
+struct in_addr  inet_makeaddr __P((u_long , u_long));
+char *          inet_neta __P((u_long, char *, size_t));
+unsigned long   inet_netof __P((struct in_addr));
+unsigned long   inet_network __P((const char *));
+char           *inet_net_ntop __P((int, const void *, int, char *, size_t));
+int             inet_net_pton __P((int, const char *, void *, size_t));
+#ifndef WINNT
+char           *inet_ntoa __P((struct in_addr));
+#endif
+int             inet_pton __P((int, const char *, void *));
+const char     *inet_ntop __P((int, const void *, char *, size_t));
+u_int           inet_nsap_addr __P((const char *, u_char *, int));
+char           *inet_nsap_ntoa __P((int, const u_char *, char *));
+__END_DECLS
+
+#endif /* !_INET_H_ */
diff --git a/bindlib_w32/arpa/nameser.h b/bindlib_w32/arpa/nameser.h
new file mode 100644 (file)
index 0000000..431071e
--- /dev/null
@@ -0,0 +1,396 @@
+/*
+ * ++Copyright++ 1983, 1989, 1993
+ * -
+ * Copyright (c) 1983, 1989, 1993
+ *    The Regents of the University of California.  All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ * 
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * Portions Copyright (c) 1995 by International Business Machines, Inc.
+ *
+ * International Business Machines, Inc. (hereinafter called IBM) grants
+ * permission under its copyrights to use, copy, modify, and distribute this
+ * Software with or without fee, provided that the above copyright notice and
+ * all paragraphs of this notice appear in all copies, and that the name of IBM
+ * not be used in connection with the marketing of any product incorporating
+ * the Software or modifications thereof, without specific, written prior
+ * permission.
+ *
+ * To the extent it has a right to do so, IBM grants an immunity from suit
+ * under its patents, if any, for the use, sale or manufacture of products to
+ * the extent that such products are used for performing Domain Name System
+ * dynamic updates in TCP/IP networks by means of the Software.  No immunity is
+ * granted for any product per se or for any other function of any product.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE.  IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
+ * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
+ * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ * --Copyright--
+ */
+
+/*
+ *      @(#)nameser.h  8.1 (Berkeley) 6/2/93
+ *     $Id$
+ */
+
+#ifndef _NAMESER_H_
+#define _NAMESER_H_
+
+#ifndef WINNT
+#include <sys/param.h>
+#endif
+#if (!defined(BSD)) || (BSD < 199306)
+# include <sys/bitypes.h>
+#else
+# include <sys/types.h>
+#endif
+#include <sys/cdefs.h>
+
+#ifdef _AUX_SOURCE
+# include <sys/types.h>
+#endif
+
+/*
+ * revision information.  this is the release date in YYYYMMDD format.
+ * it can change every day so the right thing to do with it is use it
+ * in preprocessor commands such as "#if (__BIND > 19931104)".  do not
+ * compare for equality; rather, use it to determine whether your resolver
+ * is new enough to contain a certain feature.
+ */
+
+#define __BIND         19960801        /* interface version stamp */
+
+/*
+ * Define constants based on rfc883
+ */
+#define PACKETSZ       512             /* maximum packet size */
+#define MAXDNAME       1025            /* maximum presentation domain name */
+#define MAXCDNAME      255             /* maximum compressed domain name */
+#define MAXLABEL       63              /* maximum length of domain label */
+#define HFIXEDSZ       12              /* #/bytes of fixed data in header */
+#define QFIXEDSZ       4               /* #/bytes of fixed data in query */
+#define RRFIXEDSZ      10              /* #/bytes of fixed data in r record */
+#define INT32SZ                4               /* for systems without 32-bit ints */
+#define INT16SZ                2               /* for systems without 16-bit ints */
+#define INADDRSZ       4               /* IPv4 T_A */
+#define IN6ADDRSZ      16              /* IPv6 T_AAAA */
+
+/*
+ * Internet nameserver port number
+ */
+#define NAMESERVER_PORT        53
+
+/*
+ * Currently defined opcodes
+ */
+#define QUERY          0x0             /* standard query */
+#define IQUERY         0x1             /* inverse query */
+#define STATUS         0x2             /* nameserver status query */
+/*#define xxx          0x3*/           /* 0x3 reserved */
+#define NS_NOTIFY_OP   0x4             /* notify secondary of SOA change */
+/*
+ * Currently defined response codes
+ */
+#if !(defined(WINNT) && defined(NOERROR))
+#define NOERROR                0               /* no error */
+#endif
+#define FORMERR                1               /* format error */
+#define SERVFAIL       2               /* server failure */
+#define NXDOMAIN       3               /* non existent domain */
+#define NOTIMP         4               /* not implemented */
+#define REFUSED                5               /* query refused */
+
+/*
+ * Type values for resources and queries
+ */
+#define T_A            1               /* host address */
+#define T_NS           2               /* authoritative server */
+#define T_MD           3               /* mail destination */
+#define T_MF           4               /* mail forwarder */
+#define T_CNAME                5               /* canonical name */
+#define T_SOA          6               /* start of authority zone */
+#define T_MB           7               /* mailbox domain name */
+#define T_MG           8               /* mail group member */
+#define T_MR           9               /* mail rename name */
+#define T_NULL         10              /* null resource record */
+#define T_WKS          11              /* well known service */
+#define T_PTR          12              /* domain name pointer */
+#define T_HINFO                13              /* host information */
+#define T_MINFO                14              /* mailbox information */
+#define T_MX           15              /* mail routing information */
+#define T_TXT          16              /* text strings */
+#define T_RP           17              /* responsible person */
+#define T_AFSDB                18              /* AFS cell database */
+#define T_X25          19              /* X_25 calling address */
+#define T_ISDN         20              /* ISDN calling address */
+#define T_RT           21              /* router */
+#define T_NSAP         22              /* NSAP address */
+#define T_NSAP_PTR     23              /* reverse NSAP lookup (deprecated) */
+#define T_SIG          24              /* security signature */
+#define T_KEY          25              /* security key */
+#define T_PX           26              /* X.400 mail mapping */
+#define T_GPOS         27              /* geographical position (withdrawn) */
+#define T_AAAA         28              /* IP6 Address */
+#define T_LOC          29              /* Location Information */
+#define T_NXT          30              /* Next Valid Name in Zone */
+#define T_EID          31              /* Endpoint identifier */
+#define T_NIMLOC       32              /* Nimrod locator */
+#define T_SRV          33              /* Server selection */
+#define T_ATMA         34              /* ATM Address */
+#define T_NAPTR                35              /* Naming Authority PoinTeR */
+       /* non standard */
+#define T_UINFO                100             /* user (finger) information */
+#define T_UID          101             /* user ID */
+#define T_GID          102             /* group ID */
+#define T_UNSPEC       103             /* Unspecified format (binary data) */
+       /* Query type values which do not appear in resource records */
+#define        T_IXFR          251             /* incremental zone transfer */
+#define T_AXFR         252             /* transfer zone of authority */
+#define T_MAILB                253             /* transfer mailbox records */
+#define T_MAILA                254             /* transfer mail agent records */
+#define T_ANY          255             /* wildcard match */
+
+/*
+ * Values for class field
+ */
+
+#define C_IN           1               /* the arpa internet */
+#define C_CHAOS                3               /* for chaos net (MIT) */
+#define C_HS           4               /* for Hesiod name server (MIT) (XXX) */
+       /* Query class values which do not appear in resource records */
+#define C_ANY          255             /* wildcard match */
+
+/*
+ * Flags field of the KEY RR rdata
+ */
+#define        KEYFLAG_TYPEMASK        0xC000  /* Mask for "type" bits */
+#define        KEYFLAG_TYPE_AUTH_CONF  0x0000  /* Key usable for both */
+#define        KEYFLAG_TYPE_CONF_ONLY  0x8000  /* Key usable for confidentiality */
+#define        KEYFLAG_TYPE_AUTH_ONLY  0x4000  /* Key usable for authentication */
+#define        KEYFLAG_TYPE_NO_KEY     0xC000  /* No key usable for either; no key */
+/* The type bits can also be interpreted independently, as single bits: */
+#define        KEYFLAG_NO_AUTH         0x8000  /* Key not usable for authentication */
+#define        KEYFLAG_NO_CONF         0x4000  /* Key not usable for confidentiality */
+
+#define        KEYFLAG_EXPERIMENTAL    0x2000  /* Security is *mandatory* if bit=0 */
+#define        KEYFLAG_RESERVED3       0x1000  /* reserved - must be zero */
+#define        KEYFLAG_RESERVED4       0x0800  /* reserved - must be zero */
+#define        KEYFLAG_USERACCOUNT     0x0400  /* key is assoc. with a user acct */
+#define        KEYFLAG_ENTITY          0x0200  /* key is assoc. with entity eg host */
+#define        KEYFLAG_ZONEKEY         0x0100  /* key is zone key for the zone named */
+#define        KEYFLAG_IPSEC           0x0080  /* key is for IPSEC use (host or user)*/
+#define        KEYFLAG_EMAIL           0x0040  /* key is for email (MIME security) */
+#define        KEYFLAG_RESERVED10      0x0020  /* reserved - must be zero */
+#define        KEYFLAG_RESERVED11      0x0010  /* reserved - must be zero */
+#define        KEYFLAG_SIGNATORYMASK   0x000F  /* key can sign DNS RR's of same name */
+
+#define  KEYFLAG_RESERVED_BITMASK ( KEYFLAG_RESERVED3 | \
+                                   KEYFLAG_RESERVED4 | \
+                                   KEYFLAG_RESERVED10| KEYFLAG_RESERVED11) 
+
+/* The Algorithm field of the KEY and SIG RR's is an integer, {1..254} */
+#define        ALGORITHM_MD5RSA        1       /* MD5 with RSA */
+#define        ALGORITHM_EXPIRE_ONLY   253     /* No alg, no security */
+#define        ALGORITHM_PRIVATE_OID   254     /* Key begins with OID indicating alg */
+
+/* Signatures */
+                                       /* Size of a mod or exp in bits */
+#define        MIN_MD5RSA_KEY_PART_BITS         512
+#define        MAX_MD5RSA_KEY_PART_BITS        2552
+                                       /* Total of binary mod and exp, bytes */
+#define        MAX_MD5RSA_KEY_BYTES            ((MAX_MD5RSA_KEY_PART_BITS+7/8)*2+3)
+                                       /* Max length of text sig block */
+#define        MAX_KEY_BASE64                  (((MAX_MD5RSA_KEY_BYTES+2)/3)*4)
+
+/*
+ * Status return codes for T_UNSPEC conversion routines
+ */
+#define CONV_SUCCESS   0
+#define CONV_OVERFLOW  (-1)
+#define CONV_BADFMT    (-2)
+#define CONV_BADCKSUM  (-3)
+#define CONV_BADBUFLEN (-4)
+
+#ifndef BYTE_ORDER
+#if (BSD >= 199103)
+# include <machine/endian.h>
+#else
+#ifdef linux
+# include <endian.h>
+#else
+#define LITTLE_ENDIAN  1234    /* least-significant byte first (vax, pc) */
+#define BIG_ENDIAN     4321    /* most-significant byte first (IBM, net) */
+#define PDP_ENDIAN     3412    /* LSB first in word, MSW first in long (pdp)*/
+
+#if defined(vax) || defined(ns32000) || defined(sun386) || defined(i386) || \
+    defined(MIPSEL) || defined(_MIPSEL) || defined(BIT_ZERO_ON_RIGHT) || \
+    defined(__alpha__) || defined(__alpha) || defined(WINNT)
+#define BYTE_ORDER     LITTLE_ENDIAN
+#endif
+
+#if defined(sel) || defined(pyr) || defined(mc68000) || defined(sparc) || \
+    defined(is68k) || defined(tahoe) || defined(ibm032) || defined(ibm370) || \
+    defined(MIPSEB) || defined(_MIPSEB) || defined(_IBMR2) || defined(DGUX) ||\
+    defined(apollo) || defined(__convex__) || defined(_CRAY) || \
+    defined(__hppa) || defined(__hp9000) || \
+    defined(__hp9000s300) || defined(__hp9000s700) || \
+    defined (BIT_ZERO_ON_LEFT) || defined(m68k)
+#define BYTE_ORDER     BIG_ENDIAN
+#endif
+#endif /* linux */
+#endif /* BSD */
+#endif /* BYTE_ORDER */
+
+#if !defined(BYTE_ORDER) || \
+    (BYTE_ORDER != BIG_ENDIAN && BYTE_ORDER != LITTLE_ENDIAN && \
+    BYTE_ORDER != PDP_ENDIAN)
+       /* you must determine what the correct bit order is for
+        * your compiler - the next line is an intentional error
+        * which will force your compiles to bomb until you fix
+        * the above macros.
+        */
+  error "Undefined or invalid BYTE_ORDER";
+#endif
+
+/*
+ * Structure for query header.  The order of the fields is machine- and
+ * compiler-dependent, depending on the byte/bit order and the layout
+ * of bit fields.  We use bit fields only in int variables, as this
+ * is all ANSI requires.  This requires a somewhat confusing rearrangement.
+ */
+
+typedef struct {
+       unsigned        id :16;         /* query identification number */
+#if BYTE_ORDER == BIG_ENDIAN
+                       /* fields in third byte */
+       unsigned        qr: 1;          /* response flag */
+       unsigned        opcode: 4;      /* purpose of message */
+       unsigned        aa: 1;          /* authoritive answer */
+       unsigned        tc: 1;          /* truncated message */
+       unsigned        rd: 1;          /* recursion desired */
+                       /* fields in fourth byte */
+       unsigned        ra: 1;          /* recursion available */
+       unsigned        unused :1;      /* unused bits (MBZ as of 4.9.3a3) */
+       unsigned        ad: 1;          /* authentic data from named */
+       unsigned        cd: 1;          /* checking disabled by resolver */
+       unsigned        rcode :4;       /* response code */
+#endif
+#if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN
+                       /* fields in third byte */
+       unsigned        rd :1;          /* recursion desired */
+       unsigned        tc :1;          /* truncated message */
+       unsigned        aa :1;          /* authoritive answer */
+       unsigned        opcode :4;      /* purpose of message */
+       unsigned        qr :1;          /* response flag */
+                       /* fields in fourth byte */
+       unsigned        rcode :4;       /* response code */
+       unsigned        cd: 1;          /* checking disabled by resolver */
+       unsigned        ad: 1;          /* authentic data from named */
+       unsigned        unused :1;      /* unused bits (MBZ as of 4.9.3a3) */
+       unsigned        ra :1;          /* recursion available */
+#endif
+                       /* remaining bytes */
+       unsigned        qdcount :16;    /* number of question entries */
+       unsigned        ancount :16;    /* number of answer entries */
+       unsigned        nscount :16;    /* number of authority entries */
+       unsigned        arcount :16;    /* number of resource entries */
+} HEADER;
+
+/*
+ * Defines for handling compressed domain names
+ */
+#define INDIR_MASK     0xc0
+
+extern u_int16_t       _getshort __P((const u_char *));
+extern u_int32_t       _getlong __P((const u_char *));
+
+/*
+ * Inline versions of get/put short/long.  Pointer is advanced.
+ *
+ * These macros demonstrate the property of C whereby it can be
+ * portable or it can be elegant but rarely both.
+ */
+#define GETSHORT(s, cp) { \
+       register u_char *t_cp = (u_char *)(cp); \
+       (s) = ((u_int16_t)t_cp[0] << 8) \
+           | ((u_int16_t)t_cp[1]) \
+           ; \
+       (cp) += INT16SZ; \
+}
+
+#define GETLONG(l, cp) { \
+       register u_char *t_cp = (u_char *)(cp); \
+       (l) = ((u_int32_t)t_cp[0] << 24) \
+           | ((u_int32_t)t_cp[1] << 16) \
+           | ((u_int32_t)t_cp[2] << 8) \
+           | ((u_int32_t)t_cp[3]) \
+           ; \
+       (cp) += INT32SZ; \
+}
+
+#define PUTSHORT(s, cp) { \
+       register u_int16_t t_s = (u_int16_t)(s); \
+       register u_char *t_cp = (u_char *)(cp); \
+       *t_cp++ = (char) (t_s >> 8); \
+       *t_cp   = (char) t_s; \
+       (cp) += INT16SZ; \
+}
+
+#define PUTLONG(l, cp) { \
+       register u_int32_t t_l = (u_int32_t)(l); \
+       register u_char *t_cp = (u_char *)(cp); \
+       *t_cp++ = t_l >> 24; \
+       *t_cp++ = t_l >> 16; \
+       *t_cp++ = t_l >> 8; \
+       *t_cp   = t_l; \
+       (cp) += INT32SZ; \
+}
+
+#endif /* !_NAMESER_H_ */
diff --git a/bindlib_w32/base64.c b/bindlib_w32/base64.c
new file mode 100644 (file)
index 0000000..917a757
--- /dev/null
@@ -0,0 +1,323 @@
+/*
+ * Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+/*
+ * Portions Copyright (c) 1995 by International Business Machines, Inc.
+ *
+ * International Business Machines, Inc. (hereinafter called IBM) grants
+ * permission under its copyrights to use, copy, modify, and distribute this
+ * Software with or without fee, provided that the above copyright notice and
+ * all paragraphs of this notice appear in all copies, and that the name of IBM
+ * not be used in connection with the marketing of any product incorporating
+ * the Software or modifications thereof, without specific, written prior
+ * permission.
+ *
+ * To the extent it has a right to do so, IBM grants an immunity from suit
+ * under its patents, if any, for the use, sale or manufacture of products to
+ * the extent that such products are used for performing Domain Name System
+ * dynamic updates in TCP/IP networks by means of the Software.  No immunity is
+ * granted for any product per se or for any other function of any product.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE.  IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
+ * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
+ * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ */
+
+#include <sys/types.h>
+#ifndef WINNT
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#endif
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+
+#include <ctype.h>
+#include <resolv.h>
+#include <stdio.h>
+
+#if defined(BSD) && (BSD >= 199103) && defined(AF_INET6)
+# include <stdlib.h>
+# include <string.h>
+#else
+# include "conf/portability.h"
+#endif
+
+#define Assert(Cond) if (!(Cond)) abort()
+
+static const char Base64[] =
+       "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+static const char Pad64 = '=';
+
+/* (From RFC1521 and draft-ietf-dnssec-secext-03.txt)
+   The following encoding technique is taken from RFC 1521 by Borenstein
+   and Freed.  It is reproduced here in a slightly edited form for
+   convenience.
+
+   A 65-character subset of US-ASCII is used, enabling 6 bits to be
+   represented per printable character. (The extra 65th character, "=",
+   is used to signify a special processing function.)
+
+   The encoding process represents 24-bit groups of input bits as output
+   strings of 4 encoded characters. Proceeding from left to right, a
+   24-bit input group is formed by concatenating 3 8-bit input groups.
+   These 24 bits are then treated as 4 concatenated 6-bit groups, each
+   of which is translated into a single digit in the base64 alphabet.
+
+   Each 6-bit group is used as an index into an array of 64 printable
+   characters. The character referenced by the index is placed in the
+   output string.
+
+                         Table 1: The Base64 Alphabet
+
+      Value Encoding  Value Encoding  Value Encoding  Value Encoding
+          0 A            17 R            34 i            51 z
+          1 B            18 S            35 j            52 0
+          2 C            19 T            36 k            53 1
+          3 D            20 U            37 l            54 2
+          4 E            21 V            38 m            55 3
+          5 F            22 W            39 n            56 4
+          6 G            23 X            40 o            57 5
+          7 H            24 Y            41 p            58 6
+          8 I            25 Z            42 q            59 7
+          9 J            26 a            43 r            60 8
+         10 K            27 b            44 s            61 9
+         11 L            28 c            45 t            62 +
+         12 M            29 d            46 u            63 /
+         13 N            30 e            47 v
+         14 O            31 f            48 w         (pad) =
+         15 P            32 g            49 x
+         16 Q            33 h            50 y
+
+   Special processing is performed if fewer than 24 bits are available
+   at the end of the data being encoded.  A full encoding quantum is
+   always completed at the end of a quantity.  When fewer than 24 input
+   bits are available in an input group, zero bits are added (on the
+   right) to form an integral number of 6-bit groups.  Padding at the
+   end of the data is performed using the '=' character.
+
+   Since all base64 input is an integral number of octets, only the
+         -------------------------------------------------                       
+   following cases can arise:
+   
+       (1) the final quantum of encoding input is an integral
+           multiple of 24 bits; here, the final unit of encoded
+          output will be an integral multiple of 4 characters
+          with no "=" padding,
+       (2) the final quantum of encoding input is exactly 8 bits;
+           here, the final unit of encoded output will be two
+          characters followed by two "=" padding characters, or
+       (3) the final quantum of encoding input is exactly 16 bits;
+           here, the final unit of encoded output will be three
+          characters followed by one "=" padding character.
+   */
+
+int
+b64_ntop(src, srclength, target, targsize)
+       u_char const *src;
+       size_t srclength;
+       char *target;
+       size_t targsize;
+{
+       size_t datalength = 0;
+       u_char input[3];
+       u_char output[4];
+       size_t i;
+
+       while (2 < srclength) {
+               input[0] = *src++;
+               input[1] = *src++;
+               input[2] = *src++;
+               srclength -= 3;
+
+               output[0] = input[0] >> 2;
+               output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
+               output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
+               output[3] = input[2] & 0x3f;
+               Assert(output[0] < 64);
+               Assert(output[1] < 64);
+               Assert(output[2] < 64);
+               Assert(output[3] < 64);
+
+               if (datalength + 4 > targsize)
+                       return (-1);
+               target[datalength++] = Base64[output[0]];
+               target[datalength++] = Base64[output[1]];
+               target[datalength++] = Base64[output[2]];
+               target[datalength++] = Base64[output[3]];
+       }
+    
+       /* Now we worry about padding. */
+       if (0 != srclength) {
+               /* Get what's left. */
+               input[0] = input[1] = input[2] = '\0';
+               for (i = 0; i < srclength; i++)
+                       input[i] = *src++;
+       
+               output[0] = input[0] >> 2;
+               output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
+               output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
+               Assert(output[0] < 64);
+               Assert(output[1] < 64);
+               Assert(output[2] < 64);
+
+               if (datalength + 4 > targsize)
+                       return (-1);
+               target[datalength++] = Base64[output[0]];
+               target[datalength++] = Base64[output[1]];
+               if (srclength == 1)
+                       target[datalength++] = Pad64;
+               else
+                       target[datalength++] = Base64[output[2]];
+               target[datalength++] = Pad64;
+       }
+       if (datalength >= targsize)
+               return (-1);
+       target[datalength] = '\0';      /* Returned value doesn't count \0. */
+       return (datalength);
+}
+
+/* skips all whitespace anywhere.
+   converts characters, four at a time, starting at (or after)
+   src from base - 64 numbers into three 8 bit bytes in the target area.
+   it returns the number of data bytes stored at the target, or -1 on error.
+ */
+
+int
+b64_pton(src, target, targsize)
+       char const *src;
+       u_char *target;
+       size_t targsize;
+{
+       int tarindex, state, ch;
+       char *pos;
+
+       state = 0;
+       tarindex = 0;
+
+       while ((ch = *src++) != '\0') {
+               if (isspace(ch))        /* Skip whitespace anywhere. */
+                       continue;
+
+               if (ch == Pad64)
+                       break;
+
+               pos = strchr(Base64, ch);
+               if (pos == 0)           /* A non-base64 character. */
+                       return (-1);
+
+               switch (state) {
+               case 0:
+                       if (target) {
+                               if ((size_t)tarindex >= targsize)
+                                       return (-1);
+                               target[tarindex] = (pos - Base64) << 2;
+                       }
+                       state = 1;
+                       break;
+               case 1:
+                       if (target) {
+                               if ((size_t)(tarindex + 1) >= targsize)
+                                       return (-1);
+                               target[tarindex]   |=  (pos - Base64) >> 4;
+                               target[tarindex+1]  = ((pos - Base64) & 0x0f)
+                                                       << 4 ;
+                       }
+                       tarindex++;
+                       state = 2;
+                       break;
+               case 2:
+                       if (target) {
+                               if ((size_t)(tarindex + 1) >= targsize)
+                                       return (-1);
+                               target[tarindex]   |=  (pos - Base64) >> 2;
+                               target[tarindex+1]  = ((pos - Base64) & 0x03)
+                                                       << 6;
+                       }
+                       tarindex++;
+                       state = 3;
+                       break;
+               case 3:
+                       if (target) {
+                               if ((size_t)tarindex >= targsize)
+                                       return (-1);
+                               target[tarindex] |= (pos - Base64);
+                       }
+                       tarindex++;
+                       state = 0;
+                       break;
+               default:
+                       abort();
+               }
+       }
+
+       /*
+        * We are done decoding Base-64 chars.  Let's see if we ended
+        * on a byte boundary, and/or with erroneous trailing characters.
+        */
+
+       if (ch == Pad64) {              /* We got a pad char. */
+               ch = *src++;            /* Skip it, get next. */
+               switch (state) {
+               case 0:         /* Invalid = in first position */
+               case 1:         /* Invalid = in second position */
+                       return (-1);
+
+               case 2:         /* Valid, means one byte of info */
+                       /* Skip any number of spaces. */
+                       for (NULL; ch != '\0'; ch = *src++)
+                               if (!isspace(ch))
+                                       break;
+                       /* Make sure there is another trailing = sign. */
+                       if (ch != Pad64)
+                               return (-1);
+                       ch = *src++;            /* Skip the = */
+                       /* Fall through to "single trailing =" case. */
+                       /* FALLTHROUGH */
+
+               case 3:         /* Valid, means two bytes of info */
+                       /*
+                        * We know this char is an =.  Is there anything but
+                        * whitespace after it?
+                        */
+                       for (NULL; ch != '\0'; ch = *src++)
+                               if (!isspace(ch))
+                                       return (-1);
+
+                       /*
+                        * Now make sure for cases 2 and 3 that the "extra"
+                        * bits that slopped past the last full byte were
+                        * zeros.  If we don't check them, they become a
+                        * subliminal channel.
+                        */
+                       if (target && target[tarindex] != 0)
+                               return (-1);
+               }
+       } else {
+               /*
+                * We ended by seeing the end of the string.  Make sure we
+                * have no partial bytes lying around.
+                */
+               if (state != 0)
+                       return (-1);
+       }
+
+       return (tarindex);
+}
diff --git a/bindlib_w32/bindlib.dsp b/bindlib_w32/bindlib.dsp
new file mode 100644 (file)
index 0000000..f683d33
--- /dev/null
@@ -0,0 +1,200 @@
+# Microsoft Developer Studio Project File - Name="bindlib" - Package Owner=<4>\r
+# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
+# ** DO NOT EDIT **\r
+\r
+# TARGTYPE "Win32 (x86) Static Library" 0x0104\r
+\r
+CFG=bindlib - Win32 Debug\r
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
+!MESSAGE use the Export Makefile command and run\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "bindlib.mak".\r
+!MESSAGE \r
+!MESSAGE You can specify a configuration when running NMAKE\r
+!MESSAGE by defining the macro CFG on the command line. For example:\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "bindlib.mak" CFG="bindlib - Win32 Debug"\r
+!MESSAGE \r
+!MESSAGE Possible choices for configuration are:\r
+!MESSAGE \r
+!MESSAGE "bindlib - Win32 Release" (based on "Win32 (x86) Static Library")\r
+!MESSAGE "bindlib - Win32 Debug" (based on "Win32 (x86) Static Library")\r
+!MESSAGE \r
+\r
+# Begin Project\r
+# PROP AllowPerConfigDependencies 0\r
+# PROP Scc_ProjName ""\r
+# PROP Scc_LocalPath ""\r
+CPP=cl.exe\r
+RSC=rc.exe\r
+\r
+!IF  "$(CFG)" == "bindlib - Win32 Release"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 0\r
+# PROP BASE Output_Dir "Release"\r
+# PROP BASE Intermediate_Dir "Release"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 0\r
+# PROP Output_Dir "Release"\r
+# PROP Intermediate_Dir "Release"\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c\r
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "." /D "NDEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /D "WINNT" /YX /FD /c\r
+# ADD BASE RSC /l 0x40d /d "NDEBUG"\r
+# ADD RSC /l 0x40d /d "NDEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LIB32=link.exe -lib\r
+# ADD BASE LIB32 /nologo\r
+# ADD LIB32 /nologo /out:"Release\resolv.lib"\r
+\r
+!ELSEIF  "$(CFG)" == "bindlib - Win32 Debug"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 1\r
+# PROP BASE Output_Dir "Debug"\r
+# PROP BASE Intermediate_Dir "Debug"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 1\r
+# PROP Output_Dir "Debug"\r
+# PROP Intermediate_Dir "Debug"\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c\r
+# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "." /D "_DEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /D "WINNT" /FR /YX /FD /GZ /c\r
+# ADD BASE RSC /l 0x40d /d "_DEBUG"\r
+# ADD RSC /l 0x40d /d "_DEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LIB32=link.exe -lib\r
+# ADD BASE LIB32 /nologo\r
+# ADD LIB32 /nologo /out:"Debug\resolv.lib"\r
+\r
+!ENDIF \r
+\r
+# Begin Target\r
+\r
+# Name "bindlib - Win32 Release"\r
+# Name "bindlib - Win32 Debug"\r
+# Begin Group "Source Files"\r
+\r
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
+# Begin Source File\r
+\r
+SOURCE=.\base64.c\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\gethnamaddr.c\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\getnetbyaddr.c\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\getnetbyname.c\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\getnetent.c\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\getnetnamadr.c\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\herror.c\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\hostnamelen.c\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\inet_addr.c\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\inet_net_ntop.c\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\inet_net_pton.c\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\inet_neta.c\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\inet_ntop.c\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\inet_pton.c\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\nsap_addr.c\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\res_comp.c\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\res_data.c\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\res_debug.c\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\res_init.c\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\res_mkquery.c\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\res_nt_misc.c\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\res_query.c\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\res_send.c\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\sethostent.c\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\writev.c\r
+# End Source File\r
+# End Group\r
+# Begin Group "Header Files"\r
+\r
+# PROP Default_Filter "h;hpp;hxx;hm;inl"\r
+# Begin Source File\r
+\r
+SOURCE=.\resolv\netdb.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\resolv\resolv.h\r
+# End Source File\r
+# End Group\r
+# End Target\r
+# End Project\r
diff --git a/bindlib_w32/bindlib.dsw b/bindlib_w32/bindlib.dsw
new file mode 100644 (file)
index 0000000..f3cddd6
--- /dev/null
@@ -0,0 +1,29 @@
+Microsoft Developer Studio Workspace File, Format Version 6.00\r
+# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r
+\r
+###############################################################################\r
+\r
+Project: "bindlib"=.\bindlib.dsp - Package Owner=<4>\r
+\r
+Package=<5>\r
+{{{\r
+}}}\r
+\r
+Package=<4>\r
+{{{\r
+}}}\r
+\r
+###############################################################################\r
+\r
+Global:\r
+\r
+Package=<5>\r
+{{{\r
+}}}\r
+\r
+Package=<3>\r
+{{{\r
+}}}\r
+\r
+###############################################################################\r
+\r
diff --git a/bindlib_w32/conf/bsdinstall.sh b/bindlib_w32/conf/bsdinstall.sh
new file mode 100644 (file)
index 0000000..edfa862
--- /dev/null
@@ -0,0 +1,251 @@
+#! /bin/sh
+
+## (From INN-1.4, written by Rich Salz)
+##  $Revision: 1.1 $
+##  A script to install files and directories.
+
+PROGNAME=`basename $0`
+
+##  Paths to programs.  CHOWN and WHOAMI are checked below.
+CHOWN=chown
+CHGRP=chgrp
+CHMOD=chmod
+CP=cp
+LN=ln
+MKDIR=mkdir
+MV=mv
+RM=rm
+STRIP=strip
+WHOAMI=whoami
+
+##  Some systems don't support -x, so we have to use -f.
+if [ ${CHOWN} = chown ] ; then
+    if [ -f /etc/chown ] ; then
+       CHOWN=/etc/chown
+    else
+       if [ -f /usr/etc/chown ] ; then
+           CHOWN=/usr/etc/chown
+       fi
+    fi
+fi
+
+if [ ${WHOAMI} = whoami ] ; then
+    if [ -f /usr/ucb/whoami ] ; then
+       WHOAMI=/usr/ucb/whoami
+    fi
+fi
+
+##  Defaults.
+CHOWNIT=false
+CHGROUPIT=false
+CHMODIT=false
+STRIPIT=false
+BACKIT=false
+TOUCHIT=true
+SAVESRC=false
+ROOT=unknown
+
+##  Process JCL.
+MORETODO=true
+while ${MORETODO} ; do
+    case X"$1" in
+    X-b)
+       BACKIT=true
+       BACKUP="$2"
+       shift
+       ;;
+    X-b*)
+       BACKIT=true
+       BACKUP=`expr "$1" : '-b\(.*\)'`
+       ;;
+    X-c)
+       SAVESRC=true
+       ;;
+    X-g)
+       GROUP="$2"
+       CHGROUPIT=true
+       shift
+       ;;
+    X-g*)
+       GROUP=`expr "$1" : '-g\(.*\)'`
+       CHGROUPIT=true
+       ;;
+    X-G)
+       case ${ROOT} in
+       unknown)
+           case `${WHOAMI}` in
+           root)
+               ROOT=true
+               ;;
+           *)
+               ROOT=false
+               ;;
+           esac
+           ;;
+       esac
+       GROUP="$2"
+       shift
+       ${ROOT} && CHGROUPIT=true
+       ;;
+    X-G*)
+       case ${ROOT} in
+       unknown)
+           case `${WHOAMI}` in
+           root)
+               ROOT=true
+               ;;
+           *)
+               ROOT=false
+               ;;
+           esac
+           ;;
+       esac
+       if ${ROOT} ; then
+           GROUP=`expr "$1" : '-g\(.*\)'`
+           CHGROUPIT=true
+       fi
+       ;;
+    X-m)
+       MODE="$2"
+       CHMODIT=true
+       shift
+       ;;
+    X-m*)
+       MODE=`expr "$1" : '-m\(.*\)'`
+       CHMODIT=true
+       ;;
+    X-n)
+       TOUCHIT=false
+       ;;
+    X-o)
+       OWNER="$2"
+       CHOWNIT=true
+       shift
+       ;;
+    X-o*)
+       OWNER=`expr "$1" : '-o\(.*\)'`
+       CHOWNIT=true
+       ;;
+    X-O)
+       case ${ROOT} in
+       unknown)
+           case `${WHOAMI}` in
+           root)
+               ROOT=true
+               ;;
+           *)
+               ROOT=false
+               ;;
+           esac
+           ;;
+       esac
+       OWNER="$2"
+       shift
+       ${ROOT} && CHOWNIT=true
+       ;;
+    X-O*)
+       case ${ROOT} in
+       unknown)
+           case `${WHOAMI}` in
+           root)
+               ROOT=true
+               ;;
+           *)
+               ROOT=false
+               ;;
+           esac
+           ;;
+       esac
+       if ${ROOT} ; then
+           OWNER=`expr "$1" : '-o\(.*\)'`
+           CHOWNIT=true
+       fi
+       ;;
+    X-s)
+       STRIPIT=true
+       ;;
+    X--)
+       shift
+       MORETODO=false
+       ;;
+    X-*)
+       echo "${PROGNAME}:  Unknown flag $1" 1>&2
+       exit 1
+       ;;
+    *)
+       MORETODO=false
+       ;;
+    esac
+    ${MORETODO} && shift
+done
+
+##  Process arguments.
+if [ $# -ne 2 ] ; then
+    echo "Usage:  ${PROGNAME} [flags] source destination"
+    exit 1
+fi
+
+##  Making a directory?
+if [ X"$1" = X. ] ; then
+    DEST="$2"
+    if [ ! -d "${DEST}" ] ; then
+       ${MKDIR} "${DEST}" || exit 1
+    fi
+    if ${CHOWNIT} ; then
+       ${CHOWN} "${OWNER}" "${DEST}" || exit 1
+    fi
+    if ${CHGROUPIT} ; then
+       ${CHGRP} "${GROUP}" "${DEST}" || exit 1
+    fi
+    if ${CHMODIT} ; then
+       umask 0
+       ${CHMOD} "${MODE}"  "${DEST}" || exit 1
+    fi
+    exit 0
+fi
+
+##  Get the destination and a temp file in the destination diretory.
+if [ -d "$2" ] ; then
+    DEST="$2/$1"
+    TEMP="$2/$$.tmp"
+else
+    DEST="$2"
+    TEMP="`expr "$2" : '\(.*\)/.*'`/$$.tmp"
+fi
+
+##  If not given the same name, we must try to copy.
+if [ X"$1" != X"$2" -o $SAVESRC ] ; then
+    if cmp -s "$1" "${DEST}" ; then
+       ##  Files are same; touch or not.
+       ${TOUCHIT} && touch "${DEST}"
+    else
+       ##  If destination exists and we wish to backup, link to backup.
+       if [ -f "${DEST}" ] ; then
+           if ${BACKIT} ; then
+               ${RM} -f "${DEST}${BACKUP}"
+               ${LN} "${DEST}" "${DEST}${BACKUP}"
+           fi
+       fi
+       ##  Copy source to the right dir, then move to right spot.
+       ##  Done in two parts so we can hope for atomicity.
+       ${RM} -f "${TEMP}" || exit 1
+       ${CP} "$1" "${TEMP}" || exit 1
+       ${MV} -f "${TEMP}" "${DEST}" || exit 1
+    fi
+fi
+
+##  Strip and set the modes.
+if ${STRIPIT} ; then
+    ${STRIP} "${DEST}" || exit 1
+fi
+if ${CHOWNIT} ; then
+    ${CHOWN} "${OWNER}" "${DEST}" || exit 1
+fi
+if ${CHGROUPIT} ; then
+    ${CHGRP} "${GROUP}" "${DEST}" || exit 1
+fi
+if ${CHMODIT} ; then
+    umask 0
+    ${CHMOD} "${MODE}"  "${DEST}" || exit 1
+fi
+exit 0
diff --git a/bindlib_w32/conf/copyright b/bindlib_w32/conf/copyright
new file mode 100644 (file)
index 0000000..a441ff8
--- /dev/null
@@ -0,0 +1,50 @@
+-
+Copyright (c) XYZZY
+   The Regents of the University of California.  All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+3. All advertising materials mentioning features or use of this software
+   must display the following acknowledgement:
+       This product includes software developed by the University of
+       California, Berkeley and its contributors.
+4. Neither the name of the University nor the names of its contributors
+   may be used to endorse or promote products derived from this software
+   without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+-
+Portions Copyright (c) 1993 by Digital Equipment Corporation.
+
+Permission to use, copy, modify, and distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies, and that
+the name of Digital Equipment Corporation not be used in advertising or
+publicity pertaining to distribution of the document or software without
+specific, written prior permission.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
+CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+-
diff --git a/bindlib_w32/conf/master/README b/bindlib_w32/conf/master/README
new file mode 100644 (file)
index 0000000..4e49af6
--- /dev/null
@@ -0,0 +1,45 @@
+
+How to add new hosts to the name server data base:
+
+1) Edit 'named.hosts' file:
+
+       For each machine you need to enter the following information:
+       machine name, all its network addresses, host information, and common
+       aliases for it.
+
+       This is the entry for calder.
+
+CALDER         IN      A       128.32.130.1
+               IN      A       128.32.129.3
+               IN      HINFO   VAX-11/750 UNIX
+UCBCALDER      IN      CNAME   CALDER
+
+ For the machine you are adding:
+       1) replace 'CALDER' with the new machine name
+       2) replace '128.32.130.1' with the new machines address
+               if there is more then one address for the machine
+               then add lines like the one with '128.32.129.3'
+       3) replace 'VAX-11/750' with the machine type
+       4) If it doesn't run 'UNIX' then replace UNIX with its
+          operating system.
+
+2) Edit 'named.rev' file:
+
+       For each address of a machine you need to enter the reverse
+       address notation for the machine:
+
+       For calder the lines look as follows:
+
+12.0   IN      PTR     CALDER.BERKELEY.EDU.
+3.129  IN      PTR     CALDER.BERKELEY.EDU.
+
+       Calder has two address '128.32.0.12' and '128.32.129.3'
+
+       You take the two numbers after 128.32 and reverse them.
+       Then replace CALDER with the new machine name.
+
+    *** Note the trailing "." on "EDU." it needs to be there.  Otherwise
+       BIND will add the current $ORIGIN to this name, which won't work.
+       ***
+
+3) Increment the serial number on both files.  
diff --git a/bindlib_w32/conf/master/named.boo b/bindlib_w32/conf/master/named.boo
new file mode 100644 (file)
index 0000000..7d467f2
--- /dev/null
@@ -0,0 +1,18 @@
+;
+;  @(#)named.boot.slave        1.13    (Berkeley)  87/07/21
+;
+;  boot file for secondary name server
+; Note that there should be one primary entry for each SOA record.
+;
+;
+sortlist 10.0.0.0 
+
+directory      /usr/local/adm/named
+
+; type    domain               source host/file                backup file
+
+cache     .                    root.cache
+secondary Berkeley.EDU         128.32.137.8 128.32.137.3       ucbhosts.bak
+secondary 32.128.IN-ADDR.ARPA  128.32.137.8 128.32.137.3       ucbhosts.rev.bak
+primary   0.0.127.IN-ADDR.ARPA localhost.rev
+
diff --git a/bindlib_w32/conf/master/named.boot b/bindlib_w32/conf/master/named.boot
new file mode 100644 (file)
index 0000000..7d467f2
--- /dev/null
@@ -0,0 +1,18 @@
+;
+;  @(#)named.boot.slave        1.13    (Berkeley)  87/07/21
+;
+;  boot file for secondary name server
+; Note that there should be one primary entry for each SOA record.
+;
+;
+sortlist 10.0.0.0 
+
+directory      /usr/local/adm/named
+
+; type    domain               source host/file                backup file
+
+cache     .                    root.cache
+secondary Berkeley.EDU         128.32.137.8 128.32.137.3       ucbhosts.bak
+secondary 32.128.IN-ADDR.ARPA  128.32.137.8 128.32.137.3       ucbhosts.rev.bak
+primary   0.0.127.IN-ADDR.ARPA localhost.rev
+
diff --git a/bindlib_w32/conf/master/named.boot.master b/bindlib_w32/conf/master/named.boot.master
new file mode 100644 (file)
index 0000000..702ffcf
--- /dev/null
@@ -0,0 +1,16 @@
+;
+;  boot file for authoritive master name server for Berkeley.EDU
+; Note that there should be one primary entry for each SOA record.
+;
+;
+sortlist 10.0.0.0 
+
+directory      /usr/local/adm/named
+
+; type    domain               source host/file                backup file
+
+cache     .                    root.cache
+primary   Berkeley.EDU         berkeley.zone
+primary   32.128.IN-ADDR.ARPA  berkeley.rev
+primary   0.0.127.IN-ADDR.ARPA localhost.rev
+
diff --git a/bindlib_w32/conf/master/named.hos b/bindlib_w32/conf/master/named.hos
new file mode 100644 (file)
index 0000000..d31b3bd
--- /dev/null
@@ -0,0 +1,22 @@
+; Authoritative data for Berkeley.EDU (ORIGIN assumed Berkeley.EDU)
+;
+@              IN      SOA     ucbvax.berkeley.edu kjd.ucbvax.berkeley.edu (
+                               1986020501      ; Serial
+                               10800   ; Refresh 3 hours
+                               3600    ; Retry   1 hour
+                               3600000 ; Expire  1000 hours
+                               86400 ) ; Minimum 24 hours
+               IN      MX          10 ucb-vax
+               IN      NS          monet
+localhost      IN      A           127.1
+ucb-arpa        IN     A           10.0.0.78
+               IN      A           128.32.0.4
+               IN      HINFO       VAX-11/780 UNIX
+arpa           IN      CNAME       ucbarpa
+ucb-vax   9999  IN     A           10.2.0.78
+               IN      A           128.32.0.10
+               IN      HINFO       VAX-11/750 UNIX
+ucbvax          IN     CNAME       ucb-vax
+monet          IN      A           128.32.0.7
+               IN      HINFO       VAX-11/750 UNIX
+ucbmonet       IN      CNAME       monet
diff --git a/bindlib_w32/conf/master/named.hosts b/bindlib_w32/conf/master/named.hosts
new file mode 100644 (file)
index 0000000..d31b3bd
--- /dev/null
@@ -0,0 +1,22 @@
+; Authoritative data for Berkeley.EDU (ORIGIN assumed Berkeley.EDU)
+;
+@              IN      SOA     ucbvax.berkeley.edu kjd.ucbvax.berkeley.edu (
+                               1986020501      ; Serial
+                               10800   ; Refresh 3 hours
+                               3600    ; Retry   1 hour
+                               3600000 ; Expire  1000 hours
+                               86400 ) ; Minimum 24 hours
+               IN      MX          10 ucb-vax
+               IN      NS          monet
+localhost      IN      A           127.1
+ucb-arpa        IN     A           10.0.0.78
+               IN      A           128.32.0.4
+               IN      HINFO       VAX-11/780 UNIX
+arpa           IN      CNAME       ucbarpa
+ucb-vax   9999  IN     A           10.2.0.78
+               IN      A           128.32.0.10
+               IN      HINFO       VAX-11/750 UNIX
+ucbvax          IN     CNAME       ucb-vax
+monet          IN      A           128.32.0.7
+               IN      HINFO       VAX-11/750 UNIX
+ucbmonet       IN      CNAME       monet
diff --git a/bindlib_w32/conf/master/named.loc b/bindlib_w32/conf/master/named.loc
new file mode 100644 (file)
index 0000000..e0270ea
--- /dev/null
@@ -0,0 +1,13 @@
+;
+;      @(#)named.local 1.1     (Berkeley)      86/01/21
+;
+
+@      IN      SOA     ucbvax.Berkeley.EDU. kjd.ucbvax.Berkeley.EDU.  (
+                               1986012101 ; Serial
+                                3600    ; Refresh
+                                300     ; Retry
+                                3600000 ; Expire
+                                14400 )  ; Minimum
+       IN      NS      ucbvax.Berkeley.EDU.
+0      IN      PTR     loopback.ucbvax.Berkeley.EDU.
+1      IN      PTR     localhost.
diff --git a/bindlib_w32/conf/master/named.local b/bindlib_w32/conf/master/named.local
new file mode 100644 (file)
index 0000000..e0270ea
--- /dev/null
@@ -0,0 +1,13 @@
+;
+;      @(#)named.local 1.1     (Berkeley)      86/01/21
+;
+
+@      IN      SOA     ucbvax.Berkeley.EDU. kjd.ucbvax.Berkeley.EDU.  (
+                               1986012101 ; Serial
+                                3600    ; Refresh
+                                300     ; Retry
+                                3600000 ; Expire
+                                14400 )  ; Minimum
+       IN      NS      ucbvax.Berkeley.EDU.
+0      IN      PTR     loopback.ucbvax.Berkeley.EDU.
+1      IN      PTR     localhost.
diff --git a/bindlib_w32/conf/master/named.rev b/bindlib_w32/conf/master/named.rev
new file mode 100644 (file)
index 0000000..6d1fb58
--- /dev/null
@@ -0,0 +1,30 @@
+;
+;      @(#)named.rev   1.1     (Berkeley)      86/02/05
+;
+
+@      IN      SOA     ucbvax.berkeley.edu kjd.ucbvax.berkeley.edu (
+                               1986020501 ; Serial
+                               10800   ; Refresh 3 hours
+                               3600    ; Retry   1 hour
+                               3600000 ; Expire  1000 hours
+                               86400 ) ; Minimum 24 hours
+       IN      NS      ucbvax.Berkeley.EDU.
+; RFC 1101 stuff
+0.0    IN      PTR     Berkeley-net.Berkeley.EDU.
+       IN      A       255.255.255.0
+; real hosts
+0.130  IN      PTR     csdiv-net.Berkeley.EDU.
+2.129  IN      PTR     monet.Berkeley.EDU.
+2.140  IN      PTR     ucbarpa.Berkeley.EDU.
+3.132  IN      PTR     cad.Berkeley.EDU.
+4.0    IN      PTR     ucbarpa.Berkeley.EDU.
+5.0    IN      PTR     cad.Berkeley.EDU.
+6.0    IN      PTR     ernie.Berkeley.EDU.
+6.130  IN      PTR     monet-cs.Berkeley.EDU.
+7.0    IN      PTR     monet.Berkeley.EDU.
+7.130  IN      PTR     kim.Berkeley.EDU.
+9.0    IN      PTR     esvax.Berkeley.EDU.
+10.0   IN      PTR     ucbvax.Berkeley.EDU.
+11.0   IN      PTR     kim.Berkeley.EDU.
+11.156 IN      PTR     esvax-156.Berkeley.EDU.
+38.131 IN      PTR     monet.Berkeley.EDU.
diff --git a/bindlib_w32/conf/master/namedboot.master b/bindlib_w32/conf/master/namedboot.master
new file mode 100644 (file)
index 0000000..702ffcf
--- /dev/null
@@ -0,0 +1,16 @@
+;
+;  boot file for authoritive master name server for Berkeley.EDU
+; Note that there should be one primary entry for each SOA record.
+;
+;
+sortlist 10.0.0.0 
+
+directory      /usr/local/adm/named
+
+; type    domain               source host/file                backup file
+
+cache     .                    root.cache
+primary   Berkeley.EDU         berkeley.zone
+primary   32.128.IN-ADDR.ARPA  berkeley.rev
+primary   0.0.127.IN-ADDR.ARPA localhost.rev
+
diff --git a/bindlib_w32/conf/master/root.cac b/bindlib_w32/conf/master/root.cac
new file mode 100644 (file)
index 0000000..48abd78
--- /dev/null
@@ -0,0 +1,63 @@
+;       This file holds the information on root name servers needed to
+;       initialize cache of Internet domain name servers
+;       (e.g. reference this file in the "cache  .  <file>"
+;       configuration file of BIND domain name servers).
+;
+;       This file is made available by InterNIC registration services
+;       under anonymous FTP as
+;           file                /domain/named.root
+;           on server           FTP.RS.INTERNIC.NET
+;       -OR- under Gopher at    RS.INTERNIC.NET
+;           under menu          InterNIC Registration Services (NSI)
+;              submenu          InterNIC Registration Archives
+;           file                named.root
+;
+;       last update:    Nov 8, 1995
+;       related version of root zone:   1995110800
+;
+;
+; formerly NS.INTERNIC.NET
+;
+.                        3600000  IN  NS    A.ROOT-SERVERS.NET.
+A.ROOT-SERVERS.NET.      3600000      A     198.41.0.4
+;
+; formerly NS1.ISI.EDU
+;
+.                        3600000      NS    B.ROOT-SERVERS.NET.
+B.ROOT-SERVERS.NET.      3600000      A     128.9.0.107
+;
+; formerly C.PSI.NET
+;
+.                        3600000      NS    C.ROOT-SERVERS.NET.
+C.ROOT-SERVERS.NET.      3600000      A     192.33.4.12
+;
+; formerly TERP.UMD.EDU
+;
+.                        3600000      NS    D.ROOT-SERVERS.NET.
+D.ROOT-SERVERS.NET.      3600000      A     128.8.10.90
+;
+; formerly NS.NASA.GOV
+;
+.                        3600000      NS    E.ROOT-SERVERS.NET.
+E.ROOT-SERVERS.NET.      3600000      A     192.203.230.10
+;
+; formerly NS.ISC.ORG
+;
+.                        3600000      NS    F.ROOT-SERVERS.NET.
+F.ROOT-SERVERS.NET.      3600000      A     192.5.5.241
+;
+; formerly NS.NIC.DDN.MIL
+;
+.                        3600000      NS    G.ROOT-SERVERS.NET.
+G.ROOT-SERVERS.NET.      3600000      A     192.112.36.4
+;
+; formerly AOS.ARL.ARMY.MIL
+;
+.                        3600000      NS    H.ROOT-SERVERS.NET.
+H.ROOT-SERVERS.NET.      3600000      A     128.63.2.53
+;
+; formerly NIC.NORDU.NET
+;
+.                        3600000      NS    I.ROOT-SERVERS.NET.
+I.ROOT-SERVERS.NET.      3600000      A     192.36.148.17
+; End of File
diff --git a/bindlib_w32/conf/master/root.cache b/bindlib_w32/conf/master/root.cache
new file mode 100644 (file)
index 0000000..48abd78
--- /dev/null
@@ -0,0 +1,63 @@
+;       This file holds the information on root name servers needed to
+;       initialize cache of Internet domain name servers
+;       (e.g. reference this file in the "cache  .  <file>"
+;       configuration file of BIND domain name servers).
+;
+;       This file is made available by InterNIC registration services
+;       under anonymous FTP as
+;           file                /domain/named.root
+;           on server           FTP.RS.INTERNIC.NET
+;       -OR- under Gopher at    RS.INTERNIC.NET
+;           under menu          InterNIC Registration Services (NSI)
+;              submenu          InterNIC Registration Archives
+;           file                named.root
+;
+;       last update:    Nov 8, 1995
+;       related version of root zone:   1995110800
+;
+;
+; formerly NS.INTERNIC.NET
+;
+.                        3600000  IN  NS    A.ROOT-SERVERS.NET.
+A.ROOT-SERVERS.NET.      3600000      A     198.41.0.4
+;
+; formerly NS1.ISI.EDU
+;
+.                        3600000      NS    B.ROOT-SERVERS.NET.
+B.ROOT-SERVERS.NET.      3600000      A     128.9.0.107
+;
+; formerly C.PSI.NET
+;
+.                        3600000      NS    C.ROOT-SERVERS.NET.
+C.ROOT-SERVERS.NET.      3600000      A     192.33.4.12
+;
+; formerly TERP.UMD.EDU
+;
+.                        3600000      NS    D.ROOT-SERVERS.NET.
+D.ROOT-SERVERS.NET.      3600000      A     128.8.10.90
+;
+; formerly NS.NASA.GOV
+;
+.                        3600000      NS    E.ROOT-SERVERS.NET.
+E.ROOT-SERVERS.NET.      3600000      A     192.203.230.10
+;
+; formerly NS.ISC.ORG
+;
+.                        3600000      NS    F.ROOT-SERVERS.NET.
+F.ROOT-SERVERS.NET.      3600000      A     192.5.5.241
+;
+; formerly NS.NIC.DDN.MIL
+;
+.                        3600000      NS    G.ROOT-SERVERS.NET.
+G.ROOT-SERVERS.NET.      3600000      A     192.112.36.4
+;
+; formerly AOS.ARL.ARMY.MIL
+;
+.                        3600000      NS    H.ROOT-SERVERS.NET.
+H.ROOT-SERVERS.NET.      3600000      A     128.63.2.53
+;
+; formerly NIC.NORDU.NET
+;
+.                        3600000      NS    I.ROOT-SERVERS.NET.
+I.ROOT-SERVERS.NET.      3600000      A     192.36.148.17
+; End of File
diff --git a/bindlib_w32/conf/options.h b/bindlib_w32/conf/options.h
new file mode 100644 (file)
index 0000000..c2a841f
--- /dev/null
@@ -0,0 +1,160 @@
+/* options.h - specify the conditionally-compiled features
+ * vix 28mar92 [moved out of the Makefile because they were getting too big]
+ *
+ * $Id$
+ */
+
+/*
+ * ++Copyright++
+ * -
+ * Copyright (c) 
+ *    The Regents of the University of California.  All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ * 
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+
+/* Key:
+ *     ucb = U C Berkeley 4.8.3 release
+ *     vix = Paul Vixie of Digital
+ *     del = Don Lewis of Harris
+ *     mcsun = Piet Beertema of EUNet
+ *     asp = Andrew Partan of UUNet
+ *     pma = Paul Albitz of Hewlett Packard
+ *     bb = Bryan Beecher of UMich
+ *     mpa = Mark Andrews of CSIRO - DMS
+ *     rossc = Ross Cartlidge of The Univeritsy of Sydney
+ *     mtr = Marshall Rose of TPC.INT
+ *      bg = Benoit Grange of INRIA
+ *      ckd = Christopher Davis of Kapor Enterprises
+ *      gns = Greg Shapiro of WPI
+ */
+
+#define DEBUG          /* enable -d flag and SIGUSR[12] support (ucb) */
+/*#define ALLOW_T_UNSPEC /* enable the "unspec" RR type for old athena (ucb) */
+/*#define INVQ         /* enable inverse queries (nslookup) (ucb/vix) */
+/*#define DSTORAGE     /* debug malloc overruns using storage.o (ucb/vix) */
+/*#define DMALLOC      /* trace malloc orphans using dmalloc.o (vix) */
+#define XFRNETS        /* enable "xfrnets" command in named.boot (vix) */
+#define PID_FIX        /* be careful about overwriting named.pid file (del) */
+#define FWD_LOOP       /* try to break out of forwarding loops (del) */
+#define NO_GLUE        /* don't accept or send out-of-zone glue (del) */
+#define        BOGUSNS         /* detect bogus nameservers (mcsun) */
+#define QRYLOG         /* enable SIGWINCH for query logging (bb) */
+/*#define YPKLUDGE     /* deal effectively with broken "ypserv -i" (mcsun) */
+#define TRACEROOT      /* trace bogus root servers and ignore them (pma,bb) */
+/*#define LOCALDOM     /* permit "domain" directive in named.boot (ucb) */
+#define FORCED_RELOAD  /* refresh secondary zones on SIGHUP (pma) */
+#define SLAVE_FORWARD  /* use sensible timeouts on slave forwarders (pma) */
+#define WANT_PIDFILE   /* if you want the named.pid file (ucb/arc) */
+#define DOTTED_SERIAL  /* if you want to be able to specify dotted serial#s */
+#define SENSIBLE_DOTS  /* if you want dotted serial#s to make numeric sense */
+#define NCACHE         /* negative caching (anant@isi.edu) */
+/*#define VALIDATE     /* validation procedure (anant@isi.edu) (BUGGY!) */
+/*#define SHORT_FNAMES /* file names used in named-xfer need to be short */
+#define RESOLVSORT     /* allow sorting of addresses in gethostbyname (mpa) */
+#define STUBS          /* allow transfers of NS only for a zone (mpa) */
+#ifndef LOGFAC
+#define        LOGFAC LOG_DAEMON /* what syslog facility should named use? */
+#endif
+#define SECURE_ZONES   /* if you want to inhibit world access to zones (gns)*/
+#define ROUND_ROBIN    /* rotate databuf list after each access (mtr) */
+#define ADDAUTH        /* return NS and glue w/ authorative answers (mpa) */
+#define RFC1535                /* use RFC 1535 default for "search" list (vix) */
+#define GEN_AXFR       /* distinct zones within each class */
+#define LAME_DELEGATION        /* lame delegations (original-del,reworked-bb&del)*/
+#define LAME_LOGGING LOG_DEBUG /* log lame delegations, set log level */
+#define GETSER_LOGGING LOG_INFO /* log errors/timeouts getting serial number */
+#define RETURNSOA      /* good code that the world might be ready for now */
+#define CLEANCACHE     /* useful and necessary in the face of NCACHE */
+#define PURGE_ZONE     /* remove all traces of a zone when reloading (mpa) */
+#define STATS          /* keep nameserver statistics; uses more memory */
+#ifndef WINNT
+#define RENICE         /* named-xfer should run at normal priority */
+#endif
+#define XSTATS /* extended statistics, syslogged periodically (bg) */
+/*#define BIND_NOTIFY  /* experimental - do not enable in customer products */
+#define LOC_RR         /* support for LOC record parsing (ckd/vix) */
+#define SORT_RESPONSE  /* should we try to sort responses optimally? (vix) */
+
+/*--------------------------------------------*
+ * no user-servicable parts beyond this point *
+ *--------------------------------------------*/
+
+/* if DSTORAGE is defined, we need to disable DMALLOC and remap
+ * malloc and free to storage.o's exported names.  storage.o also
+ * includes a calloc and a realloc, but once we drag in its malloc
+ * and free we'll get the others automatically and so will never
+ * pull in those routines from libc.a.
+ */
+#ifdef DSTORAGE
+# ifdef DMALLOC
+#  undef DMALLOC
+# endif /*DMALLOC*/
+# define malloc        rt_malloc
+# define free rt_free
+#endif /*DSTORAGE*/
+
+/* if DMALLOC is defined, grab the header file which will remap
+ * all the malloc-style names to those exported by dmalloc.o.  note
+ * that DMALLOC also changes the function signatures of several
+ * functions in private named source modules, and that this file
+ * (options.h) must be included before any other private *.h files
+ * since those *.h files have some conditional remapping to do.
+ */
+#ifdef DMALLOC
+# include "dmalloc.h"
+#endif
+
+#ifdef LAME_LOGGING
+# define LAME_DELEGATION
+#endif
+
+#if defined(XSTATS) && !defined(STATS)
+# define STATS
+#endif
diff --git a/bindlib_w32/conf/portability.h b/bindlib_w32/conf/portability.h
new file mode 100644 (file)
index 0000000..e13f03f
--- /dev/null
@@ -0,0 +1,763 @@
+/* portability.h - include or define things that aren't present on all systems
+ * vixie@decwrl 26dec92 [new]
+ *
+ * $Id$
+ */
+
+/*
+ * Copyright (c) 
+ *    The Regents of the University of California.  All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ * 
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+/*
+ * Portions Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#ifndef __BIND_PORTABILITY_H
+#define __BIND_PORTABILITY_H
+
+#include <sys/types.h>
+#ifndef WINNT
+#include <sys/param.h>
+#endif
+#include <string.h>
+#include <signal.h>
+#ifndef WINNT
+#ifndef TIME_H_INCLUDED
+# include <sys/time.h>
+# define TIME_H_INCLUDED
+#endif
+#endif /* WINNT */
+
+#ifdef WINNT
+#ifndef _PORTABILITY_H
+#define _PORTABILITY_H
+#include <stdio.h>
+#ifdef BUFSIZ
+#undef BUFSIZ
+#endif
+#define BUFSIZ 1024  /* GMS - added since Unix used 1K and NT 512B */
+#include <string.h>
+#include <process.h>
+#include <sys/timeb.h>
+#include <time.h>
+#include <io.h>
+#include <stdlib.h>
+#define FD_SETSIZE 512
+#include <winsock.h>
+#include <windows.h>
+#include <limits.h>
+
+#define NOWAIT
+#define HAVE_SETVBUF
+#define NEED_GETTIMEOFDAY
+#define USE_MEMCPY
+#undef IP_OPTIONS
+#define PATH_MAX MAX_PATH
+#define ETIMEDOUT WSAETIMEDOUT
+#define ECONNRESET WSAECONNRESET
+#define ECONNREFUSED WSAECONNREFUSED
+#define EADDRINUSE WSAEADDRINUSE
+#define PORT_WOULDBLK WSAEWOULDBLOCK
+#define _TIMEZONE timezoneBSD
+
+struct timezoneBSD {
+       int tz_minuteswest;
+       int tz_dsttime;
+};
+struct iovec {
+       char *  iov_base;
+       int     iov_len;
+};
+typedef char * caddr_t;
+typedef long pid_t;
+#define sleep(t) Sleep(t*1000)
+/* (Removed by Zeev - the DLL version of the C runtime conflicts with this
+ * #ifdef errno
+ * #undef errno
+ * #endif
+ * #define errno WSAGetLastError()
+ */
+/* #define close(s) closesocket(s) */
+#define chdir(path) SetCurrentDirectory(path)
+#define dup2(s1, s2) DuplicateHandle(GetCurrentProcess(), (HANDLE)(s1), \
+                                       GetCurrentProcess(), (LPHANDLE)&(s2), \
+                                       0, FALSE, DUPLICATE_SAME_ACCESS);
+#define strcasecmp(x, y) stricmp(x, y)
+#define strncasecmp(x, y, z) strnicmp(x, y, z)
+
+void   service_main(DWORD, LPTSTR *);
+void   service_ctrl(DWORD);
+void    worker_thread(void *);
+void    dispatch_thread(void *);
+void syslog(int, char *, ...);
+void expand_paths(void);
+int writev(int, struct iovec *, int);
+int mkstemp(char *);
+
+#define MAXALIASES 35
+#define LOG_EMERG       0       /* system is unusable */
+#define LOG_ALERT       1       /* action must be taken immediately */
+#define LOG_CRIT        2       /* critical conditions */
+#define LOG_ERR         3       /* error conditions */
+#define LOG_WARNING     4       /* warning conditions */
+#define LOG_NOTICE      5       /* normal but signification condition */
+#define LOG_INFO        6       /* informational */
+#define LOG_DEBUG       7       /* debug-level messages */
+/* control codes that the service will accept */
+#define SERVICE_CONTROL_DUMPDB  128
+#define SERVICE_CONTROL_RELOAD  129
+#define SERVICE_CONTROL_STATS   130
+#define SERVICE_CONTROL_TRACE   131
+#define SERVICE_CONTROL_NOTRACE 132
+#define SERVICE_CONTROL_QRYLOG  133
+#define SERVICE_CONTROL_CHKPT   134
+#define SERVICE_CONTROL_EXIT    135
+#define SERVICE_CONTROL_NOLOG   136
+#define SERVICE_CONTROL_LOG     137
+#endif /* _PORTABILITY_H */
+#endif /* WINNT */
+
+/* (ISC = INTERACTIVE Systems Corporation in the next #ifdef, btw.) */
+#ifdef ISC
+# ifndef _POSIX_SOURCE
+#  define _POSIX_SOURCE
+# endif
+# define SYSV
+# define SVR3
+# define _SYSV3
+# define NEED_STRTOUL
+# define NEED_FTRUNCATE
+# define USE_POSIX
+# include <sys/bsdtypes.h>
+# include <sys/sioctl.h>
+# include <sys/stream.h>
+# include <net/errno.h>
+#endif
+
+#if defined(__convex__)
+# if !defined(_POSIX_SOURCE)
+#  define _POSIX_SOURCE
+# endif
+# define USE_UTIME
+# define NEED_PUTENV
+#endif
+
+#if defined(_CRAY)
+# if !defined(_POSIX_SOURCE)
+#  define _POSIX_SOURCE
+# endif
+# define writev(a,b,c) __writev(a,b,c)
+# define setitimer(a,b,c) __setitimer(a,b,c)
+#endif
+
+/* This is for AIX 4.1.x */
+#ifdef _AIX41
+# include <sys/select.h>
+# include <sys/time.h>
+# include <time.h>
+# define vfork fork
+#endif
+
+/* This is defined in the Makefile for INTERACTIVE compiles. */
+#if defined(ISC)
+# define ftruncate(a,b) __ftruncate(a,b)
+# define USE_MEMCPY
+# define USE_UTIME
+# define HAVE_FCHMOD 0
+#endif
+
+/* SCO UNIX defines only this unique symbol, apparently. */
+#if defined(M_UNIX)
+# define POSIX_SIGNALS
+# if !defined(_SCO_DS)
+/* This section is for 3.2v4.2/ODT3.0 and maybe also for 3.2v4.1/3.2v4.0 */
+/* XXX - why is this POSIX_SOURCE instead of _POSIX_SOURCE? */
+#  undef POSIX_SOURCE
+#  define HAVE_FCHMOD 0
+#  define NEED_WRITEV
+#  define writev(a,b,c) __writev(a,b,c)
+#  define ftruncate(a,b) __ftruncate(a,b)
+# endif
+#endif
+
+#ifdef NeXT
+# define NEED_PUTENV
+# define NEED_SETENV
+# define HAVE_STDLIB_H
+# define NEED_STRDUP
+# define inet_addr(a) __inet_addr(a)
+#endif
+
+#if defined(__sgi)
+# define BSD 43
+# define vfork fork
+#endif
+
+#if defined(SUNOS4)
+# define BSD 43
+# define NEED_STRTOUL
+#endif
+
+#if defined(__osf__) && defined(__alpha) && defined(BSD) && (BSD < 199103)
+# undef BSD
+# define BSD 199103
+#endif
+
+#if defined(_AUX_SOURCE)
+# define vfork fork
+# define NEED_STRERROR
+# define NEED_STRTOUL
+# define SIG_FN void
+# define USE_MEMCPY
+#endif
+
+#if defined(apollo)
+# define HAVE_STDLIB_H
+#endif
+
+#if defined(SVR4) && !defined(SYSV)
+# define SYSV
+#endif
+
+#if defined(_POSIX_SOURCE) || defined(__sgi) || defined(__ultrix) || \
+       defined(__hpux) || (defined(BSD) && (BSD >= 199103)) || \
+       defined(sun) || defined(__m88k__)
+# define USE_POSIX
+#endif
+
+#if defined(__ultrix) && !defined(BSD)
+# define BSD 42
+#endif
+
+#if defined(host_mips) && defined(SYSTYPE_BSD43)
+# define RISCOS_BSD
+#endif
+
+#if defined(SYSV) || defined(__ultrix) || defined(__osf__) \
+       || (defined(BSD) && BSD >= 199306) || defined(linux)
+# define USE_UTIME
+# define HAVE_SETVBUF
+#endif
+
+#if defined(SYSV) && !defined(SVR4)
+# define vfork fork
+#endif
+
+#if defined(sun) || defined(SVR4)
+# define NETREAD_BROKEN
+#endif
+
+#if defined(BSD) && BSD >= 199006 && !defined(i386) && !defined(RISCOS_BSD)
+# define HAVE_DAEMON
+#endif
+
+#if !defined(BSD) || (BSD <= 199006)
+# if !defined(NeXT)    && !defined(WINNT)
+#  define NEED_INETADDR
+# endif
+# define NEED_INETATON
+#endif
+
+#if defined(__hpux)
+# if defined(__STDC__)
+#  define select(a,b,c,d,e) select(a, (int *)b, (int *)c, (int *)d, e)
+#  define ctime(x) ctime((const time_t *)x)
+# endif /*__STDC__*/
+# if !defined(SYSV)
+#  define USE_UTIME
+#  define setlinebuf(x) setvbuf(x, NULL, _IOLBF, BUFSIZ)
+#  if !defined(SIGWINCH)  /*pre 9.0*/
+#   define SIGWINCH SIGWINDOW
+#  endif
+# endif /*SYSV*/
+/* XXX: better autodetection of the need for "struct linger" would be nice */
+# if 0
+struct linger {
+       int     l_onoff;                /* option on/off */
+       int     l_linger;               /* linger time */
+};
+# endif
+#endif /*__hpux*/
+
+#if defined(_SEQUENT_)
+# include <netinet/in_systm.h>
+# define USE_UTIME
+# define USE_POSIX
+# define NEED_GETTIMEOFDAY
+# define _TIMEZONE timezoneBSD
+struct timezoneBSD {
+       int tz_minuteswest;
+       int tz_dsttime;
+};
+#endif
+
+#ifndef __P
+# if defined(__STDC__) || defined(__GNUC__)
+#  define __P(x) x
+# else
+#  define __P(x) ()
+# endif
+#endif
+
+#ifndef _TIMEZONE
+# define _TIMEZONE timezone
+#endif
+
+#if defined(USE_POSIX) || defined(HAVE_STDLIB_H)
+# include <stdlib.h>
+# if defined(__ultrix)
+#  define NEED_STRDUP
+# endif
+
+#else
+
+# if !defined(_SCO_DS)
+#  define NEED_STRDUP
+#  define NEED_STRTOUL
+# endif
+
+#ifndef WINNT
+# if !defined(NeXT) && !defined(WINNT)
+extern char *getenv __P((char *));
+# else
+extern char *getenv __P((const char *));
+# endif
+#endif
+
+# if !defined(DMALLOC) && !defined(NeXT) && !defined(WINNT)
+extern char *malloc(), *realloc(), *calloc();
+extern void free();
+# endif
+
+#endif /*HAVE_STDLIB_H*/
+
+#if defined(USE_POSIX)
+# include <unistd.h>
+# include <limits.h>
+
+#else
+
+# define STDIN_FILENO  0
+# define STDOUT_FILENO 1
+# define STDERR_FILENO 2
+#ifndef WINNT
+extern int errno;
+#endif
+
+extern int getdtablesize __P((void));
+# ifdef SHORT_FNAMES
+extern long pathconf __P((const char *path, int name));
+# endif
+
+#endif /*USE_POSIX*/
+
+#ifndef UINT_MAX
+# ifdef __STDC__
+#  define UINT_MAX     4294967295u             /* max value of an "u_int" */
+# else
+#  define UINT_MAX     ((unsigned)4294967295)  /* max value of an "u_int" */
+# endif
+#  define ULONG_MAX    UINT_MAX        /* max decimal value of a "u_long" */
+#endif
+
+#ifndef INT_MAX
+# define INT_MAX       2147483647      /* max decimal value of an "int" */
+#endif
+
+#ifndef RAND_MAX
+# define RAND_MAX      0x7fffffff
+#endif
+
+#ifndef        IN_LOOPBACKNET
+# define IN_LOOPBACKNET        127
+#endif
+
+#ifndef        INADDR_NONE
+# define INADDR_NONE   0xffffffff
+#endif
+
+#if defined(apollo)
+               /* Defined in /usr/include/netinet/in.h but doesn't work */
+#undef IP_OPTIONS
+#endif
+
+#if !defined(__STDC__) && !defined(const) && !defined(WINNT)
+# define const /*constant*/
+#endif
+
+#if !defined(__convex__) && (!defined(BSD) || (BSD < 199103))
+int      strcasecmp __P((const char *, const char *));
+#endif
+
+/* is USE_POSIX the right thing to use here? */
+#if (!defined(BSD) || (BSD <= 43)) && \
+       !defined(NeXT) && \
+       !defined(WINNT) && \
+       !defined(__convex__) && \
+       !defined(USE_POSIX)
+# if !defined(NCR)
+extern void    syslog();
+# endif
+extern char    *ctime __P((const time_t *clock));
+# if !defined(M_UNIX)
+extern int     close(), setitimer(), recv(), sendto(), sigsetmask(),
+               atoi(), getpid(), fork(), read(), ioctl(),
+               setsockopt(), socket(), bind();
+# endif
+#endif
+
+#if !defined(bcopy) /* some machines have their own macros for this */
+#if (defined(USE_POSIX) && !defined(SUNOS4)) || defined(WINNT) ||\
+        (defined(__STDC__) && !defined(sun) && !defined(sequent) \
+         && !defined(M_UNIX))
+/* use ANSI C3.159-1989 (``ANSI C'') functions if possible;
+ * ideally we would change the code to use them and then
+ * define them in terms of bcopy et al if !defined(__STDC__)
+ * but that's more work.
+ */
+#if defined(USE_MEMCPY)
+#  define bcopy(a,b,c) memcpy(b,a,c)
+#else
+#  define bcopy(a,b,c) memmove(b,a,c)
+#endif
+#  define bzero(a,b) memset(a,0,b)
+#  define bcmp(a,b,c) memcmp(a,b,c)
+# else
+extern void bcopy();
+extern void bzero();
+extern int bcmp();
+# endif /* BSD */
+#endif /* bcopy */
+
+#if (!defined(BSD) || (BSD < 43) || defined(RISCOS_BSD)) \
+       && !defined(USE_POSIX) && !defined(apollo) && !defined(sequent) \
+       && !defined(M_UNIX)     && !defined(WINNT)
+# define NEED_STRERROR
+#if !defined(ultrix) && !defined(NCR)
+# define NEED_PUTENV
+#endif
+#endif
+
+#if defined(SUNOS4)
+# define NEED_STRERROR
+# if defined(sun386)
+#  define pid_t int
+#  define NEED_STRCASECMP
+# endif
+#endif
+
+#if (!defined(BSD) || (BSD < 43)) && !defined(__hpux)
+# define NEED_MKSTEMP
+# if !defined(__ultrix) && !defined(apollo) && !defined(WINNT)
+#  if !defined(_SCO_DS)
+#   define NEED_STRCASECMP
+#   define NEED_MKTEMP
+#   if !defined(SVR4)
+#    define NEED_STRPBRK
+#   endif
+#  endif
+# endif
+#endif
+
+#if defined(USE_POSIX)
+# define POSIX_SIGNALS
+#endif
+
+/*
+ * Attempt to configure for type of function returned by signal-catching
+ * functions (which signal and sigvec.sv_handler take a pointer to).
+ * This can guess for BSD; otherwise, define SIG_FN externally.
+ */
+#ifndef        SIG_FN
+# ifdef BSD
+#  if (BSD >= 199006) || defined(NeXT) || defined(__osf__) || defined(sun) \
+       || defined(__ultrix) || defined(apollo) || defined(POSIX_SIGNALS)
+#   define SIG_FN void         /* signal-catching functions return void */
+#  else
+#   define SIG_FN int          /* signal-catching functions return int */
+#  endif
+# else /*BSD*/
+#  define SIG_FN void          /* signal-catching functions return void */
+# endif /*BSD*/
+#endif
+
+#if !defined(SIGUSR1) && !defined(SIGUSR2)
+# define SIGUSR1 SIGEMT
+# define SIGUSR2 SIGFPE
+#endif
+#if !defined(SIGCHLD)
+# define SIGCHLD SIGCLD
+#endif
+
+#if !defined(ntohl) && !defined(htonl) && defined(BSD) && (BSD <= 43)
+/* if these aren't null macros in netinet/in.h, extern them here. */
+extern u_short htons __P((u_short)), ntohs __P((u_short));
+extern u_long htonl __P((u_long)), ntohl __P((u_long));
+#endif
+
+#if defined(USE_POSIX) && !defined(sun) && !defined(__sgi) \
+       && !defined(__convex__) && !defined(__ultrix) && !defined(_AUX_SOURCE)
+# define PORT_NONBLOCK O_NONBLOCK
+# define PORT_WOULDBLK EAGAIN
+#else
+#if !defined(WINNT)
+# define PORT_NONBLOCK O_NDELAY
+# define PORT_WOULDBLK EWOULDBLOCK
+#endif
+#endif
+
+#if defined(USE_POSIX)
+# define USE_SETSID
+#endif
+
+#if defined(USE_POSIX) || !defined(SYSV)
+#define USE_WAITPID
+#endif
+
+#if !defined(USE_POSIX) && !defined(WINNT)
+#define waitpid(x,y,z) (wait3(y,z,(struct rusage *)NULL))
+#endif
+
+#if defined(NeXT) || defined(_AIX) || defined(sun386)
+# undef WIFEXITED
+# undef WEXITSTATUS
+# undef WIFSIGNALED
+# undef WTERMSIG
+#endif /* NeXT */
+
+#if defined(sequent)
+#define WEXITSTATUS(x) ((x).w_retcode)
+#define WTERMSIG(x)    ((x).w_termsig)
+#endif /* sequent */
+
+#ifndef WINNT
+#if !defined(WIFEXITED)
+# define WIFEXITED(x) (!(x & 0177))
+#endif
+#if !defined(WEXITSTATUS)
+# define WEXITSTATUS(x) (x >> 8)
+#endif
+#if !defined(WIFSIGNALED)
+# define WIFSIGNALED(x) ((x & 0177) && ((x & 0377) != 0177))
+#endif
+#if !defined(WTERMSIG)
+# define WTERMSIG(x) (x & 0177)
+#endif
+#endif
+
+#ifndef S_ISDIR
+# ifndef S_IFMT
+#  define S_IFMT 0170000
+# endif
+# ifndef S_IFDIR
+#  define S_IFDIR 0040000
+# endif
+# define S_ISDIR(m)    ((m & S_IFMT) == S_IFDIR)
+#endif
+
+#ifndef S_ISREG
+# ifndef S_IFMT
+#  define S_IFMT 0170000
+# endif
+# ifndef S_IFREG
+#  define S_IFREG 0100000
+# endif
+# define S_ISREG(m)    ((m & S_IFMT) == S_IFREG)
+#endif
+
+#ifndef S_ISFIFO
+# ifndef S_IFMT
+#  define S_IFMT 0170000
+# endif
+# ifndef S_IFIFO
+#  define S_IFIFO 0010000
+# endif
+# define S_ISFIFO(m)   ((m & S_IFMT) == S_IFIFO)
+#endif
+
+#if defined(NEED_STRTOUL) && \
+       (defined(__ultrix) || defined(__osf__) || defined(NeXT) || defined(WINNT))
+# undef NEED_STRTOUL
+#endif
+
+#if defined(__ultrix) || defined(__osf__)
+# define MAYBE_HESIOD
+#endif
+
+#ifndef FD_SET
+#define        NFDBITS         32
+#define        FD_SETSIZE      32
+#define        FD_SET(n, p)    ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
+#define        FD_CLR(n, p)    ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
+#define        FD_ISSET(n, p)  ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
+#define FD_ZERO(p)     bzero((char *)(p), sizeof(*(p)))
+#endif
+
+#ifndef MIN
+# define MIN(x, y)     ((x > y) ?y :x)
+#endif
+#ifndef MAX
+# define MAX(x, y)     ((x > y) ?x :y)
+#endif
+
+#if !defined(PATH_MAX)
+# if defined(_POSIX_PATH_MAX)
+#  define PATH_MAX _POSIX_PATH_MAX
+# else
+#  if defined(MAXPATHLEN)
+#   define PATH_MAX MAXPATHLEN
+#  endif
+# endif
+#endif
+
+#if defined(BSD) || defined(__osf__) || defined(__convex__)
+# define HAVE_GETRUSAGE
+#endif
+
+/* May be set in the Makefile. */
+#if defined(HAVE_GETRUSAGE)
+# include <sys/resource.h>
+#endif
+
+/*
+ *  Because Convex has true library function feof() which is
+ *  patently wrong (it test bit _IOREAD) we need feof() as
+ *  a macro.
+ */
+#if defined(__convex__) && !defined(feof)
+#  define   feof(p)    ((p)->_flag&_IOEOF)
+#endif
+
+#if defined(M_UNIX) || defined(linux)
+# define SPURIOUS_ECONNREFUSED
+#endif
+
+/*
+ * Assume that a system has fchmod() unless something above says otherwise.
+ */
+#if !defined(HAVE_FCHMOD) && !defined(WINNT)
+# define HAVE_FCHMOD 1
+#endif
+
+/*
+ * Some systems need _res to be linked into text rather than bss.
+ */
+#if defined(__m88k__)
+# define __BIND_RES_TEXT
+#endif
+
+/*
+ * Motorola FH40.43 and FH40.44 need specific macros for
+ * get/settimeofday as only one argument seems to be accepted
+ * by the compiler. NULL generates compile errors
+ */
+#if defined(__m88k__) && defined(__unix__)
+# define gettimeofday(tp, tzp) gettimeofday(tp)
+# define settimeofday(tp, tzp) settimeofday(tp)
+#endif
+
+/*
+ * We need to know the IPv6 address family number even on IPv4-only systems.
+ * Note that this is NOT a protocol constant, and that if the system has its
+ * own AF_INET6, different from ours below, all of BIND's libraries and
+ * executables will need to be recompiled after the system <sys/socket.h>
+ * has had this type added.  The type number below is correct on most BSD-
+ * derived systems for which AF_INET6 is defined.
+ */
+#ifndef AF_INET6
+#define AF_INET6       24
+#endif
+
+/*
+ * Prototype the functions we'll be supplying.
+ */
+#ifdef NEED_PUTENV
+extern int putenv __P((char *));
+#endif
+
+#ifdef NEED_GETTIMEOFDAY
+extern int gettimeofday __P((struct timeval *, struct _TIMEZONE *));
+#endif
+
+#if defined(SVR4) && defined(sun)
+extern int gethostname __P((char *, size_t));
+#endif
+
+#ifdef WINNT
+#undef NEED_STRDUP
+#endif
+
+#ifdef NEED_STRDUP
+extern char *strdup __P((const char *));
+#endif
+
+#endif /*__BIND_PORTABILITY_H*/
+
+#ifdef WINNT /* l kahn new definitions needed for vc++4.0 */
+#define fstat _fstat
+#define stat _stat
+#define fileno _fileno
+extern BOOL OnWinnt();
+#endif
diff --git a/bindlib_w32/gethnamaddr.c b/bindlib_w32/gethnamaddr.c
new file mode 100644 (file)
index 0000000..98b49f3
--- /dev/null
@@ -0,0 +1,1184 @@
+/*
+ * ++Copyright++ 1985, 1988, 1993
+ * -
+ * Copyright (c) 1985, 1988, 1993
+ *    The Regents of the University of California.  All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ * 
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)gethostnamadr.c    8.1 (Berkeley) 6/4/93";
+static char rcsid[] = "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#ifndef WINNT
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#endif
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+
+#include <stdio.h>
+#include <netdb.h>
+#include <resolv.h>
+#include <ctype.h>      
+#include <errno.h>
+#ifndef WINNT
+#include <syslog.h>
+#endif
+
+#ifndef LOG_AUTH
+#define LOG_AUTH 0
+#endif
+
+#define MULTI_PTRS_ARE_ALIASES 1       /* XXX - experimental */
+
+#if defined(BSD) && (BSD >= 199103) && defined(AF_INET6)
+#include <stdlib.h>
+#include <string.h>
+#else
+#include "conf/portability.h"
+#endif
+
+#if defined(USE_OPTIONS_H)
+#include <conf/options.h>
+#endif
+
+#ifdef SPRINTF_CHAR
+#define SPRINTF(x) strlen(sprintf/**/x)
+#else
+#define SPRINTF(x) ((size_t)sprintf x)
+#endif
+
+#ifdef WINNT
+extern char *pathhosts;
+extern int res_paths_initialized;
+extern init_res_paths();
+#endif
+
+#define        MAXALIASES      35
+#define        MAXADDRS        35
+
+static const char AskedForGot[] =
+                         "gethostby*.getanswer: asked for \"%s\", got \"%s\"";
+
+static char *h_addr_ptrs[MAXADDRS + 1];
+
+static struct hostent host;
+static char *host_aliases[MAXALIASES];
+static char hostbuf[8*1024];
+static u_char host_addr[16];   /* IPv4 or IPv6 */
+static FILE *hostf = NULL;
+static int stayopen = 0;
+
+int inet_pton();
+static void map_v4v6_address __P((const char *src, char *dst));
+static void map_v4v6_hostent __P((struct hostent *hp, char **bp, int *len));
+
+#ifdef RESOLVSORT
+static void addrsort __P((char **, int));
+#endif
+
+#if PACKETSZ > 1024
+#define        MAXPACKET       PACKETSZ
+#else
+#define        MAXPACKET       1024
+#endif
+
+typedef union {
+    HEADER hdr;
+    u_char buf[MAXPACKET];
+} querybuf;
+
+typedef union {
+    int32_t al;
+    char ac;
+} align;
+
+#ifndef WINNT
+extern int h_errno;
+#endif
+
+#ifdef DEBUG
+static void
+dprintf(msg, num)
+       char *msg;
+       int num;
+{
+       if (_res.options & RES_DEBUG) {
+               int save = errno;
+
+               printf(msg, num);
+#ifndef WINNT
+               errno = save;
+#else
+               WSASetLastError(save);
+               SetLastError(save);
+#endif
+       }
+}
+#else
+#define dprintf(msg, num) /*nada*/
+#endif
+
+#ifndef WINNT
+#define BOUNDED_INCR(x) \
+       do { \
+               cp += x; \
+               if (cp > eom) { \
+                       h_errno = NO_RECOVERY; \
+                       return (NULL); \
+               } \
+       } while (0)
+
+#else
+
+#define BOUNDED_INCR(x) \
+       do { \
+               cp += x; \
+               if (cp > eom) { \
+               WSASetLastError(NO_RECOVERY); \
+                       return (NULL); \
+               } \
+       } while (0)
+
+#endif
+
+#ifndef WINNT  
+#define BOUNDS_CHECK(ptr, count) \
+       do { \
+               if ((ptr) + (count) > eom) { \
+                       h_errno = NO_RECOVERY; \
+                       return (NULL); \
+               } \
+       } while (0)
+#else
+#define BOUNDS_CHECK(ptr, count) \
+       do { \
+               if ((ptr) + (count) > eom) { \
+               WSASetLastError(NO_RECOVERY); \
+                       return (NULL); \
+               } \
+       } while (0)
+#endif
+       
+static struct hostent *
+getanswer(answer, anslen, qname, qtype)
+       const querybuf *answer;
+       int anslen;
+       const char *qname;
+       int qtype;
+{
+       register const HEADER *hp;
+       register const u_char *cp;
+       register int n;
+       const u_char *eom, *erdata;
+       char *bp, **ap, **hap;
+       int type, class, buflen, ancount, qdcount;
+       int haveanswer, had_error;
+       int toobig = 0;
+       char tbuf[MAXDNAME];
+       const char *tname;
+       int (*name_ok) __P((const char *));
+
+       tname = qname;
+       host.h_name = NULL;
+       eom = answer->buf + anslen;
+       switch (qtype) {
+       case T_A:
+       case T_AAAA:
+               name_ok = res_hnok;
+               break;
+       case T_PTR:
+               name_ok = res_dnok;
+               break;
+       default:
+               return (NULL);  /* XXX should be abort(); */
+       }
+       /*
+        * find first satisfactory answer
+        */
+       hp = &answer->hdr;
+       ancount = ntohs((u_short)hp->ancount);
+       qdcount = ntohs((u_short)hp->qdcount);
+       bp = hostbuf;
+       buflen = sizeof hostbuf;
+       cp = answer->buf;
+       BOUNDED_INCR(HFIXEDSZ);
+       if (qdcount != 1) {
+#ifndef WINNT
+               h_errno = NO_RECOVERY;
+#else
+               WSASetLastError(NO_RECOVERY);
+#endif
+               return (NULL);
+       }
+       n = dn_expand(answer->buf, eom, cp, bp, buflen);
+       if ((n < 0) || !(*name_ok)(bp)) {
+#ifndef WINNT
+               h_errno = NO_RECOVERY;
+#else
+               WSASetLastError(NO_RECOVERY);
+#endif
+               return (NULL);
+       }
+       BOUNDED_INCR(n + QFIXEDSZ);
+       if (qtype == T_A || qtype == T_AAAA) {
+               /* res_send() has already verified that the query name is the
+                * same as the one we sent; this just gets the expanded name
+                * (i.e., with the succeeding search-domain tacked on).
+                */
+               n = strlen(bp) + 1;             /* for the \0 */
+               if (n >= MAXHOSTNAMELEN) {
+#ifndef WINNT
+               h_errno = NO_RECOVERY;
+#else
+               WSASetLastError(NO_RECOVERY);
+#endif
+                       return (NULL);
+               }
+               host.h_name = bp;
+               bp += n;
+               buflen -= n;
+               /* The qname can be abbreviated, but h_name is now absolute. */
+               qname = host.h_name;
+       }
+       ap = host_aliases;
+       *ap = NULL;
+       host.h_aliases = host_aliases;
+       hap = h_addr_ptrs;
+       *hap = NULL;
+       host.h_addr_list = h_addr_ptrs;
+       haveanswer = 0;
+       had_error = 0;
+       while (ancount-- > 0 && cp < eom && !had_error) {
+               n = dn_expand(answer->buf, eom, cp, bp, buflen);
+               if ((n < 0) || !(*name_ok)(bp)) {
+                       had_error++;
+                       continue;
+               }
+               cp += n;                        /* name */
+               BOUNDS_CHECK(cp, 3 * INT16SZ + INT32SZ);
+               type = _getshort(cp);
+               cp += INT16SZ;                  /* type */
+               class = _getshort(cp);
+               cp += INT16SZ + INT32SZ;        /* class, TTL */
+               n = _getshort(cp);
+               cp += INT16SZ;                  /* len */
+               BOUNDS_CHECK(cp, n);
+               erdata = cp + n;
+               if (class != C_IN) {
+                       /* XXX - debug? syslog? */
+                       cp += n;
+                       continue;               /* XXX - had_error++ ? */
+               }
+               if ((qtype == T_A || qtype == T_AAAA) && type == T_CNAME) {
+                       if (ap >= &host_aliases[MAXALIASES-1])
+                               continue;
+                       n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf);
+                       if ((n < 0) || !(*name_ok)(tbuf)) {
+                               had_error++;
+                               continue;
+                       }
+                       cp += n;
+                       if (cp != erdata) {
+#ifndef WINNT
+                       h_errno = NO_RECOVERY;
+#else
+                       WSASetLastError(NO_RECOVERY);
+#endif
+                               return (NULL);
+                       }
+                       /* Store alias. */
+                       *ap++ = bp;
+                       n = strlen(bp) + 1;     /* for the \0 */
+                       if (n >= MAXHOSTNAMELEN) {
+                               had_error++;
+                               continue;
+                       }
+                       bp += n;
+                       buflen -= n;
+                       /* Get canonical name. */
+                       n = strlen(tbuf) + 1;   /* for the \0 */
+                       if (n > buflen || n >= MAXHOSTNAMELEN) {
+                               had_error++;
+                               continue;
+                       }
+                       strcpy(bp, tbuf);
+                       host.h_name = bp;
+                       bp += n;
+                       buflen -= n;
+                       continue;
+               }
+               if (qtype == T_PTR && type == T_CNAME) {
+                       n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf);
+                       if (n < 0 || !res_dnok(tbuf)) {
+                               had_error++;
+                               continue;
+                       }
+                       cp += n;
+                       if (cp != erdata) {
+#ifndef WINNT
+                       h_errno = NO_RECOVERY;
+#else
+                       WSASetLastError(NO_RECOVERY);
+#endif
+                               return (NULL);
+                       }
+                       /* Get canonical name. */
+                       n = strlen(tbuf) + 1;   /* for the \0 */
+                       if (n > buflen || n >= MAXHOSTNAMELEN) {
+                               had_error++;
+                               continue;
+                       }
+                       strcpy(bp, tbuf);
+                       tname = bp;
+                       bp += n;
+                       buflen -= n;
+                       continue;
+               }
+               if (type != qtype) {
+                       syslog(LOG_NOTICE|LOG_AUTH,
+              "gethostby*.getanswer: asked for \"%s %s %s\", got type \"%s\"",
+                              qname, p_class(C_IN), p_type(qtype),
+                              p_type(type));
+                       cp += n;
+                       continue;               /* XXX - had_error++ ? */
+               }
+               switch (type) {
+               case T_PTR:
+                       if (strcasecmp(tname, bp) != 0) {
+                               syslog(LOG_NOTICE|LOG_AUTH,
+                                      (char *) AskedForGot, qname, bp);
+                               cp += n;
+                               continue;       /* XXX - had_error++ ? */
+                       }
+                       n = dn_expand(answer->buf, eom, cp, bp, buflen);
+                       if ((n < 0) || !res_hnok(bp)) {
+                               had_error++;
+                               break;
+                       }
+#if MULTI_PTRS_ARE_ALIASES
+                       cp += n;
+                       if (cp != erdata) {
+#ifndef WINNT
+                       h_errno = NO_RECOVERY;
+#else
+                       WSASetLastError(NO_RECOVERY);
+#endif
+                               return (NULL);
+                       }
+                       if (!haveanswer)
+                               host.h_name = bp;
+                       else if (ap < &host_aliases[MAXALIASES-1])
+                               *ap++ = bp;
+                       else
+                               n = -1;
+                       if (n != -1) {
+                               n = strlen(bp) + 1;     /* for the \0 */
+                               if (n >= MAXHOSTNAMELEN) {
+                                       had_error++;
+                                       break;
+                               }
+                               bp += n;
+                               buflen -= n;
+                       }
+                       break;
+#else
+                       host.h_name = bp;
+                       if (_res.options & RES_USE_INET6) {
+                               n = strlen(bp) + 1;     /* for the \0 */
+                               if (n >= MAXHOSTNAMELEN) {
+                                       had_error++;
+                                       break;
+                               }
+                               bp += n;
+                               buflen -= n;
+                               map_v4v6_hostent(&host, &bp, &buflen);
+                       }
+#ifndef WINNT
+                      h_errno = NETDB_SUCCESS;
+#else
+                      WSASetLastError(NETDB_SUCCESS);
+#endif
+                       return (&host);
+#endif
+               case T_A:
+               case T_AAAA:
+                       if (strcasecmp(host.h_name, bp) != 0) {
+                               syslog(LOG_NOTICE|LOG_AUTH,
+                                      (char *)AskedForGot, host.h_name, bp);
+                               cp += n;
+                               continue;       /* XXX - had_error++ ? */
+                       }
+                       if (n != host.h_length) {
+                               cp += n;
+                               continue;
+                       }
+                       if (!haveanswer) {
+                               register int nn;
+
+                               host.h_name = bp;
+                               nn = strlen(bp) + 1;    /* for the \0 */
+                               bp += nn;
+                               buflen -= nn;
+                       }
+
+                       bp += sizeof(align) - ((u_long)bp % sizeof(align));
+
+                       if (bp + n >= &hostbuf[sizeof hostbuf]) {
+                               dprintf("size (%d) too big\n", n);
+                               had_error++;
+                               continue;
+                       }
+                       if (hap >= &h_addr_ptrs[MAXADDRS-1]) {
+                               if (!toobig++)
+                                       dprintf("Too many addresses (%d)\n",
+                                               MAXADDRS);
+                               cp += n;
+                               continue;
+                       }
+                       bcopy(cp, *hap++ = bp, n);
+                       bp += n;
+                       buflen -= n;
+                       cp += n;
+                       if (cp != erdata) {
+#ifndef WINNT
+                               h_errno = NO_RECOVERY;
+#else
+                               WSASetLastError(NO_RECOVERY);
+#endif
+                               return (NULL);
+                       }
+                       break;
+               default:
+                       abort();
+               }
+               if (!had_error)
+                       haveanswer++;
+       }
+       if (haveanswer) {
+               *ap = NULL;
+               *hap = NULL;
+#if defined(RESOLVSORT)
+               /*
+                * Note: we sort even if host can take only one address
+                * in its return structures - should give it the "best"
+                * address in that case, not some random one
+                */
+               if (_res.nsort && haveanswer > 1 && qtype == T_A)
+                       addrsort(h_addr_ptrs, haveanswer);
+#endif /*RESOLVSORT*/
+               if (!host.h_name) {
+                       n = strlen(qname) + 1;  /* for the \0 */
+                       if (n > buflen || n >= MAXHOSTNAMELEN)
+                               goto no_recovery;
+                       strcpy(bp, qname);
+                       host.h_name = bp;
+                       bp += n;
+                       buflen -= n;
+               }
+               if (_res.options & RES_USE_INET6)
+                       map_v4v6_hostent(&host, &bp, &buflen);
+#ifndef WINNT
+                      h_errno = NETDB_SUCCESS;
+#else
+                      WSASetLastError(NETDB_SUCCESS);
+#endif
+               return (&host);
+       }
+ no_recovery:
+#ifndef WINNT
+               h_errno = NO_RECOVERY;
+#else
+               WSASetLastError(NO_RECOVERY);
+#endif
+       return (NULL);
+}
+
+
+struct hostent *
+gethostbyname2(name, af)
+       const char *name;
+       int af;
+{
+       querybuf buf;
+       register const char *cp;
+       char *bp;
+       int n, size, type, len;
+       extern struct hostent *_gethtbyname2();
+
+       if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+#ifndef WINNT
+               h_errno = NETDB_INTERNAL;
+#else
+               WSASetLastError(NETDB_INTERNAL);
+#endif
+               return (NULL);
+       }
+
+       switch (af) {
+       case AF_INET:
+               size = INADDRSZ;
+               type = T_A;
+               break;
+       case AF_INET6:
+               size = IN6ADDRSZ;
+               type = T_AAAA;
+               break;
+       default:
+#ifndef WINNT
+               h_errno = NETDB_INTERNAL;
+               errno = EAFNOSUPPORT;
+#else
+               WSASetLastError(NETDB_INTERNAL);
+               SetLastError(WSAEAFNOSUPPORT);
+#endif
+               return (NULL);
+       }
+
+       host.h_addrtype = af;
+       host.h_length = size;
+
+       /*
+        * if there aren't any dots, it could be a user-level alias.
+        * this is also done in res_query() since we are not the only
+        * function that looks up host names.
+        */
+       if (!strchr(name, '.') && (cp = __hostalias(name)))
+               name = cp;
+
+       /*
+        * disallow names consisting only of digits/dots, unless
+        * they end in a dot.
+        */
+       if (isdigit(name[0]))
+               for (cp = name;; ++cp) {
+                       if (!*cp) {
+                               if (*--cp == '.')
+                                       break;
+                               /*
+                                * All-numeric, no dot at the end.
+                                * Fake up a hostent as if we'd actually
+                                * done a lookup.
+                                */
+                               if (inet_pton(af, name, host_addr) <= 0) {
+#ifndef WINNT
+                                       h_errno = HOST_NOT_FOUND;
+#else
+                                        WSASetLastError(HOST_NOT_FOUND);
+#endif
+                                       return (NULL);
+                               }
+                               strncpy(hostbuf, name, MAXDNAME);
+                               hostbuf[MAXDNAME] = '\0';
+                               bp = hostbuf + MAXDNAME;
+                               len = sizeof hostbuf - MAXDNAME;
+                               host.h_name = hostbuf;
+                               host.h_aliases = host_aliases;
+                               host_aliases[0] = NULL;
+                               h_addr_ptrs[0] = (char *)host_addr;
+                               h_addr_ptrs[1] = NULL;
+                               host.h_addr_list = h_addr_ptrs;
+                               if (_res.options & RES_USE_INET6)
+                                       map_v4v6_hostent(&host, &bp, &len);
+#ifndef WINNT
+                                h_errno = NETDB_SUCCESS;
+#else
+                                WSASetLastError(NETDB_SUCCESS);
+#endif
+                               return (&host);
+                       }
+                       if (!isdigit(*cp) && *cp != '.') 
+                               break;
+               }
+       if ((isxdigit(name[0]) && strchr(name, ':') != NULL) ||
+           name[0] == ':')
+               for (cp = name;; ++cp) {
+                       if (!*cp) {
+                               if (*--cp == '.')
+                                       break;
+                               /*
+                                * All-IPv6-legal, no dot at the end.
+                                * Fake up a hostent as if we'd actually
+                                * done a lookup.
+                                */
+                               if (inet_pton(af, name, host_addr) <= 0) {
+#ifndef WINNT
+                                       h_errno = HOST_NOT_FOUND;
+#else
+                                        WSASetLastError(HOST_NOT_FOUND);
+#endif
+                                       return (NULL);
+                               }
+                               strncpy(hostbuf, name, MAXDNAME);
+                               hostbuf[MAXDNAME] = '\0';
+                               bp = hostbuf + MAXDNAME;
+                               len = sizeof hostbuf - MAXDNAME;
+                               host.h_name = hostbuf;
+                               host.h_aliases = host_aliases;
+                               host_aliases[0] = NULL;
+                               h_addr_ptrs[0] = (char *)host_addr;
+                               h_addr_ptrs[1] = NULL;
+                               host.h_addr_list = h_addr_ptrs;
+#ifndef WINNT
+                               h_errno = NETDB_SUCCESS;
+#else
+                               WSASetLastError(NETDB_SUCCESS);
+#endif
+                               return (&host);
+                       }
+                       if (!isxdigit(*cp) && *cp != ':' && *cp != '.') 
+                               break;
+               }
+
+       if ((n = res_search(name, C_IN, type, buf.buf, sizeof(buf))) < 0) {
+               dprintf("res_search failed (%d)\n", n);
+               if (errno == ECONNREFUSED)
+                       return (_gethtbyname2(name, af));
+               return (NULL);
+       }
+       return (getanswer(&buf, n, name, type));
+}
+
+struct hostent *
+#ifndef WINNT
+gethostbyname(name)
+#else
+gethostbyname_nt(name)
+#endif
+       const char *name;
+{
+       struct hostent *hp;
+
+       if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+#ifndef WINNT
+               h_errno = NETDB_INTERNAL;
+#else
+               WSASetLastError(NETDB_INTERNAL);
+#endif
+               return (NULL);
+       }
+       if (_res.options & RES_USE_INET6) {
+               hp = gethostbyname2(name, AF_INET6);
+               if (hp)
+                       return (hp);
+       }
+       return (gethostbyname2(name, AF_INET));
+}
+
+struct hostent *
+#ifndef WINNT
+gethostbyaddr(addr, len, af)
+#else
+gethostbyaddr_nt(addr, len, af)
+#endif
+       const char *addr;       /* XXX should have been def'd as u_char! */
+       int len, af;
+{
+       const u_char *uaddr = (const u_char *)addr;
+       static const u_char mapped[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0xff,0xff };
+       static const u_char tunnelled[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0,0 };
+       int n, size;
+       querybuf buf;
+       register struct hostent *hp;
+       char qbuf[MAXDNAME+1], *qp;
+#ifdef SUNSECURITY
+       register struct hostent *rhp;
+       char **haddr;
+       u_long old_options;
+       char hname2[MAXDNAME+1];
+#endif /*SUNSECURITY*/
+extern struct hostent *_gethtbyaddr();
+       
+       if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+#ifndef WINNT
+               h_errno = NETDB_INTERNAL;
+#else
+               WSASetLastError(NETDB_INTERNAL);
+#endif
+               return (0);
+       }
+       if (af == AF_INET6 && len == IN6ADDRSZ &&
+           (!bcmp(uaddr, mapped, sizeof mapped) ||
+            !bcmp(uaddr, tunnelled, sizeof tunnelled))) {
+               /* Unmap. */
+               addr += sizeof mapped;
+               uaddr += sizeof mapped;
+               af = AF_INET;
+               len = INADDRSZ;
+       }
+       switch (af) {
+       case AF_INET:
+               size = INADDRSZ;
+               break;
+       case AF_INET6:
+               size = IN6ADDRSZ;
+               break;
+       default:
+#ifndef WINNT
+               errno = EAFNOSUPPORT;
+               h_errno = NETDB_INTERNAL;
+#else
+               SetLastError(WSAEAFNOSUPPORT);
+               WSASetLastError(NETDB_INTERNAL);
+#endif
+               return (0);
+       }
+       if (size != len) {
+#ifndef WINNT
+               errno = EINVAL;
+               h_errno = NETDB_INTERNAL;
+#else
+               SetLastError(WSAEINVAL);
+               WSASetLastError(NETDB_INTERNAL);
+#endif
+               return (0);
+       }
+       switch (af) {
+       case AF_INET:
+               (void) sprintf(qbuf, "%u.%u.%u.%u.in-addr.arpa",
+                              (uaddr[3] & 0xff),
+                              (uaddr[2] & 0xff),
+                              (uaddr[1] & 0xff),
+                              (uaddr[0] & 0xff));
+               break;
+       case AF_INET6:
+               qp = qbuf;
+               for (n = IN6ADDRSZ - 1; n >= 0; n--) {
+                       qp += SPRINTF((qp, "%x.%x.",
+                                      uaddr[n] & 0xf,
+                                      (uaddr[n] >> 4) & 0xf));
+               }
+               strcpy(qp, "ip6.int");
+               break;
+       default:
+               abort();
+       }
+       n = res_query(qbuf, C_IN, T_PTR, (u_char *)buf.buf, sizeof buf.buf);
+       if (n < 0) {
+               dprintf("res_query failed (%d)\n", n);
+               if (errno == ECONNREFUSED)
+                       return (_gethtbyaddr(addr, len, af));
+               return (0);
+       }
+       if (!(hp = getanswer(&buf, n, qbuf, T_PTR)))
+               return (0);     /* h_errno was set by getanswer() */
+#ifdef SUNSECURITY
+       if (af == AF_INET) {
+           /*
+            * turn off search as the name should be absolute,
+            * 'localhost' should be matched by defnames
+            */
+           strncpy(hname2, hp->h_name, MAXDNAME);
+           hname2[MAXDNAME] = '\0';
+           old_options = _res.options;
+           _res.options &= ~RES_DNSRCH;
+           _res.options |= RES_DEFNAMES;
+           if (!(rhp = gethostbyname_nt(hname2))) {
+               syslog(LOG_NOTICE|LOG_AUTH,
+                      "gethostbyaddr: No A record for %s (verifying [%s])",
+                      hname2, inet_ntoa(*((struct in_addr *)addr)));
+               _res.options = old_options;
+#ifndef WINNT
+                   h_errno = HOST_NOT_FOUND;
+#else
+                    WSASetLastError(HOST_NOT_FOUND);
+#endif
+               return (NULL);
+           }
+           _res.options = old_options;
+           for (haddr = rhp->h_addr_list; *haddr; haddr++)
+               if (!memcmp(*haddr, addr, INADDRSZ))
+                       break;
+           if (!*haddr) {
+               syslog(LOG_NOTICE|LOG_AUTH,
+                      "gethostbyaddr: A record of %s != PTR record [%s]",
+                      hname2, inet_ntoa(*((struct in_addr *)addr)));
+#ifndef WINNT
+                   h_errno = HOST_NOT_FOUND;
+#else
+                    WSASetLastError(HOST_NOT_FOUND);
+#endif
+               return (NULL);
+           }
+       }
+#endif /*SUNSECURITY*/
+       hp->h_addrtype = af;
+       hp->h_length = len;
+       bcopy(addr, host_addr, len);
+       h_addr_ptrs[0] = (char *)host_addr;
+       h_addr_ptrs[1] = NULL;
+       if (af == AF_INET && (_res.options & RES_USE_INET6)) {
+               map_v4v6_address((char*)host_addr, (char*)host_addr);
+               hp->h_addrtype = AF_INET6;
+               hp->h_length = IN6ADDRSZ;
+       }
+#ifndef WINNT
+                      h_errno = NETDB_SUCCESS;
+#else
+                      WSASetLastError(NETDB_SUCCESS);
+#endif
+       return (hp);
+}
+
+void
+_sethtent(f)
+       int f;
+{
+    
+#ifndef WINNT
+       if (!hostf)
+               hostf = fopen(_PATH_HOSTS, "r" );
+#else
+        if (!res_paths_initialized)
+          init_res_paths();
+
+       if (!hostf)
+               hostf = fopen(pathhosts, "r" );
+#endif
+
+       else
+               rewind(hostf);
+       stayopen = f;
+}
+
+void
+_endhtent()
+{
+       if (hostf && !stayopen) {
+               (void) fclose(hostf);
+               hostf = NULL;
+       }
+}
+
+struct hostent *
+_gethtent()
+{
+       char *p;
+       register char *cp, **q;
+       int af, len;
+
+#ifndef WINNT
+       if (!hostf && !(hostf = fopen(_PATH_HOSTS, "r" ))) {
+#else
+        if (!res_paths_initialized)
+           init_res_paths();
+       if (!hostf && !(hostf = fopen(pathhosts, "r" ))) {
+#endif
+#ifndef WINNT
+               h_errno = NETDB_INTERNAL;
+#else
+               WSASetLastError(NETDB_INTERNAL);
+#endif
+               return (NULL);
+       }
+ again:
+       if (!(p = fgets(hostbuf, sizeof hostbuf, hostf))) {
+#ifndef WINNT
+                   h_errno = HOST_NOT_FOUND;
+#else
+                    WSASetLastError(HOST_NOT_FOUND);
+#endif
+               return (NULL);
+       }
+       if (*p == '#')
+               goto again;
+       if (!(cp = strpbrk(p, "#\n")))
+               goto again;
+       *cp = '\0';
+       if (!(cp = strpbrk(p, " \t")))
+               goto again;
+       *cp++ = '\0';
+       if (inet_pton(AF_INET6, p, host_addr) > 0) {
+               af = AF_INET6;
+               len = IN6ADDRSZ;
+       } else if (inet_pton(AF_INET, p, host_addr) > 0) {
+               if (_res.options & RES_USE_INET6) {
+                       map_v4v6_address((char*)host_addr, (char*)host_addr);
+                       af = AF_INET6;
+                       len = IN6ADDRSZ;
+               } else {
+                       af = AF_INET;
+                       len = INADDRSZ;
+               }
+       } else {
+               goto again;
+       }
+       h_addr_ptrs[0] = (char *)host_addr;
+       h_addr_ptrs[1] = NULL;
+       host.h_addr_list = h_addr_ptrs;
+       host.h_length = len;
+       host.h_addrtype = af;
+       while (*cp == ' ' || *cp == '\t')
+               cp++;
+       host.h_name = cp;
+       q = host.h_aliases = host_aliases;
+       if (cp = strpbrk(cp, " \t"))
+               *cp++ = '\0';
+       while (cp && *cp) {
+               if (*cp == ' ' || *cp == '\t') {
+                       cp++;
+                       continue;
+               }
+               if (q < &host_aliases[MAXALIASES - 1])
+                       *q++ = cp;
+               if (cp = strpbrk(cp, " \t"))
+                       *cp++ = '\0';
+       }
+       *q = NULL;
+#ifndef WINNT
+                      h_errno = NETDB_SUCCESS;
+#else
+                      WSASetLastError(NETDB_SUCCESS);
+#endif
+       return (&host);
+}
+
+struct hostent *
+_gethtbyname(name)
+       const char *name;
+{
+       extern struct hostent *_gethtbyname2();
+       struct hostent *hp;
+
+       if (_res.options & RES_USE_INET6) {
+               hp = _gethtbyname2(name, AF_INET6);
+               if (hp)
+                       return (hp);
+       }
+       return (_gethtbyname2(name, AF_INET));
+}
+
+struct hostent *
+_gethtbyname2(name, af)
+       const char *name;
+       int af;
+{
+       register struct hostent *p;
+       register char **cp;
+       
+       _sethtent(0);
+       while (p = _gethtent()) {
+               if (p->h_addrtype != af)
+                       continue;
+               if (strcasecmp(p->h_name, name) == 0)
+                       break;
+               for (cp = p->h_aliases; *cp != 0; cp++)
+                       if (strcasecmp(*cp, name) == 0)
+                               goto found;
+       }
+ found:
+       _endhtent();
+       return (p);
+}
+
+struct hostent *
+_gethtbyaddr(addr, len, af)
+       const char *addr;
+       int len, af;
+{
+       register struct hostent *p;
+
+       _sethtent(0);
+       while (p = _gethtent())
+               if (p->h_addrtype == af && !bcmp(p->h_addr, addr, len))
+                       break;
+       _endhtent();
+       return (p);
+}
+
+static void
+map_v4v6_address(src, dst)
+       const char *src;
+       char *dst;
+{
+       u_char *p = (u_char *)dst;
+       char tmp[INADDRSZ];
+       int i;
+
+       /* Stash a temporary copy so our caller can update in place. */
+       bcopy(src, tmp, INADDRSZ);
+       /* Mark this ipv6 addr as a mapped ipv4. */
+       for (i = 0; i < 10; i++)
+               *p++ = 0x00;
+       *p++ = 0xff;
+       *p++ = 0xff;
+       /* Retrieve the saved copy and we're done. */
+       bcopy(tmp, (void*)p, INADDRSZ);
+}
+
+static void
+map_v4v6_hostent(hp, bpp, lenp)
+       struct hostent *hp;
+       char **bpp;
+       int *lenp;
+{
+       char **ap;
+
+       if (hp->h_addrtype != AF_INET || hp->h_length != INADDRSZ)
+               return;
+       hp->h_addrtype = AF_INET6;
+       hp->h_length = IN6ADDRSZ;
+       for (ap = hp->h_addr_list; *ap; ap++) {
+               int i = sizeof(align) - ((u_long)*bpp % sizeof(align));
+
+               if (*lenp < (i + IN6ADDRSZ)) {
+                       /* Out of memory.  Truncate address list here.  XXX */
+                       *ap = NULL;
+                       return;
+               }
+               *bpp += i;
+               *lenp -= i;
+               map_v4v6_address(*ap, *bpp);
+               *ap = *bpp;
+               *bpp += IN6ADDRSZ;
+               *lenp -= IN6ADDRSZ;
+       }
+}
+
+#ifdef RESOLVSORT
+static void
+addrsort(ap, num)
+       char **ap;
+       int num;
+{
+       int i, j;
+       char **p;
+       short aval[MAXADDRS];
+       int needsort = 0;
+
+       p = ap;
+       for (i = 0; i < num; i++, p++) {
+           for (j = 0 ; (unsigned)j < _res.nsort; j++)
+               if (_res.sort_list[j].addr.s_addr == 
+                   (((struct in_addr *)(*p))->s_addr & _res.sort_list[j].mask))
+                       break;
+           aval[i] = j;
+           if (needsort == 0 && i > 0 && j < aval[i-1])
+               needsort = i;
+       }
+       if (!needsort)
+           return;
+
+       while (needsort < num) {
+           for (j = needsort - 1; j >= 0; j--) {
+               if (aval[j] > aval[j+1]) {
+                   char *hp;
+
+                   i = aval[j];
+                   aval[j] = aval[j+1];
+                   aval[j+1] = i;
+
+                   hp = ap[j];
+                   ap[j] = ap[j+1];
+                   ap[j+1] = hp;
+
+               } else
+                   break;
+           }
+           needsort++;
+       }
+}
+#endif
+
+#if defined(BSD43_BSD43_NFS) || defined(sun)
+/* some libc's out there are bound internally to these names (UMIPS) */
+void
+ht_sethostent(stayopen)
+       int stayopen;
+{
+       _sethtent(stayopen);
+}
+
+void
+ht_endhostent()
+{
+       _endhtent();
+}
+
+struct hostent *
+ht_gethostbyname(name)
+       char *name;
+{
+       return (_gethtbyname(name));
+}
+
+struct hostent *
+ht_gethostbyaddr(addr, len, af)
+       const char *addr;
+       int len, af;
+{
+       return (_gethtbyaddr(addr, len, af));
+}
+
+struct hostent *
+gethostent()
+{
+       return (_gethtent());
+}
+
+void
+dns_service()
+{
+       return;
+}
+
+#undef dn_skipname
+dn_skipname(comp_dn, eom)
+       const u_char *comp_dn, *eom;
+{
+       return (__dn_skipname(comp_dn, eom));
+}
+#endif /*old-style libc with yp junk in it*/
diff --git a/bindlib_w32/getnetbyaddr.c b/bindlib_w32/getnetbyaddr.c
new file mode 100644 (file)
index 0000000..33ec7db
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 1983 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)getnetbyaddr.c     1.1 (Coimbra) 93/06/02";
+static char rcsid[] = "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+#include <netdb.h>
+#ifdef WINNT
+#include "conf/portability.h"
+#endif
+
+extern int _net_stayopen;
+
+struct netent *
+_getnetbyaddr(net, type)
+       register unsigned long net;
+       register int type;
+{
+       register struct netent *p;
+
+       setnetent(_net_stayopen);
+       while (p = getnetent())
+               if (p->n_addrtype == type && p->n_net == net)
+                       break;
+       if (!_net_stayopen)
+               endnetent();
+       return (p);
+}
diff --git a/bindlib_w32/getnetbyname.c b/bindlib_w32/getnetbyname.c
new file mode 100644 (file)
index 0000000..a547479
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 1983, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)getnetbyname.c     8.1 (Berkeley) 6/4/93";
+static char sccsid_[] = "from getnetbyname.c   1.1 (Coimbra) 93/06/02";
+static char rcsid[] = "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+#include <netdb.h>
+#include <string.h>
+#ifdef WINNT
+#include "conf/portability.h"
+#endif
+
+extern int _net_stayopen;
+
+struct netent *
+_getnetbyname(name)
+       register const char *name;
+{
+       register struct netent *p;
+       register char **cp;
+
+       setnetent(_net_stayopen);
+       while (p = getnetent()) {
+               if (strcasecmp(p->n_name, name) == 0)
+                       break;
+               for (cp = p->n_aliases; *cp != 0; cp++)
+                       if (strcasecmp(*cp, name) == 0)
+                               goto found;
+       }
+found:
+       if (!_net_stayopen)
+               endnetent();
+       return (p);
+}
diff --git a/bindlib_w32/getnetent.c b/bindlib_w32/getnetent.c
new file mode 100644 (file)
index 0000000..e562848
--- /dev/null
@@ -0,0 +1,189 @@
+/*
+ * Copyright (c) 1983 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/* Portions Copyright (c) 1993 Carlos Leandro and Rui Salgueiro
+ *     Dep. Matematica Universidade de Coimbra, Portugal, Europe
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * from getnetent.c    1.1 (Coimbra) 93/06/02
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)getnetent.c        8.1 (Berkeley) 6/4/93";
+static char rcsid[] = "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#ifndef WINNT
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#endif
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+
+#include <stdio.h>
+#include <resolv.h>
+#include <netdb.h>
+#include <string.h>
+#ifdef WINNT
+#include "conf/portability.h"
+extern char *pathnetworks;
+extern int res_paths_initialized;
+extern init_res_paths();
+#endif
+
+#ifndef _PATH_NETWORKS 
+#define _PATH_NETWORKS  "/etc/networks"
+#endif
+
+
+
+#define        MAXALIASES      35
+
+static FILE *netf;
+static char line[BUFSIZ+1];
+static struct netent net;
+static char *net_aliases[MAXALIASES];
+int _net_stayopen;
+
+void _setnetent __P((int));
+void _endnetent __P((void));
+
+void
+setnetent(stayopen)
+       int stayopen;
+{
+
+       sethostent(stayopen);
+       _setnetent(stayopen);
+}
+
+void
+endnetent()
+{
+
+       endhostent();
+       _endnetent();
+}
+
+void
+_setnetent(f)
+       int f;
+{
+
+#ifndef WINNT
+       if (netf == NULL)
+               netf = fopen(_PATH_NETWORKS, "r" );
+#else
+       if (!res_paths_initialized)
+         init_res_paths();
+
+       if (netf == NULL)
+               netf = fopen(pathnetworks, "r" );
+#endif
+       else
+               rewind(netf);
+       _net_stayopen |= f;
+}
+
+void
+_endnetent()
+{
+
+       if (netf) {
+               fclose(netf);
+               netf = NULL;
+       }
+       _net_stayopen = 0;
+}
+
+struct netent *
+getnetent()
+{
+       char *p;
+       register char *cp, **q;
+
+#ifndef WINNT
+       if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "r" )) == NULL)
+#else
+       if (!res_paths_initialized)
+         init_res_paths();
+
+       if (netf == NULL && (netf = fopen(pathnetworks, "r" )) == NULL)
+#endif
+
+               return (NULL);
+again:
+       p = fgets(line, sizeof line, netf);
+       if (p == NULL)
+               return (NULL);
+       if (*p == '#')
+               goto again;
+       cp = strpbrk(p, "#\n");
+       if (cp == NULL)
+               goto again;
+       *cp = '\0';
+       net.n_name = p;
+       cp = strpbrk(p, " \t");
+       if (cp == NULL)
+               goto again;
+       *cp++ = '\0';
+       while (*cp == ' ' || *cp == '\t')
+               cp++;
+       p = strpbrk(cp, " \t");
+       if (p != NULL)
+               *p++ = '\0';
+       net.n_net = inet_network(cp);
+       net.n_addrtype = AF_INET;
+       q = net.n_aliases = net_aliases;
+       if (p != NULL) {
+               cp = p;
+               while (cp && *cp) {
+                       if (*cp == ' ' || *cp == '\t') {
+                               cp++;
+                               continue;
+                       }
+                       if (q < &net_aliases[MAXALIASES - 1])
+                               *q++ = cp;
+                       cp = strpbrk(cp, " \t");
+                       if (cp != NULL)
+                               *cp++ = '\0';
+               }
+       }
+       *q = NULL;
+       return (&net);
+}
diff --git a/bindlib_w32/getnetnamadr.c b/bindlib_w32/getnetnamadr.c
new file mode 100644 (file)
index 0000000..7653675
--- /dev/null
@@ -0,0 +1,310 @@
+/* Copyright (c) 1993 Carlos Leandro and Rui Salgueiro
+ *     Dep. Matematica Universidade de Coimbra, Portugal, Europe
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ */
+/*
+ * Copyright (c) 1983, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)getnetbyaddr.c     8.1 (Berkeley) 6/4/93";
+static char sccsid_[] = "from getnetnamadr.c   1.4 (Coimbra) 93/06/03";
+static char rcsid[] = "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#ifndef WINNT
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#endif
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+
+#include <stdio.h>
+#include <netdb.h>
+#include <resolv.h>
+#include <ctype.h>
+#include <errno.h>
+#include <string.h>
+
+#ifndef WINNT
+extern int h_errno;
+#else
+#include "conf/portability.h"
+#endif
+
+#if defined(mips) && defined(SYSTYPE_BSD43)
+extern int errno;
+#endif
+
+struct netent *_getnetbyaddr __P((u_long net, int type));
+struct netent *_getnetbyname __P((const char *name));
+
+#define BYADDR 0
+#define BYNAME 1
+#define        MAXALIASES      35
+
+#if PACKETSZ > 1024
+#define        MAXPACKET       PACKETSZ
+#else
+#define        MAXPACKET       1024
+#endif
+
+typedef union {
+       HEADER  hdr;
+       u_char  buf[MAXPACKET];
+} querybuf;
+
+typedef union {
+       long    al;
+       char    ac;
+} align;
+
+static struct netent *
+getnetanswer(answer, anslen, net_i)
+       querybuf *answer;
+       int anslen;
+       int net_i;
+{
+
+       register HEADER *hp;
+       register u_char *cp;
+       register int n;
+       u_char *eom;
+       int type, class, buflen, ancount, qdcount, haveanswer, i, nchar;
+       char aux1[30], aux2[30], ans[30], *in, *st, *pauxt, *bp, **ap,
+               *paux1 = &aux1[0], *paux2 = &aux2[0], flag = 0;
+static struct netent net_entry;
+static char *net_aliases[MAXALIASES], netbuf[PACKETSZ];
+
+       /*
+        * find first satisfactory answer
+        *
+        *      answer --> +------------+  ( MESSAGE )
+        *                 |   Header   |
+        *                 +------------+
+        *                 |  Question  | the question for the name server
+        *                 +------------+
+        *                 |   Answer   | RRs answering the question
+        *                 +------------+
+        *                 | Authority  | RRs pointing toward an authority
+        *                 | Additional | RRs holding additional information
+        *                 +------------+
+        */
+       eom = answer->buf + anslen;
+       hp = &answer->hdr;
+       ancount = ntohs( (u_short) hp->ancount); /* #/records in the answer section */
+       qdcount = ntohs( (u_short) hp->qdcount); /* #/entries in the question section */
+       bp = netbuf;
+       buflen = sizeof(netbuf);
+       cp = answer->buf + HFIXEDSZ;
+       if (!qdcount) {
+               if (hp->aa)
+#ifndef WINNT
+                       h_errno = HOST_NOT_FOUND;
+#else
+                       WSASetLastError(HOST_NOT_FOUND);
+#endif
+               else
+#ifndef WINNT
+                       h_errno = TRY_AGAIN;
+#else
+                       WSASetLastError(HOST_NOT_FOUND);
+#endif
+               return (NULL);
+       }
+       while (qdcount-- > 0)
+               cp += __dn_skipname(cp, eom) + QFIXEDSZ;
+       ap = net_aliases;
+       *ap = NULL;
+       net_entry.n_aliases = net_aliases;
+       haveanswer = 0;
+       while (--ancount >= 0 && cp < eom) {
+               n = dn_expand(answer->buf, eom, cp, bp, buflen);
+               if ((n < 0) || !res_dnok(bp))
+                       break;
+               cp += n;
+               ans[0] = '\0';
+               (void)strcpy(&ans[0], bp);
+               GETSHORT(type, cp);
+               GETSHORT(class, cp);
+               cp += INT32SZ;          /* TTL */
+               GETSHORT(n, cp);
+               if (class == C_IN && type == T_PTR) {
+                       n = dn_expand(answer->buf, eom, cp, bp, buflen);
+                       if ((n < 0) || !res_hnok(bp)) {
+                               cp += n;
+                               return (NULL);
+                       }
+                       cp += n; 
+                       *ap++ = bp;
+                       bp += strlen(bp) + 1;
+                       net_entry.n_addrtype =
+                               (class == C_IN) ? AF_INET : AF_UNSPEC;
+                       haveanswer++;
+               }
+       }
+       if (haveanswer) {
+               *ap = NULL;
+               switch (net_i) {
+               case BYADDR:
+                       net_entry.n_name = *net_entry.n_aliases;
+                       net_entry.n_net = 0L;
+                       break;
+               case BYNAME:
+                       in = *net_entry.n_aliases;
+                       net_entry.n_name = &ans[0];
+                       aux2[0] = '\0';
+                       for (i = 0; i < 4; i++) {
+                               for (st = in, nchar = 0;
+                                    *st != '.';
+                                    st++, nchar++)
+                                       ;
+                               if (nchar != 1 || *in != '0' || flag) {
+                                       flag = 1;
+                                       (void)strncpy(paux1,
+                                                     (i==0) ? in : in-1,
+                                                     (i==0) ?nchar : nchar+1);
+                                       paux1[(i==0) ? nchar : nchar+1] = '\0';
+                                       pauxt = paux2;
+                                       paux2 = strcat(paux1, paux2);
+                                       paux1 = pauxt;
+                               }
+                               in = ++st;
+                       }                 
+                       net_entry.n_net = inet_network(paux2);
+                       break;
+               }
+               net_entry.n_aliases++;
+               return (&net_entry);
+       }
+#ifndef WINNT
+       h_errno = TRY_AGAIN;
+#else
+       WSASetLastError(TRY_AGAIN);
+#endif
+       return (NULL);
+}
+
+struct netent *
+getnetbyaddr(net, net_type)
+       register u_long net;
+       register int net_type;
+{
+       unsigned int netbr[4];
+       int nn, anslen;
+       querybuf buf;
+       char qbuf[MAXDNAME];
+       unsigned long net2;
+       struct netent *net_entry;
+
+       if (net_type != AF_INET)
+               return (_getnetbyaddr(net, net_type));
+
+       for (nn = 4, net2 = net; net2; net2 >>= 8)
+               netbr[--nn] = net2 & 0xff;
+       switch (nn) {
+       case 3:         /* Class A */
+               sprintf(qbuf, "0.0.0.%u.in-addr.arpa", netbr[3]);
+               break;
+       case 2:         /* Class B */
+               sprintf(qbuf, "0.0.%u.%u.in-addr.arpa", netbr[3], netbr[2]);
+               break;
+       case 1:         /* Class C */
+               sprintf(qbuf, "0.%u.%u.%u.in-addr.arpa", netbr[3], netbr[2],
+                   netbr[1]);
+               break;
+       case 0:         /* Class D - E */
+               sprintf(qbuf, "%u.%u.%u.%u.in-addr.arpa", netbr[3], netbr[2],
+                   netbr[1], netbr[0]);
+               break;
+       }
+       anslen = res_query(qbuf, C_IN, T_PTR, (u_char *)&buf, sizeof(buf));
+       if (anslen < 0) {
+#ifdef DEBUG
+               if (_res.options & RES_DEBUG)
+                       printf("res_query failed\n");
+#endif
+               if (errno == ECONNREFUSED)
+                       return (_getnetbyaddr(net, net_type));
+               return (NULL);
+       }
+       net_entry = getnetanswer(&buf, anslen, BYADDR);
+       if (net_entry) {
+               unsigned u_net = net;   /* maybe net should be unsigned ? */
+
+               /* Strip trailing zeros */
+               while ((u_net & 0xff) == 0 && u_net != 0)
+                       u_net >>= 8;
+               net_entry->n_net = u_net;
+               return (net_entry);
+       }
+       return (_getnetbyaddr(net, net_type));
+}
+
+struct netent *
+getnetbyname(net)
+       register const char *net;
+{
+       int anslen;
+       querybuf buf;
+       char qbuf[MAXDNAME];
+       struct netent *net_entry;
+
+       if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+#ifndef WINNT
+               h_errno = NETDB_INTERNAL;
+#else
+               WSASetLastError(NETDB_INTERNAL);
+#endif
+               return (NULL);
+       }
+       strcpy(&qbuf[0], net);
+       anslen = res_search(qbuf, C_IN, T_PTR, (u_char *)&buf, sizeof(buf));
+       if (anslen < 0) {
+#ifdef DEBUG
+               if (_res.options & RES_DEBUG)
+                       printf("res_query failed\n");
+#endif
+               if (errno == ECONNREFUSED)
+                       return (_getnetbyname(net));
+               return (_getnetbyname(net));
+       }
+       net_entry = getnetanswer(&buf, anslen, BYNAME);
+       if (net_entry)
+               return (net_entry);
+       return (_getnetbyname(net));
+}
diff --git a/bindlib_w32/herror.c b/bindlib_w32/herror.c
new file mode 100644 (file)
index 0000000..2cfb266
--- /dev/null
@@ -0,0 +1,134 @@
+/*
+ * ++Copyright++ 1987, 1993
+ * -
+ * Copyright (c) 1987, 1993
+ *    The Regents of the University of California.  All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ * 
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)herror.c   8.1 (Berkeley) 6/4/93";
+static char rcsid[] = "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#ifndef WINNT
+#include <sys/param.h>
+#include <sys/uio.h>
+#endif
+#include <netdb.h>
+#if defined(BSD) && (BSD >= 199103)
+# include <unistd.h>
+# include <string.h>
+#else
+# include "conf/portability.h"
+#endif
+
+const char *h_errlist[] = {
+       "Resolver Error 0 (no error)",
+       "Unknown host",                         /* 1 HOST_NOT_FOUND */
+       "Host name lookup failure",             /* 2 TRY_AGAIN */
+       "Unknown server error",                 /* 3 NO_RECOVERY */
+       "No address associated with name",      /* 4 NO_ADDRESS */
+};
+int    h_nerr = { sizeof h_errlist / sizeof h_errlist[0] };
+
+#ifndef WINNT
+extern int     h_errno;
+#endif
+
+/*
+ * herror --
+ *     print the error indicated by the h_errno value.
+ */
+void
+herror(s)
+       const char *s;
+{
+       struct iovec iov[4];
+       register struct iovec *v = iov;
+#ifdef WINNT
+       char err[50];
+#endif
+
+       if (s && *s) {
+               v->iov_base = (char *)s;
+               v->iov_len = strlen(s);
+               v++;
+               v->iov_base = ": ";
+               v->iov_len = 2;
+               v++;
+       }
+#ifndef WINNT
+       v->iov_base = (char *)hstrerror(h_errno);
+#else
+       /* XXX - map the error number to the corresponding message here */
+       sprintf(err, "%d", h_errno);
+       v->iov_base = err;
+#endif
+       v->iov_len = strlen(v->iov_base);
+       v++;
+       v->iov_base = "\n";
+       v->iov_len = 1;
+       writev(STDERR_FILENO, iov, (v - iov) + 1);
+}
+
+#ifndef WINNT
+const char *
+hstrerror(err)
+       int err;
+{
+       if (err < 0)
+               return ("Resolver internal error");
+       else if (err < h_nerr)
+               return (h_errlist[err]);
+       return ("Unknown resolver error");
+}
+#endif
diff --git a/bindlib_w32/hostnamelen.c b/bindlib_w32/hostnamelen.c
new file mode 100644 (file)
index 0000000..69031b1
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * ++Copyright++ 1995
+ * -
+ * Copyright (c) 1995
+ *    The Regents of the University of California.  All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ * 
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char rcsid[] = "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+#ifndef WINNT
+#include <sys/param.h>
+#include <sys/types.h>
+#include <netinet/in.h>
+#endif
+
+#include <arpa/nameser.h>
+#include <resolv.h>
+
+#if defined(BSD) && (BSD >= 199103)
+# include <string.h>
+#else
+# include "conf/portability.h"
+#endif
+#if defined(USE_OPTIONS_H)
+# include <conf/options.h>
+#endif
+
+#ifndef ultrix
+int __local_hostname_length_unneeded;
+#else
+int
+local_hostname_length(hostname)
+       const char *hostname;
+{
+       int len_host, len_domain;
+
+       if (!*_res.defdname)
+               res_init();
+       len_host = strlen(hostname);
+       len_domain = strlen(_res.defdname);
+       if (len_host > len_domain &&
+           !strcasecmp(hostname + len_host - len_domain, _res.defdname) &&
+           hostname[len_host - len_domain - 1] == '.')
+               return (len_host - len_domain - 1);
+       return (0);
+}
+#endif
diff --git a/bindlib_w32/inet_addr.c b/bindlib_w32/inet_addr.c
new file mode 100644 (file)
index 0000000..bd9eddd
--- /dev/null
@@ -0,0 +1,190 @@
+/*
+ * ++Copyright++ 1983, 1990, 1993
+ * -
+ * Copyright (c) 1983, 1990, 1993
+ *    The Regents of the University of California.  All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ * 
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)inet_addr.c        8.1 (Berkeley) 6/17/93";
+static char rcsid[] = "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#ifndef WINNT
+#include <sys/param.h>
+#include <netinet/in.h>
+#endif
+#include <arpa/inet.h>
+#include <ctype.h>
+#include "conf/portability.h"
+
+#ifndef NEED_INETADDR
+int __inet_addr_unneeded__;
+#else
+/* these are compatibility routines, not needed on recent BSD releases */
+
+/*
+ * Ascii internet address interpretation routine.
+ * The value returned is in network order.
+ */
+u_long
+inet_addr(cp)
+       register const char *cp;
+{
+       struct in_addr val;
+
+       if (inet_aton(cp, &val))
+               return (val.s_addr);
+       return (INADDR_NONE);
+}
+#endif  /* NEED_INETADDR */
+
+/* 
+ * Check whether "cp" is a valid ascii representation
+ * of an Internet address and convert to a binary address.
+ * Returns 1 if the address is valid, 0 if not.
+ * This replaces inet_addr, the return value from which
+ * cannot distinguish between failure and a local broadcast address.
+ */
+int
+inet_aton(cp, addr)
+       register const char *cp;
+       struct in_addr *addr;
+{
+       register u_long val;
+       register int base, n;
+       register char c;
+       u_int parts[4];
+       register u_int *pp = parts;
+
+       c = *cp;
+       for (;;) {
+               /*
+                * Collect number up to ``.''.
+                * Values are specified as for C:
+                * 0x=hex, 0=octal, isdigit=decimal.
+                */
+               if (!isdigit(c))
+                       return (0);
+               val = 0; base = 10;
+               if (c == '0') {
+                       c = *++cp;
+                       if (c == 'x' || c == 'X')
+                               base = 16, c = *++cp;
+                       else
+                               base = 8;
+               }
+               for (;;) {
+                       if (isascii(c) && isdigit(c)) {
+                               val = (val * base) + (c - '0');
+                               c = *++cp;
+                       } else if (base == 16 && isascii(c) && isxdigit(c)) {
+                               val = (val << 4) |
+                                       (c + 10 - (islower(c) ? 'a' : 'A'));
+                               c = *++cp;
+                       } else
+                               break;
+               }
+               if (c == '.') {
+                       /*
+                        * Internet format:
+                        *      a.b.c.d
+                        *      a.b.c   (with c treated as 16 bits)
+                        *      a.b     (with b treated as 24 bits)
+                        */
+                       if (pp >= parts + 3)
+                               return (0);
+                       *pp++ = val;
+                       c = *++cp;
+               } else
+                       break;
+       }
+       /*
+        * Check for trailing characters.
+        */
+       if (c != '\0' && (!isascii(c) || !isspace(c)))
+               return (0);
+       /*
+        * Concoct the address according to
+        * the number of parts specified.
+        */
+       n = pp - parts + 1;
+       switch (n) {
+
+       case 0:
+               return (0);             /* initial nondigit */
+
+       case 1:                         /* a -- 32 bits */
+               break;
+
+       case 2:                         /* a.b -- 8.24 bits */
+               if (val > 0xffffff)
+                       return (0);
+               val |= parts[0] << 24;
+               break;
+
+       case 3:                         /* a.b.c -- 8.8.16 bits */
+               if (val > 0xffff)
+                       return (0);
+               val |= (parts[0] << 24) | (parts[1] << 16);
+               break;
+
+       case 4:                         /* a.b.c.d -- 8.8.8.8 bits */
+               if (val > 0xff)
+                       return (0);
+               val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
+               break;
+       }
+       if (addr)
+               addr->s_addr = htonl(val);
+       return (1);
+}
diff --git a/bindlib_w32/inet_net_ntop.c b/bindlib_w32/inet_net_ntop.c
new file mode 100644 (file)
index 0000000..d2c0993
--- /dev/null
@@ -0,0 +1,159 @@
+/*
+ * Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static const char rcsid[] = "$Id$";
+#endif
+
+#include <sys/types.h>
+#ifndef WINNT
+#include <sys/socket.h>
+#include <netinet/in.h>
+#endif
+#include <arpa/inet.h>
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#ifdef SPRINTF_CHAR
+# define SPRINTF(x) strlen(sprintf/**/x)
+#else
+# define SPRINTF(x) ((size_t)sprintf x)
+#endif
+
+static char *  inet_net_ntop_ipv4 __P((const u_char *src, int bits,
+                                       char *dst, size_t size));
+
+/*
+ * char *
+ * inet_net_ntop(af, src, bits, dst, size)
+ *     convert network number from network to presentation format.
+ *     generates CIDR style result always.
+ * return:
+ *     pointer to dst, or NULL if an error occurred (check errno).
+ * author:
+ *     Paul Vixie (ISC), July 1996
+ */
+char *
+inet_net_ntop(af, src, bits, dst, size)
+       int af;
+       const void *src;
+       int bits;
+       char *dst;
+       size_t size;
+{
+       switch (af) {
+       case AF_INET:
+               return (inet_net_ntop_ipv4(src, bits, dst, size));
+       default:
+
+#ifndef WINNT
+       errno = EAFNOSUPPORT;
+     return (NULL);
+#else
+
+       WSASetLastError(WSAEAFNOSUPPORT);
+       SetLastError(WSAEAFNOSUPPORT);
+     return (NULL);
+#endif
+
+       }
+}
+
+/*
+ * static char *
+ * inet_net_ntop_ipv4(src, bits, dst, size)
+ *     convert IPv4 network number from network to presentation format.
+ *     generates CIDR style result always.
+ * return:
+ *     pointer to dst, or NULL if an error occurred (check errno).
+ * note:
+ *     network byte order assumed.  this means 192.5.5.240/28 has
+ *     0x11110000 in its fourth octet.
+ * author:
+ *     Paul Vixie (ISC), July 1996
+ */
+static char *
+inet_net_ntop_ipv4(src, bits, dst, size)
+       const u_char *src;
+       int bits;
+       char *dst;
+       size_t size;
+{
+       char *odst = dst;
+       char *t;
+       u_int m;
+       int b;
+
+       if (bits < 0 || bits > 32) {
+               errno = EINVAL;
+               return (NULL);
+       }
+       if (bits == 0) {
+               if (size < sizeof "0")
+                       goto emsgsize;
+               *dst++ = '0';
+               *dst = '\0';
+       }
+
+       /* Format whole octets. */
+       for (b = bits / 8; b > 0; b--) {
+               if (size < sizeof "255.")
+                       goto emsgsize;
+               t = dst;
+               dst += SPRINTF((dst, "%u", *src++));
+               if (b > 1) {
+                       *dst++ = '.';
+                       *dst = '\0';
+               }
+               size -= (size_t)(dst - t);
+       }
+
+       /* Format partial octet. */
+       b = bits % 8;
+       if (b > 0) {
+               if (size < sizeof ".255")
+                       goto emsgsize;
+               t = dst;
+               if (dst != odst)
+                       *dst++ = '.';
+               m = ((1 << b) - 1) << (8 - b);
+               dst += SPRINTF((dst, "%u", *src & m));
+               size -= (size_t)(dst - t);
+       }
+
+       /* Format CIDR /width. */
+       if (size < sizeof "/32")
+               goto emsgsize;
+       dst += SPRINTF((dst, "/%u", bits));
+       return (odst);
+
+ emsgsize:
+
+ #ifndef WINNT
+     errno = EMSGSIZE;
+     return (NULL);
+#else
+     WSASetLastError(WSAEMSGSIZE);
+     SetLastError(WSAEMSGSIZE);
+     return (NULL);
+#endif
+
+
+}
diff --git a/bindlib_w32/inet_net_pton.c b/bindlib_w32/inet_net_pton.c
new file mode 100644 (file)
index 0000000..8130d81
--- /dev/null
@@ -0,0 +1,231 @@
+/*
+ * Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static const char rcsid[] = "$Id$";
+#endif
+
+#include <sys/types.h>
+#ifndef WINNT
+#include <sys/socket.h>
+#include <netinet/in.h>
+#endif
+#include <arpa/inet.h>
+
+#include <assert.h>
+#include <ctype.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#ifdef SPRINTF_CHAR
+# define SPRINTF(x) strlen(sprintf/**/x)
+#else
+# define SPRINTF(x) ((size_t)sprintf x)
+#endif
+
+static int     inet_net_pton_ipv4 __P((const char *src, u_char *dst,
+                                       size_t size));
+
+/*
+ * static int
+ * inet_net_pton(af, src, dst, size)
+ *     convert network number from presentation to network format.
+ *     accepts hex octets, hex strings, decimal octets, and /CIDR.
+ *     "size" is in bytes and describes "dst".
+ * return:
+ *     number of bits, either imputed classfully or specified with /CIDR,
+ *     or -1 if some failure occurred (check errno).  ENOENT means it was
+ *     not a valid network specification.
+ * author:
+ *     Paul Vixie (ISC), June 1996
+ */
+int
+inet_net_pton(af, src, dst, size)
+       int af;
+       const char *src;
+       void *dst;
+       size_t size;
+{
+       switch (af) {
+       case AF_INET:
+               return (inet_net_pton_ipv4(src, dst, size));
+       default:
+#ifndef WINNT
+       errno = EAFNOSUPPORT;
+     return (-1);
+#else
+
+       WSASetLastError(WSAEAFNOSUPPORT);
+       SetLastError(WSAEAFNOSUPPORT);
+     return (-1);
+#endif
+               
+       }
+}
+
+/*
+ * static int
+ * inet_net_pton_ipv4(src, dst, size)
+ *     convert IPv4 network number from presentation to network format.
+ *     accepts hex octets, hex strings, decimal octets, and /CIDR.
+ *     "size" is in bytes and describes "dst".
+ * return:
+ *     number of bits, either imputed classfully or specified with /CIDR,
+ *     or -1 if some failure occurred (check errno).  ENOENT means it was
+ *     not an IPv4 network specification.
+ * note:
+ *     network byte order assumed.  this means 192.5.5.240/28 has
+ *     0x11110000 in its fourth octet.
+ * author:
+ *     Paul Vixie (ISC), June 1996
+ */
+static int
+inet_net_pton_ipv4(src, dst, size)
+       const char *src;
+       u_char *dst;
+       size_t size;
+{
+       static const char
+               xdigits[] = "0123456789abcdef",
+               digits[] = "0123456789";
+       int n, ch, tmp, dirty, bits;
+       const u_char *odst = dst;
+
+       ch = *src++;
+       if (ch == '0' && (src[0] == 'x' || src[0] == 'X')
+           && isascii(src[1]) && isxdigit(src[1])) {
+               /* Hexadecimal: Eat nybble string. */
+               if (size <= 0)
+                       goto emsgsize;
+               *dst = 0, dirty = 0;
+               src++;  /* skip x or X. */
+               while ((ch = *src++) != '\0' &&
+                      isascii(ch) && isxdigit(ch)) {
+                       if (isupper(ch))
+                               ch = tolower(ch);
+                       n = strchr(xdigits, ch) - xdigits;
+                       assert(n >= 0 && n <= 15);
+                       *dst |= n;
+                       if (!dirty++)
+                               *dst <<= 4;
+                       else if (size-- > 0)
+                               *++dst = 0, dirty = 0;
+                       else
+                               goto emsgsize;
+               }
+               if (dirty)
+                       size--;
+       } else if (isascii(ch) && isdigit(ch)) {
+               /* Decimal: eat dotted digit string. */
+               for (;;) {
+                       tmp = 0;
+                       do {
+                               n = strchr(digits, ch) - digits;
+                               assert(n >= 0 && n <= 9);
+                               tmp *= 10;
+                               tmp += n;
+                               if (tmp > 255)
+                                       goto enoent;
+                       } while ((ch = *src++) != '\0' &&
+                                isascii(ch) && isdigit(ch));
+                       if (size-- <= 0)
+                               goto emsgsize;
+                       *dst++ = (u_char) tmp;
+                       if (ch == '\0' || ch == '/')
+                               break;
+                       if (ch != '.')
+                               goto enoent;
+                       ch = *src++;
+                       if (!isascii(ch) || !isdigit(ch))
+                               goto enoent;
+               }
+       } else
+               goto enoent;
+
+       bits = -1;
+       if (ch == '/' && isascii(src[0]) && isdigit(src[0]) && dst > odst) {
+               /* CIDR width specifier.  Nothing can follow it. */
+               ch = *src++;    /* Skip over the /. */
+               bits = 0;
+               do {
+                       n = strchr(digits, ch) - digits;
+                       assert(n >= 0 && n <= 9);
+                       bits *= 10;
+                       bits += n;
+               } while ((ch = *src++) != '\0' &&
+                        isascii(ch) && isdigit(ch));
+               if (ch != '\0')
+                       goto enoent;
+               if (bits > 32)
+                       goto emsgsize;
+       }
+
+       /* Firey death and destruction unless we prefetched EOS. */
+       if (ch != '\0')
+               goto enoent;
+
+       /* If nothing was written to the destination, we found no address. */
+       if (dst == odst)
+               goto enoent;
+       /* If no CIDR spec was given, infer width from net class. */
+       if (bits == -1) {
+               if (*odst >= 240)       /* Class E */
+                       bits = 32;
+               else if (*odst >= 224)  /* Class D */
+                       bits = 4;
+               else if (*odst >= 192)  /* Class C */
+                       bits = 24;
+               else if (*odst >= 128)  /* Class B */
+                       bits = 16;
+               else                    /* Class A */
+                       bits = 8;
+               /* If imputed mask is narrower than specified octets, widen. */
+               if (bits >= 8 && bits < ((dst - odst) * 8))
+                       bits = (dst - odst) * 8;
+       }
+       /* Extend network to cover the actual mask. */
+       while (bits > ((dst - odst) * 8)) {
+               if (size-- <= 0)
+                       goto emsgsize;
+               *dst++ = '\0';
+       }
+       return (bits);
+
+ enoent:
+
+#ifndef WINNT
+       errno = ENOENT
+     return (-1);
+#else
+     SetLastError(ENOENT);
+     return (-1);
+#endif
+
+ emsgsize:
+
+#ifndef WINNT
+       errno = EMSGSIZE;
+     return (-1);
+#else
+     SetLastError(WSAEMSGSIZE);
+     WSASetLastError(WSAEMSGSIZE);
+     return (-1);
+#endif
+
+}
diff --git a/bindlib_w32/inet_neta.c b/bindlib_w32/inet_neta.c
new file mode 100644 (file)
index 0000000..9e28ff9
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static const char rcsid[] = "$Id$";
+#endif
+
+#include <sys/types.h>
+#ifndef WINNT
+#include <sys/socket.h>
+#include <netinet/in.h>
+#endif
+#include <arpa/inet.h>
+
+#include <errno.h>
+#include <stdio.h>
+
+#ifdef SPRINTF_CHAR
+# define SPRINTF(x) strlen(sprintf/**/x)
+#else
+# define SPRINTF(x) ((size_t)sprintf x)
+#endif
+
+/*
+ * char *
+ * inet_neta(src, dst, size)
+ *     format a u_long network number into presentation format.
+ * return:
+ *     pointer to dst, or NULL if an error occurred (check errno).
+ * note:
+ *     format of ``src'' is as for inet_network().
+ * author:
+ *     Paul Vixie (ISC), July 1996
+ */
+char *
+inet_neta(src, dst, size)
+       u_long src;
+       char *dst;
+       size_t size;
+{
+       char *odst = dst;
+       char *tp;
+
+       while (src & 0xffffffff) {
+               u_char b = (u_char)((src & 0xff000000) >> 24);
+
+               src <<= 8;
+               if (b) {
+                       if (size < sizeof "255.")
+                               goto emsgsize;
+                       tp = dst;
+                       dst += SPRINTF((dst, "%u", b));
+                       if (src != 0L) {
+                               *dst++ = '.';
+                               *dst = '\0';
+                       }
+                       size -= (size_t)(dst - tp);
+               }
+       }
+       if (dst == odst) {
+               if (size < sizeof "0.0.0.0")
+                       goto emsgsize;
+               strcpy(dst, "0.0.0.0");
+       }
+       return (odst);
+
+ emsgsize:
+
+ #ifndef WINNT
+     errno = EMSGSIZE;
+     return (NULL);
+#else
+     WSASetLastError(WSAEMSGSIZE);
+     SetLastError(WSAEMSGSIZE);
+     return (NULL);
+#endif
+
+}
diff --git a/bindlib_w32/inet_ntop.c b/bindlib_w32/inet_ntop.c
new file mode 100644 (file)
index 0000000..b13f68e
--- /dev/null
@@ -0,0 +1,212 @@
+/* Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char rcsid[] = "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+#ifndef WINNT
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#endif
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+#include <string.h>
+#include <errno.h>
+#include <stdio.h>
+#include "conf/portability.h"
+
+#ifdef SPRINTF_CHAR
+# define SPRINTF(x) strlen(sprintf/**/x)
+#else
+# define SPRINTF(x) ((size_t)sprintf x)
+#endif
+
+/*
+ * WARNING: Don't even consider trying to compile this on a system where
+ * sizeof(int) < 4.  sizeof(int) > 4 is fine; all the world's not a VAX.
+ */
+
+static const char *inet_ntop4 __P((const u_char *src, char *dst, size_t size));
+static const char *inet_ntop6 __P((const u_char *src, char *dst, size_t size));
+
+/* char *
+ * inet_ntop(af, src, dst, size)
+ *     convert a network format address to presentation format.
+ * return:
+ *     pointer to presentation format address (`dst'), or NULL (see errno).
+ * author:
+ *     Paul Vixie, 1996.
+ */
+const char *
+inet_ntop(af, src, dst, size)
+       int af;
+       const void *src;
+       char *dst;
+       size_t size;
+{
+       switch (af) {
+       case AF_INET:
+               return (inet_ntop4(src, dst, size));
+       case AF_INET6:
+               return (inet_ntop6(src, dst, size));
+       default:
+#ifndef WINNT
+               errno = EAFNOSUPPORT;
+#else
+               SetLastError(WSAEAFNOSUPPORT);
+               WSASetLastError(WSAEAFNOSUPPORT);
+#endif
+               return (NULL);
+       }
+       /* NOTREACHED */
+}
+
+/* const char *
+ * inet_ntop4(src, dst, size)
+ *     format an IPv4 address, more or less like inet_ntoa()
+ * return:
+ *     `dst' (as a const)
+ * notes:
+ *     (1) uses no statics
+ *     (2) takes a u_char* not an in_addr as input
+ * author:
+ *     Paul Vixie, 1996.
+ */
+static const char *
+inet_ntop4(src, dst, size)
+       const u_char *src;
+       char *dst;
+       size_t size;
+{
+       static const char fmt[] = "%u.%u.%u.%u";
+       char tmp[sizeof "255.255.255.255"];
+
+       if (SPRINTF((tmp, fmt, src[0], src[1], src[2], src[3])) > (int)size) {
+#ifndef WINNT
+               errno = ENOSPC;
+#else
+               SetLastError(ENOSPC);
+               WSASetLastError(ENOSPC);
+#endif
+               return (NULL);
+       }
+       strcpy(dst, tmp);
+       return (dst);
+}
+
+/* const char *
+ * inet_ntop6(src, dst, size)
+ *     convert IPv6 binary address into presentation (printable) format
+ * author:
+ *     Paul Vixie, 1996.
+ */
+static const char *
+inet_ntop6(src, dst, size)
+       const u_char *src;
+       char *dst;
+       size_t size;
+{
+       /*
+        * Note that int32_t and int16_t need only be "at least" large enough
+        * to contain a value of the specified size.  On some systems, like
+        * Crays, there is no such thing as an integer variable with 16 bits.
+        * Keep this in mind if you think this function should have been coded
+        * to use pointer overlays.  All the world's not a VAX.
+        */
+       char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp;
+       struct { int base, len; } best, cur;
+       u_int words[IN6ADDRSZ / INT16SZ];
+       int i;
+
+       /*
+        * Preprocess:
+        *      Copy the input (bytewise) array into a wordwise array.
+        *      Find the longest run of 0x00's in src[] for :: shorthanding.
+        */
+       memset(words, '\0', sizeof words);
+       for (i = 0; i < IN6ADDRSZ; i++)
+               words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3));
+       best.base = -1;
+       cur.base = -1;
+       for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++) {
+               if (words[i] == 0) {
+                       if (cur.base == -1)
+                               cur.base = i, cur.len = 1;
+                       else
+                               cur.len++;
+               } else {
+                       if (cur.base != -1) {
+                               if (best.base == -1 || cur.len > best.len)
+                                       best = cur;
+                               cur.base = -1;
+                       }
+               }
+       }
+       if (cur.base != -1) {
+               if (best.base == -1 || cur.len > best.len)
+                       best = cur;
+       }
+       if (best.base != -1 && best.len < 2)
+               best.base = -1;
+
+       /*
+        * Format the result.
+        */
+       tp = tmp;
+       for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++) {
+               /* Are we inside the best run of 0x00's? */
+               if (best.base != -1 && i >= best.base &&
+                   i < (best.base + best.len)) {
+                       if (i == best.base)
+                               *tp++ = ':';
+                       continue;
+               }
+               /* Are we following an initial run of 0x00s or any real hex? */
+               if (i != 0)
+                       *tp++ = ':';
+               /* Is this address an encapsulated IPv4? */
+               if (i == 6 && best.base == 0 &&
+                   (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) {
+                       if (!inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp)))
+                               return (NULL);
+                       tp += strlen(tp);
+                       break;
+               }
+               tp += SPRINTF((tp, "%x", words[i]));
+       }
+       /* Was it a trailing run of 0x00's? */
+       if (best.base != -1 && (best.base + best.len) == (IN6ADDRSZ / INT16SZ))
+               *tp++ = ':';
+       *tp++ = '\0';
+
+       /*
+        * Check for overflow, copy, and we're done.
+        */
+       if ((size_t)(tp - tmp) > size) {
+#ifndef WINNT
+               errno = ENOSPC;
+#else
+               SetLastError(ENOSPC);
+               WSASetLastError(ENOSPC);
+#endif
+               return (NULL);
+       }
+       strcpy(dst, tmp);
+       return (dst);
+}
diff --git a/bindlib_w32/inet_pton.c b/bindlib_w32/inet_pton.c
new file mode 100644 (file)
index 0000000..a809fbb
--- /dev/null
@@ -0,0 +1,221 @@
+/* Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char rcsid[] = "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+#ifndef WINNT
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#endif
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+#include <string.h>
+#include <errno.h>
+#include "conf/portability.h"
+
+/*
+ * WARNING: Don't even consider trying to compile this on a system where
+ * sizeof(int) < 4.  sizeof(int) > 4 is fine; all the world's not a VAX.
+ */
+
+static int     inet_pton4 __P((const char *src, u_char *dst));
+static int     inet_pton6 __P((const char *src, u_char *dst));
+
+/* int
+ * inet_pton(af, src, dst)
+ *     convert from presentation format (which usually means ASCII printable)
+ *     to network format (which is usually some kind of binary format).
+ * return:
+ *     1 if the address was valid for the specified address family
+ *     0 if the address wasn't valid (`dst' is untouched in this case)
+ *     -1 if some other error occurred (`dst' is untouched in this case, too)
+ * author:
+ *     Paul Vixie, 1996.
+ */
+int
+inet_pton(af, src, dst)
+       int af;
+       const char *src;
+       void *dst;
+{
+       switch (af) {
+       case AF_INET:
+               return (inet_pton4(src, dst));
+       case AF_INET6:
+               return (inet_pton6(src, dst));
+       default:
+#ifndef WINNT
+               errno = EAFNOSUPPORT;
+#else
+        SetLastError(WSAEAFNOSUPPORT);
+#endif
+               return (-1);
+       }
+       /* NOTREACHED */
+}
+
+/* int
+ * inet_pton4(src, dst)
+ *     like inet_aton() but without all the hexadecimal and shorthand.
+ * return:
+ *     1 if `src' is a valid dotted quad, else 0.
+ * notice:
+ *     does not touch `dst' unless it's returning 1.
+ * author:
+ *     Paul Vixie, 1996.
+ */
+static int
+inet_pton4(src, dst)
+       const char *src;
+       u_char *dst;
+{
+       static const char digits[] = "0123456789";
+       int saw_digit, octets, ch;
+       u_char tmp[INADDRSZ], *tp;
+
+       saw_digit = 0;
+       octets = 0;
+       *(tp = tmp) = 0;
+       while ((ch = *src++) != '\0') {
+               const char *pch;
+
+               if ((pch = strchr(digits, ch)) != NULL) {
+                       u_int new = *tp * 10 + (pch - digits);
+
+                       if (new > 255)
+                               return (0);
+                       *tp = new;
+                       if (! saw_digit) {
+                               if (++octets > 4)
+                                       return (0);
+                               saw_digit = 1;
+                       }
+               } else if (ch == '.' && saw_digit) {
+                       if (octets == 4)
+                               return (0);
+                       *++tp = 0;
+                       saw_digit = 0;
+               } else
+                       return (0);
+       }
+       if (octets < 4)
+               return (0);
+
+       memcpy(dst, tmp, INADDRSZ);
+       return (1);
+}
+
+/* int
+ * inet_pton6(src, dst)
+ *     convert presentation level address to network order binary form.
+ * return:
+ *     1 if `src' is a valid [RFC1884 2.2] address, else 0.
+ * notice:
+ *     (1) does not touch `dst' unless it's returning 1.
+ *     (2) :: in a full address is silently ignored.
+ * credit:
+ *     inspired by Mark Andrews.
+ * author:
+ *     Paul Vixie, 1996.
+ */
+static int
+inet_pton6(src, dst)
+       const char *src;
+       u_char *dst;
+{
+       static const char xdigits_l[] = "0123456789abcdef",
+                         xdigits_u[] = "0123456789ABCDEF";
+       u_char tmp[IN6ADDRSZ], *tp, *endp, *colonp;
+       const char *xdigits, *curtok;
+       int ch, saw_xdigit;
+       u_int val;
+
+       memset((tp = tmp), '\0', IN6ADDRSZ);
+       endp = tp + IN6ADDRSZ;
+       colonp = NULL;
+       /* Leading :: requires some special handling. */
+       if (*src == ':')
+               if (*++src != ':')
+                       return (0);
+       curtok = src;
+       saw_xdigit = 0;
+       val = 0;
+       while ((ch = *src++) != '\0') {
+               const char *pch;
+
+               if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
+                       pch = strchr((xdigits = xdigits_u), ch);
+               if (pch != NULL) {
+                       val <<= 4;
+                       val |= (pch - xdigits);
+                       if (val > 0xffff)
+                               return (0);
+                       saw_xdigit = 1;
+                       continue;
+               }
+               if (ch == ':') {
+                       curtok = src;
+                       if (!saw_xdigit) {
+                               if (colonp)
+                                       return (0);
+                               colonp = tp;
+                               continue;
+                       }
+                       if (tp + INT16SZ > endp)
+                               return (0);
+                       *tp++ = (u_char) (val >> 8) & 0xff;
+                       *tp++ = (u_char) val & 0xff;
+                       saw_xdigit = 0;
+                       val = 0;
+                       continue;
+               }
+               if (ch == '.' && ((tp + INADDRSZ) <= endp) &&
+                   inet_pton4(curtok, tp) > 0) {
+                       tp += INADDRSZ;
+                       saw_xdigit = 0;
+                       break;  /* '\0' was seen by inet_pton4(). */
+               }
+               return (0);
+       }
+       if (saw_xdigit) {
+               if (tp + INT16SZ > endp)
+                       return (0);
+               *tp++ = (u_char) (val >> 8) & 0xff;
+               *tp++ = (u_char) val & 0xff;
+       }
+       if (colonp != NULL) {
+               /*
+                * Since some memmove()'s erroneously fail to handle
+                * overlapping regions, we'll do the shift by hand.
+                */
+               const int n = tp - colonp;
+               int i;
+
+               for (i = 1; i <= n; i++) {
+                       endp[- i] = colonp[n - i];
+                       colonp[n - i] = 0;
+               }
+               tp = endp;
+       }
+       if (tp != endp)
+               return (0);
+       memcpy(dst, tmp, IN6ADDRSZ);
+       return (1);
+}
diff --git a/bindlib_w32/named/pathnames.h b/bindlib_w32/named/pathnames.h
new file mode 100644 (file)
index 0000000..9850422
--- /dev/null
@@ -0,0 +1,143 @@
+/*
+ *     @(#)pathnames.h 5.4 (Berkeley) 6/1/90
+ *     $Id$
+ */
+
+/*
+ * ++Copyright++ 1989
+ * -
+ * Copyright (c) 1989
+ *    The Regents of the University of California.  All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ * 
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+
+
+#ifdef _PATH_XFER
+# define _PATH_XFER_PREDEFINED /* probably from Makefile */
+#endif
+
+#ifdef WINNT
+#define        _PATH_BOOT      "%windir%\\NAMED.BOOT"
+#define        _ALT_PATH_BOOT  "%windir%\\NAMED.INI"
+#ifndef _PATH_XFER
+# define _PATH_XFER    "%windir%\\SYSTEM32\\XFER.EXE"
+#endif
+#ifndef _PATH_PIDFILE
+# define _PATH_PIDFILE "%windir%\\NAMED.PID"
+#endif
+/* following paths prepended with GetTempPath() */
+#define        _PATH_DEBUG     "NAMED.RUN" 
+#define        _PATH_DUMPFILE  "NAMDUMP.DB"
+#define        _PATH_STATS     "NAMED.STS"
+#define        _PATH_XFERTRACE "XFER.TRC"
+#define _PATH_XFERDDT  "XFER.DDT"
+#define        _PATH_TMPXFER   "XFER.DDT.XXXXXX"
+#else
+
+#if defined (__sgi) && !defined(_SYSTYPE_SVR4) && !defined(__SYSTYPE_SVR4)
+#define        _PATH_BOOT      "/usr/etc/named.d/named.boot"
+#else
+#define        _PATH_BOOT      "/etc/named.boot"
+#endif
+
+#if defined(BSD) && BSD >= 198810
+
+#include <paths.h>
+#ifndef _PATH_XFER
+# define _PATH_XFER    "/usr/libexec/named-xfer"
+#endif
+#define        _PATH_DEBUG     "named.run"
+#define        _PATH_DUMPFILE  "named_dump.db"
+#ifndef _PATH_PIDFILE
+# define _PATH_PIDFILE "/var/run/named.pid"
+#endif
+#define        _PATH_STATS     "named.stats"
+#define        _PATH_XFERTRACE "xfer.trace"
+#define _PATH_XFERDDT  "xfer.ddt"
+#define        _PATH_TMPXFER   "xfer.ddt.XXXXXX"
+#define        _PATH_TMPDIR    "/var/tmp"
+
+#else /* BSD */
+
+#define        _PATH_DEVNULL   "/dev/null"
+#define        _PATH_TTY       "/dev/tty"
+#ifndef _PATH_XFER
+# define _PATH_XFER    "/etc/named-xfer"
+#endif
+#define        _PATH_DEBUG     "named.run"
+#define        _PATH_DUMPFILE  "named_dump.db"
+#ifndef _PATH_PIDFILE
+# define _PATH_PIDFILE "/etc/named.pid"
+#endif
+#define        _PATH_STATS     "named.stats"
+#define        _PATH_XFERTRACE "xfer.trace"
+#define _PATH_XFERDDT  "xfer.ddt"
+#define        _PATH_TMPXFER   "xfer.ddt.XXXXXX"
+#define        _PATH_TMPDIR    "/usr/tmp"
+#endif /* BSD */
+
+#ifndef _PATH_XFER_PREDEFINED
+# if defined(__sgi) || defined(NeXT) || defined(__ultrix)
+#  undef _PATH_XFER
+#  define _PATH_XFER   "/usr/etc/named-xfer"
+# endif
+# if defined(__osf__)
+#  undef _PATH_XFER
+#  define _PATH_XFER   "/usr/sbin/named-xfer"
+# endif
+# ifdef sun
+#  undef _PATH_XFER
+#  define _PATH_XFER   "/usr/etc/in.named-xfer"
+# endif
+#else
+# undef _PATH_XFER_PREDEFINED
+#endif /*_PATH_XFER_PREDEFINED*/
+
+#endif /* WINNT */
diff --git a/bindlib_w32/netdb.h b/bindlib_w32/netdb.h
new file mode 100644 (file)
index 0000000..db01fd6
--- /dev/null
@@ -0,0 +1,216 @@
+/*
+ * ++Copyright++ 1980, 1983, 1988, 1993
+ * -
+ * Copyright (c) 1980, 1983, 1988, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+
+/*
+ *      @(#)netdb.h    8.1 (Berkeley) 6/2/93
+ *     $Id$
+ */
+
+#ifndef _NETDB_H_
+#define _NETDB_H_
+
+#ifndef WINNT
+#include <sys/param.h>
+#endif /* WINNT */
+#if (!defined(BSD)) || (BSD < 199306)
+#include <sys/bitypes.h>
+#endif
+#include <sys/cdefs.h>
+
+#ifndef WINNT
+#define        _PATH_HEQUIV    "/etc/hosts.equiv"
+#define        _PATH_HOSTS     "/etc/hosts"
+#define        _PATH_NETWORKS  "/etc/networks"
+#define        _PATH_PROTOCOLS "/etc/protocols"
+#define        _PATH_SERVICES  "/etc/services"
+
+extern int h_errno;
+#else /* WINNT */
+
+#ifndef WIN95
+#define        _PATH_HOSTS     "%windir%\\SYSTEM32\\DRIVERS\\ETC\\HOSTS"
+#define        _PATH_NETWORKS  "%windir%\\SYSTEM32\\DRIVERS\\ETC\\NETWORKS"
+#define        _PATH_PROTOCOL  "%windir%\\SYSTEM32\\DRIVERS\\ETC\\PROTOCOL"
+#define        _PATH_SERVICES  "%windir%\\SYSTEM32\\DRIVERS\\ETC\\SERVICES"
+#else
+#define        _PATH_HOSTS     "%windir%\\HOSTS"
+#define        _PATH_NETWORKS  "%windir%\\NETWORKS"
+#define        _PATH_PROTOCOL  "%windir%\\PROTOCOL"
+#define        _PATH_SERVICES  "%windir%\\SERVICES"
+#endif /* WIN95 */
+#endif /* WINNT */
+
+#ifndef WINNT
+/*
+ * Structures returned by network data base library.  All addresses are
+ * supplied in host order, and returned in network order (suitable for
+ * use in system calls).
+ */
+struct hostent {
+       char    *h_name;        /* official name of host */
+       char    **h_aliases;    /* alias list */
+       int     h_addrtype;     /* host address type */
+       int     h_length;       /* length of address */
+       char    **h_addr_list;  /* list of addresses from name server */
+#define        h_addr  h_addr_list[0]  /* address, for backward compatiblity */
+};
+
+/*
+ * Assumption here is that a network number
+ * fits in an unsigned long -- probably a poor one.
+ */
+struct netent {
+       char            *n_name;        /* official name of net */
+       char            **n_aliases;    /* alias list */
+       int             n_addrtype;     /* net address type */
+       unsigned long   n_net;          /* network # */
+};
+
+struct servent {
+       char    *s_name;        /* official service name */
+       char    **s_aliases;    /* alias list */
+       int     s_port;         /* port # */
+       char    *s_proto;       /* protocol to use */
+};
+
+struct protoent {
+       char    *p_name;        /* official protocol name */
+       char    **p_aliases;    /* alias list */
+       int     p_proto;        /* protocol # */
+};
+#endif /* WINNT */
+
+/*
+ * Error return codes from gethostbyname() and gethostbyaddr()
+ * (left in extern int h_errno).
+ */
+
+#define        NETDB_INTERNAL  -1      /* see errno */
+#define        NETDB_SUCCESS   0       /* no problem */
+#ifndef WINNT
+#define        HOST_NOT_FOUND  1 /* Authoritative Answer Host not found */
+#define        TRY_AGAIN       2 /* Non-Authoritive Host not found, or SERVERFAIL */
+#define        NO_RECOVERY     3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
+#define        NO_DATA         4 /* Valid name, no data record of requested type */
+#define        NO_ADDRESS      NO_DATA         /* no address, look for MX record */
+#endif /* WINNT */
+
+__BEGIN_DECLS
+void           endhostent __P((void));
+void           endnetent __P((void));
+void           endprotoent __P((void));
+void           endservent __P((void));
+#ifndef WINNT
+struct hostent *gethostbyaddr __P((const char *, int, int));
+struct hostent *gethostbyname __P((const char *));
+struct hostent *gethostbyname2 __P((const char *, int));
+struct hostent *gethostent __P((void));
+struct netent  *getnetbyaddr __P((unsigned long, int)); /* u_long? */
+struct netent  *getnetbyname __P((const char *));
+#else
+struct hostent *gethostbyaddr_nt __P((const char *, int, int));
+struct hostent *gethostbyname_nt __P((const char *));
+struct hostent *gethostbyname2 __P((const char *, int));
+struct hostent *gethostent __P((void));
+struct netent  *getnetbyaddr __P((unsigned long, int)); /* u_long? */
+struct netent  *getnetbyname __P((const char *));
+#endif
+
+struct netent  *getnetent __P((void));
+#ifndef WINNT
+struct protoent        *getprotobyname __P((const char *));
+struct protoent        *getprotobynumber __P((int));
+#endif
+struct protoent        *getprotoent __P((void));
+#ifndef WINNT
+struct servent *getservbyname __P((const char *, const char *));
+struct servent *getservbyport __P((int, const char *));
+#endif
+struct servent *getservent __P((void));
+void           herror __P((const char *));
+const char     *hstrerror __P((int));
+void           sethostent __P((int));
+/* void                sethostfile __P((const char *)); */
+void           setnetent __P((int));
+void           setprotoent __P((int));
+void           setservent __P((int));
+__END_DECLS
+
+/* This is nec'y to make this include file properly replace the sun version. */
+#ifdef sun
+#ifdef __GNU_LIBRARY__
+#include <rpc/netdb.h>
+#else
+struct rpcent {
+       char    *r_name;        /* name of server for this rpc program */
+       char    **r_aliases;    /* alias list */
+       int     r_number;       /* rpc program number */
+};
+struct rpcent  *getrpcbyname(), *getrpcbynumber(), *getrpcent();
+#endif /* __GNU_LIBRARY__ */
+#endif /* sun */
+
+/*
+ * The Motorola kernel will only support 64 characters for hostname
+ * also defined in /usr/ucbinclude/netdb.h
+ */
+#ifdef __m88k__ 
+#define MAXHOSTNAMELEN 64
+#endif
+#ifdef WINNT 
+#define MAXHOSTNAMELEN 64
+#endif
+
+#endif /* !_NETDB_H_ */
diff --git a/bindlib_w32/nsap_addr.c b/bindlib_w32/nsap_addr.c
new file mode 100644 (file)
index 0000000..f38bddf
--- /dev/null
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char rcsid[] = "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+#ifndef WINNT
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#endif
+#include <arpa/nameser.h>
+#include <ctype.h>
+#include <resolv.h>
+
+#include "conf/portability.h"
+
+#if !defined(isxdigit) /* XXX - could be a function */
+static int
+isxdigit(c)
+       register int c;
+{
+       return ((c >= '0') && (c <= '9')) || ((c >= 'A') && (c <= 'F'));
+}
+#endif
+
+static char
+xtob(c)
+       register int c;
+{
+       return (c - (((c >= '0') && (c <= '9')) ? '0' : '7'));
+}
+
+u_int
+inet_nsap_addr(ascii, binary, maxlen)
+       const char *ascii;
+       u_char *binary;
+       u_int maxlen;
+{
+       register u_char c, nib;
+       u_int len = 0;
+
+       while ((c = *ascii++) != '\0' && len < maxlen) {
+               if (c == '.' || c == '+' || c == '/')
+                       continue;
+               if (!isascii(c))
+                       return (0);
+               if (islower(c))
+                       c = toupper(c);
+               if (isxdigit(c)) {
+                       nib = xtob(c);
+                       if (c = *ascii++) {
+                               c = toupper(c);
+                               if (isxdigit(c)) {
+                                       *binary++ = (nib << 4) | xtob(c);
+                                       len++;
+                               } else
+                                       return (0);
+                       }
+                       else
+                               return (0);
+               }
+               else
+                       return (0);
+       }
+       return (len);
+}
+
+char *
+inet_nsap_ntoa(binlen, binary, ascii)
+       int binlen;
+       register const u_char *binary;
+       register char *ascii;
+{
+       register int nib;
+       int i;
+       static char tmpbuf[255*3];
+       char *start;
+
+       if (ascii)
+               start = ascii;
+       else {
+               ascii = tmpbuf;
+               start = tmpbuf;
+       }
+
+       if (binlen > 255)
+               binlen = 255;
+
+       for (i = 0; i < binlen; i++) {
+               nib = *binary >> 4;
+               *ascii++ = nib + (nib < 10 ? '0' : '7');
+               nib = *binary++ & 0x0f;
+               *ascii++ = nib + (nib < 10 ? '0' : '7');
+               if (((i % 2) == 0 && (i + 1) < binlen))
+                       *ascii++ = '.';
+       }
+       *ascii = '\0';
+       return (start);
+}
diff --git a/bindlib_w32/res_comp.c b/bindlib_w32/res_comp.c
new file mode 100644 (file)
index 0000000..0871f96
--- /dev/null
@@ -0,0 +1,1135 @@
+/*
+ * ++Copyright++ 1985, 1993
+ * -
+ * Copyright (c) 1985, 1993
+ *    The Regents of the University of California.  All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ * 
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)res_comp.c 8.1 (Berkeley) 6/4/93";
+static char rcsid[] = "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#ifndef WINNT
+#include <sys/param.h>
+#include <netinet/in.h>
+#endif
+#include <arpa/nameser.h>
+
+#include <ctype.h>
+#include <errno.h>
+#include <resolv.h>
+#include <stdio.h>
+
+#if defined(BSD) && (BSD >= 199103)
+# include <unistd.h>
+# include <string.h>
+#else
+# include "conf/portability.h"
+#endif
+
+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 *, int,
+                                 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,
+ * 'eomorig' points to the first location after the message,
+ * 'exp_dn' is a pointer to a buffer of size 'length' for the result.
+ * Return size of compressed name or -1 if there was an error.
+ */
+int
+dn_expand(msg, eom, src, dst, dstsiz)
+       const u_char *msg;
+       const u_char *eom;
+       const u_char *src;
+       char *dst;
+       int dstsiz;
+{
+       int n = ns_name_uncompress(msg, eom, src, dst, (size_t)dstsiz);
+
+       if (n > 0 && dst[0] == '.')
+               dst[0] = '\0';
+       return (n);
+}
+
+/*
+ * 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'.
+ */
+int
+dn_comp(src, dst, dstsiz, dnptrs, lastdnptr)
+       const char *src;
+       u_char *dst;
+       int dstsiz;
+       u_char **dnptrs;
+       u_char **lastdnptr;
+{
+       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(ptr, eom)
+       const u_char *ptr;
+       const u_char *eom;
+{
+       const u_char *saveptr = ptr;
+
+       if (ns_name_skip(&ptr, eom) == -1)
+               return (-1);
+       return (ptr - saveptr);
+}
+
+/*
+ * Verify that a domain name uses an acceptable character set.
+ */
+
+/*
+ * Note the conspicuous absence of ctype macros in these definitions.  On
+ * non-ASCII hosts, we can't depend on string literals or ctype macros to
+ * tell us anything about network-format data.  The rest of the BIND system
+ * is not careful about this, but for some reason, we're doing it right here.
+ */
+#define PERIOD 0x2e
+#define        hyphenchar(c) ((c) == 0x2d)
+#define bslashchar(c) ((c) == 0x5c)
+#define periodchar(c) ((c) == PERIOD)
+#define asterchar(c) ((c) == 0x2a)
+#define alphachar(c) (((c) >= 0x41 && (c) <= 0x5a) \
+                  || ((c) >= 0x61 && (c) <= 0x7a))
+#define digitchar(c) ((c) >= 0x30 && (c) <= 0x39)
+
+#define borderchar(c) (alphachar(c) || digitchar(c))
+#define middlechar(c) (borderchar(c) || hyphenchar(c))
+#define        domainchar(c) ((c) > 0x20 && (c) < 0x7f)
+
+int
+res_hnok(dn)
+       const char *dn;
+{
+       int ppch = '\0', pch = PERIOD, ch = *dn++;
+
+       while (ch != '\0') {
+               int nch = *dn++;
+
+               if (periodchar(ch)) {
+                       NULL;
+               } else if (periodchar(pch)) {
+                       if (!borderchar(ch))
+                               return (0);
+               } else if (periodchar(nch) || nch == '\0') {
+                       if (!borderchar(ch))
+                               return (0);
+               } else {
+                       if (!middlechar(ch))
+                               return (0);
+               }
+               ppch = pch, pch = ch, ch = nch;
+       }
+       return (1);
+}
+
+/*
+ * hostname-like (A, MX, WKS) owners can have "*" as their first label
+ * but must otherwise be as a host name.
+ */
+int
+res_ownok(dn)
+       const char *dn;
+{
+       if (asterchar(dn[0])) {
+               if (periodchar(dn[1]))
+                       return (res_hnok(dn+2));
+               if (dn[1] == '\0')
+                       return (1);
+       }
+       return (res_hnok(dn));
+}
+
+/*
+ * SOA RNAMEs and RP RNAMEs can have any printable character in their first
+ * label, but the rest of the name has to look like a host name.
+ */
+int
+res_mailok(dn)
+       const char *dn;
+{
+       int ch, escaped = 0;
+
+       /* "." is a valid missing representation */
+       if (*dn == '\0')
+               return(1);
+
+       /* otherwise <label>.<hostname> */
+       while ((ch = *dn++) != '\0') {
+               if (!domainchar(ch))
+                       return (0);
+               if (!escaped && periodchar(ch))
+                       break;
+               if (escaped)
+                       escaped = 0;
+               else if (bslashchar(ch))
+                       escaped = 1;
+       }
+       if (periodchar(ch))
+               return (res_hnok(dn));
+       return(0);
+}
+
+/*
+ * This function is quite liberal, since RFC 1034's character sets are only
+ * recommendations.
+ */
+int
+res_dnok(dn)
+       const char *dn;
+{
+       int ch;
+
+       while ((ch = *dn++) != '\0')
+               if (!domainchar(ch))
+                       return (0);
+       return (1);
+}
+
+/*
+ * Routines to insert/extract short/long's.
+ */
+
+u_int16_t
+_getshort(msgp)
+       register const u_char *msgp;
+{
+       register u_int16_t u;
+
+       GETSHORT(u, msgp);
+       return (u);
+}
+
+#ifdef NeXT
+/*
+ * nExt machines have some funky library conventions, which we must maintain.
+ */
+u_int16_t
+res_getshort(msgp)
+       register const u_char *msgp;
+{
+       return (_getshort(msgp));
+}
+#endif
+
+u_int32_t
+_getlong(msgp)
+       register const u_char *msgp;
+{
+       register u_int32_t u;
+
+       GETLONG(u, msgp);
+       return (u);
+}
+
+void
+#if defined(__STDC__) || defined(__cplusplus)
+__putshort(register u_int16_t s, register u_char *msgp)        /* must match proto */
+#else
+__putshort(s, msgp)
+       register u_int16_t s;
+       register u_char *msgp;
+#endif
+{
+       PUTSHORT(s, msgp);
+}
+
+void
+__putlong(l, msgp)
+       register u_int32_t l;
+       register u_char *msgp;
+{
+       PUTLONG(l, msgp);
+}
+
+/* ++ From BIND 8.1.1. ++ */
+/*
+ * Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+/*"Id: ns_name.c,v 1.1 1997/12/13 02:41:13 vixie Exp vixie"*/
+
+/*#include "port_before.h"*/
+
+/*#include <sys/types.h>*/
+
+/*#include <netinet/in.h>*/
+/*#include <arpa/nameser.h>*/
+
+/*#include <errno.h>*/
+/*#include <resolv.h>*/
+/*#include <string.h>*/
+
+/*#include "port_after.h"*/
+
+#define NS_CMPRSFLGS   0xc0    /* Flag bits indicating name compression. */
+#define NS_MAXCDNAME   255     /* maximum compressed domain name */
+
+/* Data. */
+
+static char            digits[] = "0123456789";
+
+/* Forward. */
+
+static int             special(int);
+static int             printable(int);
+static int             dn_find(const u_char *, const u_char *,
+                               const u_char * const *,
+                               const u_char * const *);
+
+/* Public. */
+
+/*
+ * ns_name_ntop(src, dst, dstsiz)
+ *     Convert an encoded domain name to printable ascii as per RFC1035.
+ * return:
+ *     Number of bytes written to buffer, or -1 (with errno set)
+ * notes:
+ *     The root is returned as "."
+ *     All other domains are returned in non absolute form
+ */
+static int
+ns_name_ntop(src, dst, dstsiz)
+       const u_char *src;
+       char *dst;
+       size_t dstsiz;
+{
+       const u_char *cp;
+       char *dn, *eom;
+       u_char c;
+       u_int n;
+
+       cp = src;
+       dn = dst;
+       eom = dst + dstsiz;
+
+       while ((n = *cp++) != 0) {
+               if ((n & NS_CMPRSFLGS) != 0) {
+                       /* Some kind of compression pointer. */
+#ifndef WINNT
+     errno = EMSGSIZE;
+#else
+     WSASetLastError(WSAEMSGSIZE);
+     SetLastError(WSAEMSGSIZE);
+#endif
+     return (-1);
+
+               }
+               if (dn != dst) {
+                       if (dn >= eom) {
+#ifndef WINNT
+     errno = EMSGSIZE;
+#else
+     WSASetLastError(WSAEMSGSIZE);
+     SetLastError(WSAEMSGSIZE);
+#endif
+     return (-1);
+                       }
+                       *dn++ = '.';
+               }
+               if (dn + n >= eom) {
+#ifndef WINNT
+     errno = EMSGSIZE;
+#else
+     WSASetLastError(WSAEMSGSIZE);
+     SetLastError(WSAEMSGSIZE);
+#endif
+                       return (-1);
+               }
+               for ((void)NULL; n > 0; n--) {
+                       c = *cp++;
+                       if (special(c)) {
+                               if (dn + 1 >= eom) {
+#ifndef WINNT
+     errno = EMSGSIZE;
+#else
+     WSASetLastError(WSAEMSGSIZE);
+     SetLastError(WSAEMSGSIZE);
+#endif
+                                       return (-1);
+                               }
+                               *dn++ = '\\';
+                               *dn++ = (char)c;
+                       } else if (!printable(c)) {
+                               if (dn + 3 >= eom) {
+#ifndef WINNT
+     errno = EMSGSIZE;
+#else
+     WSASetLastError(WSAEMSGSIZE);
+     SetLastError(WSAEMSGSIZE);
+#endif
+                                       return (-1);
+                               }
+                               *dn++ = '\\';
+                               *dn++ = digits[c / 100];
+                               *dn++ = digits[(c % 100) / 10];
+                               *dn++ = digits[c % 10];
+                       } else {
+                               if (dn >= eom) {
+#ifndef WINNT
+     errno = EMSGSIZE;
+#else
+     WSASetLastError(WSAEMSGSIZE);
+     SetLastError(WSAEMSGSIZE);
+#endif
+                                       return (-1);
+                               }
+                               *dn++ = (char)c;
+                       }
+               }
+       }
+       if (dn == dst) {
+               if (dn >= eom) {
+#ifndef WINNT
+     errno = EMSGSIZE;
+#else
+     WSASetLastError(WSAEMSGSIZE);
+     SetLastError(WSAEMSGSIZE);
+#endif
+                       return (-1);
+               }
+               *dn++ = '.';
+       }
+       if (dn >= eom) {
+#ifndef WINNT
+     errno = EMSGSIZE;
+#else
+     WSASetLastError(WSAEMSGSIZE);
+     SetLastError(WSAEMSGSIZE);
+#endif
+               return (-1);
+       }
+       *dn++ = '\0';
+       return (dn - dst);
+}
+
+/*
+ * ns_name_pton(src, dst, dstsiz)
+ *     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
+ * notes:
+ *     Enforces label and domain length limits.
+ */
+
+static int
+ns_name_pton(src, dst, dstsiz)
+       const char *src;
+       u_char *dst;
+       size_t dstsiz;
+{
+       u_char *label, *bp, *eom;
+       int c, n, escaped;
+       char *cp;
+
+       escaped = 0;
+       bp = dst;
+       eom = dst + dstsiz;
+       label = bp++;
+
+       while ((c = *src++) != 0) {
+               if (escaped) {
+                       if ((cp = strchr(digits, c)) != NULL) {
+                               n = (cp - digits) * 100;
+                               if ((c = *src++) == 0 ||
+                                   (cp = strchr(digits, c)) == NULL) {
+#ifndef WINNT
+     errno = EMSGSIZE;
+#else
+     WSASetLastError(WSAEMSGSIZE);
+     SetLastError(WSAEMSGSIZE);
+#endif
+                                       return (-1);
+                               }
+                               n += (cp - digits) * 10;
+                               if ((c = *src++) == 0 ||
+                                   (cp = strchr(digits, c)) == NULL) {
+#ifndef WINNT
+     errno = EMSGSIZE;
+#else
+     WSASetLastError(WSAEMSGSIZE);
+     SetLastError(WSAEMSGSIZE);
+#endif
+                                       return (-1);
+                               }
+                               n += (cp - digits);
+                               if (n > 255) {
+#ifndef WINNT
+     errno = EMSGSIZE;
+#else
+     WSASetLastError(WSAEMSGSIZE);
+     SetLastError(WSAEMSGSIZE);
+#endif
+                                       return (-1);
+                               }
+                               c = n;
+                       }
+                       escaped = 0;
+               } else if (c == '\\') {
+                       escaped = 1;
+                       continue;
+               } else if (c == '.') {
+                       c = (bp - label - 1);
+                       if ((c & NS_CMPRSFLGS) != 0) {  /* Label too big. */
+#ifndef WINNT
+     errno = EMSGSIZE;
+#else
+     WSASetLastError(WSAEMSGSIZE);
+     SetLastError(WSAEMSGSIZE);
+#endif
+                               return (-1);
+                       }
+                       if (label >= eom) {
+#ifndef WINNT
+     errno = EMSGSIZE;
+#else
+     WSASetLastError(WSAEMSGSIZE);
+     SetLastError(WSAEMSGSIZE);
+#endif
+                               return (-1);
+                       }
+                       *label = c;
+                       /* Fully qualified ? */
+                       if (*src == '\0') {
+                               if (c != 0) {
+                                       if (bp >= eom) {
+#ifndef WINNT
+     errno = EMSGSIZE;
+#else
+     WSASetLastError(WSAEMSGSIZE);
+     SetLastError(WSAEMSGSIZE);
+#endif
+                                               return (-1);
+                                       }
+                                       *bp++ = '\0';
+                               }
+                               if ((bp - dst) > MAXCDNAME) {
+#ifndef WINNT
+     errno = EMSGSIZE;
+#else
+     WSASetLastError(WSAEMSGSIZE);
+     SetLastError(WSAEMSGSIZE);
+#endif
+                                       return (-1);
+                               }
+                               return (1);
+                       }
+                       if (c == 0) {
+#ifndef WINNT
+     errno = EMSGSIZE;
+#else
+     WSASetLastError(WSAEMSGSIZE);
+     SetLastError(WSAEMSGSIZE);
+#endif
+                               return (-1);
+                       }
+                       label = bp++;
+                       continue;
+               }
+               if (bp >= eom) {
+#ifndef WINNT
+     errno = EMSGSIZE;
+#else
+     WSASetLastError(WSAEMSGSIZE);
+     SetLastError(WSAEMSGSIZE);
+#endif
+                       return (-1);
+               }
+               *bp++ = (u_char)c;
+       }
+       c = (bp - label - 1);
+       if ((c & NS_CMPRSFLGS) != 0) {          /* Label too big. */
+#ifndef WINNT
+     errno = EMSGSIZE;
+#else
+     WSASetLastError(WSAEMSGSIZE);
+     SetLastError(WSAEMSGSIZE);
+#endif
+               return (-1);
+       }
+       if (label >= eom) {
+#ifndef WINNT
+     errno = EMSGSIZE;
+#else
+     WSASetLastError(WSAEMSGSIZE);
+     SetLastError(WSAEMSGSIZE);
+#endif
+               return (-1);
+       }
+       *label = c;
+       if (c != 0) {
+               if (bp >= eom) {
+#ifndef WINNT
+     errno = EMSGSIZE;
+#else
+     WSASetLastError(WSAEMSGSIZE);
+     SetLastError(WSAEMSGSIZE);
+#endif
+                       return (-1);
+               }
+               *bp++ = 0;
+       }
+       if ((bp - dst) > MAXCDNAME) {   /* src too big */
+#ifndef WINNT
+     errno = EMSGSIZE;
+#else
+     WSASetLastError(WSAEMSGSIZE);
+     SetLastError(WSAEMSGSIZE);
+#endif
+               return (-1);
+       }
+       return (0);
+}
+
+/*
+ * ns_name_unpack(msg, eom, src, dst, dstsiz)
+ *     Unpack a domain name from a message, source may be compressed.
+ * return:
+ *     -1 if it fails, or consumed octets if it succeeds.
+ */
+static int
+ns_name_unpack(msg, eom, src, dst, dstsiz)
+       const u_char *msg;
+       const u_char *eom;
+       const u_char *src;
+       u_char *dst;
+       size_t dstsiz;
+{
+       const u_char *srcp, *dstlim;
+       u_char *dstp;
+       int n, len, checked;
+
+       len = -1;
+       checked = 0;
+       dstp = dst;
+       srcp = src;
+       dstlim = dst + dstsiz;
+       if (srcp < msg || srcp >= eom) {
+#ifndef WINNT
+     errno = EMSGSIZE;
+#else
+     WSASetLastError(WSAEMSGSIZE);
+     SetLastError(WSAEMSGSIZE);
+#endif
+               return (-1);
+       }
+       /* Fetch next label in domain name. */
+       while ((n = *srcp++) != 0) {
+               /* Check for indirection. */
+               switch (n & NS_CMPRSFLGS) {
+               case 0:
+                       /* Limit checks. */
+                       if (dstp + n + 1 >= dstlim || srcp + n >= eom) {
+#ifndef WINNT
+     errno = EMSGSIZE;
+#else
+     WSASetLastError(WSAEMSGSIZE);
+     SetLastError(WSAEMSGSIZE);
+#endif
+                               return (-1);
+                       }
+                       checked += n + 1;
+                       *dstp++ = n;
+                       memcpy(dstp, srcp, n);
+                       dstp += n;
+                       srcp += n;
+                       break;
+
+               case NS_CMPRSFLGS:
+                       if (srcp >= eom) {
+#ifndef WINNT
+     errno = EMSGSIZE;
+#else
+     WSASetLastError(WSAEMSGSIZE);
+     SetLastError(WSAEMSGSIZE);
+#endif
+                               return (-1);
+                       }
+                       if (len < 0)
+                               len = srcp - src + 1;
+                       srcp = msg + (((n & 0x3f) << 8) | (*srcp & 0xff));
+                       if (srcp < msg || srcp >= eom) {  /* Out of range. */
+#ifndef WINNT
+     errno = EMSGSIZE;
+#else
+     WSASetLastError(WSAEMSGSIZE);
+     SetLastError(WSAEMSGSIZE);
+#endif
+                               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 >= eom - msg) {
+#ifndef WINNT
+     errno = EMSGSIZE;
+#else
+     WSASetLastError(WSAEMSGSIZE);
+     SetLastError(WSAEMSGSIZE);
+#endif
+                               return (-1);
+                       }
+                       break;
+
+               default:
+#ifndef WINNT
+     errno = EMSGSIZE;
+#else
+     WSASetLastError(WSAEMSGSIZE);
+     SetLastError(WSAEMSGSIZE);
+#endif
+                       return (-1);                    /* flag error */
+               }
+       }
+       *dstp = '\0';
+       if (len < 0)
+               len = srcp - src;
+       return (len);
+}
+
+/*
+ * ns_name_pack(src, dst, dstsiz, dnptrs, lastdnptr)
+ *     Pack domain name 'domain' into 'comp_dn'.
+ * return:
+ *     Size of the compressed name, or -1.
+ * notes:
+ *     'dnptrs' is an array of pointers to previous compressed names.
+ *     dnptrs[0] is a pointer to the beginning of the message. The array
+ *     ends with NULL.
+ *     'lastdnptr' is a pointer to the end of the array pointed to
+ *     by 'dnptrs'.
+ * Side effects:
+ *     The list of pointers in dnptrs is updated 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.
+ */
+static int
+ns_name_pack(src, dst, dstsiz, dnptrs, lastdnptr)
+       const u_char *src;
+       u_char *dst;
+       int dstsiz;
+       const u_char **dnptrs;
+       const u_char **lastdnptr;
+{
+       u_char *dstp;
+       const u_char **cpp, **lpp, *eob, *msg;
+       const u_char *srcp;
+       int n, l;
+
+       srcp = src;
+       dstp = dst;
+       eob = dstp + dstsiz;
+       lpp = cpp = NULL;
+       if (dnptrs != NULL) {
+               if ((msg = *dnptrs++) != NULL) {
+                       for (cpp = dnptrs; *cpp != NULL; cpp++)
+                               (void)NULL;
+                       lpp = cpp;      /* end of list to search */
+               }
+       } else
+               msg = NULL;
+
+       /* make sure the domain we are about to add is legal */
+       l = 0;
+       do {
+               n = *srcp;
+               if ((n & NS_CMPRSFLGS) != 0) {
+#ifndef WINNT
+     errno = EMSGSIZE;
+#else
+     WSASetLastError(WSAEMSGSIZE);
+     SetLastError(WSAEMSGSIZE);
+#endif
+                       return (-1);
+               }
+               l += n + 1;
+               if (l > MAXCDNAME) {
+#ifndef WINNT
+     errno = EMSGSIZE;
+#else
+     WSASetLastError(WSAEMSGSIZE);
+     SetLastError(WSAEMSGSIZE);
+#endif
+                       return (-1);
+               }
+               srcp += n + 1;
+       } while (n != 0);
+
+       srcp = src;
+       do {
+               /* Look to see if we can use pointers. */
+               n = *srcp;
+               if (n != 0 && msg != NULL) {
+                       l = dn_find(srcp, msg, (const u_char * const *)dnptrs,
+                                   (const u_char * const *)lpp);
+                       if (l >= 0) {
+                               if (dstp + 1 >= eob) {
+#ifndef WINNT
+     errno = EMSGSIZE;
+#else
+     WSASetLastError(WSAEMSGSIZE);
+     SetLastError(WSAEMSGSIZE);
+#endif
+                                       return (-1);
+                               }
+                               *dstp++ = (l >> 8) | NS_CMPRSFLGS;
+                               *dstp++ = l % 256;
+                               return (dstp - dst);
+                       }
+                       /* Not found, save it. */
+                       if (lastdnptr != NULL && cpp < lastdnptr - 1 &&
+                           (dstp - msg) < 0x4000) {
+                               *cpp++ = dstp;
+                               *cpp = NULL;
+                       }
+               }
+               /* copy label to buffer */
+               if (n & NS_CMPRSFLGS) {         /* Should not happen. */
+#ifndef WINNT
+     errno = EMSGSIZE;
+#else
+     WSASetLastError(WSAEMSGSIZE);
+     SetLastError(WSAEMSGSIZE);
+#endif
+                       return (-1);
+               }
+               if (dstp + 1 + n >= eob) {
+#ifndef WINNT
+     errno = EMSGSIZE;
+#else
+     WSASetLastError(WSAEMSGSIZE);
+     SetLastError(WSAEMSGSIZE);
+#endif
+                       return (-1);
+               }
+               memcpy(dstp, srcp, n + 1);
+               srcp += n + 1;
+               dstp += n + 1;
+       } while (n != 0);
+
+       if (dstp > eob) {
+               if (msg != NULL)
+                       *lpp = NULL;
+#ifndef WINNT
+     errno = EMSGSIZE;
+#else
+     WSASetLastError(WSAEMSGSIZE);
+     SetLastError(WSAEMSGSIZE);
+#endif
+               return (-1);
+       } 
+       return (dstp - dst);
+}
+
+/*
+ * ns_name_uncompress(msg, eom, src, dst, dstsiz)
+ *     Expand compressed domain name to presentation format.
+ * return:
+ *     Number of bytes read out of `src', or -1 (with errno set).
+ * note:
+ *     Root domain returns as "." not "".
+ */
+static int
+ns_name_uncompress(msg, eom, src, dst, dstsiz)
+       const u_char *msg;
+       const u_char *eom;
+       const u_char *src;
+       char *dst;
+       size_t dstsiz;
+{
+       u_char tmp[NS_MAXCDNAME];
+       int n;
+       
+       if ((n = ns_name_unpack(msg, eom, src, tmp, sizeof tmp)) == -1)
+               return (-1);
+       if (ns_name_ntop(tmp, dst, dstsiz) == -1)
+               return (-1);
+       return (n);
+}
+
+/*
+ * ns_name_compress(src, dst, dstsiz, dnptrs, lastdnptr)
+ *     Compress a domain name into wire format, using compression pointers.
+ * return:
+ *     Number of bytes consumed in `dst' or -1 (with errno set).
+ * notes:
+ *     'dnptrs' is an array 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
+ *     array 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.
+ */
+static int
+ns_name_compress(src, dst, dstsiz, dnptrs, lastdnptr)
+       const char *src;
+       u_char *dst;
+       size_t dstsiz;
+       const u_char **dnptrs;
+       const u_char **lastdnptr;
+{
+       u_char tmp[NS_MAXCDNAME];
+
+       if (ns_name_pton(src, tmp, sizeof tmp) == -1)
+               return (-1);
+       return (ns_name_pack(tmp, dst, dstsiz, dnptrs, lastdnptr));
+}
+
+/*
+ * ns_name_skip(ptrptr, eom)
+ *     Advance *ptrptr to skip over the compressed name it points at.
+ * return:
+ *     0 on success, -1 (with errno set) on failure.
+ */
+static int
+ns_name_skip(ptrptr, eom)
+       const u_char **ptrptr;
+       const u_char *eom;
+{
+       const u_char *cp;
+       u_int n;
+
+       cp = *ptrptr;
+       while (cp < eom && (n = *cp++) != 0) {
+               /* Check for indirection. */
+               switch (n & NS_CMPRSFLGS) {
+               case 0:                 /* normal case, n == len */
+                       cp += n;
+                       continue;
+               case NS_CMPRSFLGS:      /* indirection */
+                       cp++;
+                       break;
+               default:                /* illegal type */
+#ifndef WINNT
+     errno = EMSGSIZE;
+#else
+     WSASetLastError(WSAEMSGSIZE);
+     SetLastError(WSAEMSGSIZE);
+#endif
+                       return (-1);
+               }
+               break;
+       }
+       if (cp > eom) {
+#ifndef WINNT
+     errno = EMSGSIZE;
+#else
+     WSASetLastError(WSAEMSGSIZE);
+     SetLastError(WSAEMSGSIZE);
+#endif
+               return (-1);
+       }
+       *ptrptr = cp;
+       return (0);
+}
+
+/* Private. */
+
+/*
+ * special(ch)
+ *     Thinking in noninternationalized USASCII (per the DNS spec),
+ *     is this characted special ("in need of quoting") ?
+ * return:
+ *     boolean.
+ */
+static int
+special(ch)
+       int ch;
+{
+       switch (ch) {
+       case 0x22: /* '"' */
+       case 0x2E: /* '.' */
+       case 0x3B: /* ';' */
+       case 0x5C: /* '\\' */
+       /* Special modifiers in zone files. */
+       case 0x40: /* '@' */
+       case 0x24: /* '$' */
+               return (1);
+       default:
+               return (0);
+       }
+}
+
+/*
+ * printable(ch)
+ *     Thinking in noninternationalized USASCII (per the DNS spec),
+ *     is this character visible and not a space when printed ?
+ * return:
+ *     boolean.
+ */
+static int
+printable(ch)
+       int ch;
+{
+       return (ch > 0x20 && ch < 0x7f);
+}
+
+/*
+ *     Thinking in noninternationalized USASCII (per the DNS spec),
+ *     convert this character to lower case if it's upper case.
+ */
+static int
+mklower(ch)
+       int ch;
+{
+       if (ch >= 0x41 && ch <= 0x5A)
+               return (ch + 0x20);
+       return (ch);
+}
+
+/*
+ * dn_find(domain, msg, dnptrs, lastdnptr)
+ *     Search for the counted-label name in an array of compressed names.
+ * return:
+ *     offset from msg if found, or -1.
+ * notes:
+ *     dnptrs is the pointer to the first name on the list,
+ *     not the pointer to the start of the message.
+ */
+static int
+dn_find(domain, msg, dnptrs, lastdnptr)
+       const u_char *domain;
+       const u_char *msg;
+       const u_char * const *dnptrs;
+       const u_char * const *lastdnptr;
+{
+       const u_char *dn, *cp, *sp;
+       const u_char * const *cpp;
+       u_int n;
+
+       for (cpp = dnptrs; cpp < lastdnptr; cpp++) {
+               dn = domain;
+               sp = cp = *cpp;
+               while ((n = *cp++) != 0) {
+                       /*
+                        * check for indirection
+                        */
+                       switch (n & NS_CMPRSFLGS) {
+                       case 0:                 /* normal case, n == len */
+                               if (n != *dn++)
+                                       goto next;
+                               for ((void)NULL; n > 0; n--)
+                                       if (mklower(*dn++) != mklower(*cp++))
+                                               goto next;
+                               /* Is next root for both ? */
+                               if (*dn == '\0' && *cp == '\0')
+                                       return (sp - msg);
+                               if (*dn)
+                                       continue;
+                               goto next;
+
+                       case NS_CMPRSFLGS:      /* indirection */
+                               cp = msg + (((n & 0x3f) << 8) | *cp);
+                               break;
+
+                       default:        /* illegal type */
+#ifndef WINNT
+     errno = EMSGSIZE;
+#else
+     WSASetLastError(WSAEMSGSIZE);
+     SetLastError(WSAEMSGSIZE);
+#endif
+                               return (-1);
+                       }
+               }
+ next: ;
+       }
+#ifndef WINNT
+    errno = ENOENT;
+#else
+     SetLastError(ENOENT);
+#endif
+       return (-1);
+}
+
+/* -- From BIND 8.1.1. -- */
diff --git a/bindlib_w32/res_data.c b/bindlib_w32/res_data.c
new file mode 100644 (file)
index 0000000..e434731
--- /dev/null
@@ -0,0 +1,117 @@
+/*
+ * ++Copyright++ 1995
+ * -
+ * Copyright (c) 1995
+ *    The Regents of the University of California.  All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ * 
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char rcsid[] = "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#ifndef WINNT
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <netinet/in.h>
+#endif /* WINNT */
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+
+#include <stdio.h>
+#include <ctype.h>
+#include <resolv.h>
+#if defined(BSD) && (BSD >= 199103)
+# include <unistd.h>
+# include <stdlib.h>
+# include <string.h>
+#else
+# include "conf/portability.h"
+#endif
+
+const char *_res_opcodes[] = {
+       "QUERY",
+       "IQUERY",
+       "CQUERYM",
+       "CQUERYU",      /* experimental */
+       "NOTIFY",       /* experimental */
+       "5",
+       "6",
+       "7",
+       "8",
+       "UPDATEA",
+       "UPDATED",
+       "UPDATEDA",
+       "UPDATEM",
+       "UPDATEMA",
+       "ZONEINIT",
+       "ZONEREF",
+};
+
+const char *_res_resultcodes[] = {
+       "NOERROR",
+       "FORMERR",
+       "SERVFAIL",
+       "NXDOMAIN",
+       "NOTIMP",
+       "REFUSED",
+       "6",
+       "7",
+       "8",
+       "9",
+       "10",
+       "11",
+       "12",
+       "13",
+       "14",
+       "NOCHANGE",
+};
diff --git a/bindlib_w32/res_debug.c b/bindlib_w32/res_debug.c
new file mode 100644 (file)
index 0000000..feaf6a2
--- /dev/null
@@ -0,0 +1,1546 @@
+/*
+ * ++Copyright++ 1985, 1990, 1993
+ * -
+ * Copyright (c) 1985, 1990, 1993
+ *    The Regents of the University of California.  All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ * 
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * Portions Copyright (c) 1995 by International Business Machines, Inc.
+ *
+ * International Business Machines, Inc. (hereinafter called IBM) grants
+ * permission under its copyrights to use, copy, modify, and distribute this
+ * Software with or without fee, provided that the above copyright notice and
+ * all paragraphs of this notice appear in all copies, and that the name of IBM
+ * not be used in connection with the marketing of any product incorporating
+ * the Software or modifications thereof, without specific, written prior
+ * permission.
+ *
+ * To the extent it has a right to do so, IBM grants an immunity from suit
+ * under its patents, if any, for the use, sale or manufacture of products to
+ * the extent that such products are used for performing Domain Name System
+ * dynamic updates in TCP/IP networks by means of the Software.  No immunity is
+ * granted for any product per se or for any other function of any product.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE.  IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
+ * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
+ * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ * --Copyright--
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)res_debug.c        8.1 (Berkeley) 6/4/93";
+static char rcsid[] = "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+#ifndef WINNT
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#endif
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+
+#include <ctype.h>
+#include <netdb.h>
+#include <resolv.h>
+#include <stdio.h>
+#include <time.h>
+
+#if defined(BSD) && (BSD >= 199103) && defined(AF_INET6)
+# include <stdlib.h>
+# include <string.h>
+#else
+# include "conf/portability.h"
+#endif
+
+#if defined(USE_OPTIONS_H)
+# include "conf/options.h"
+#endif
+
+extern const char *_res_opcodes[];
+extern const char *_res_resultcodes[];
+char * inet_nsap_ntoa();
+const char * inet_ntop();
+
+/* XXX: we should use getservbyport() instead. */
+static const char *
+dewks(wks)
+       int wks;
+{
+       static char nbuf[20];
+
+       switch (wks) {
+       case 5: return "rje";
+       case 7: return "echo";
+       case 9: return "discard";
+       case 11: return "systat";
+       case 13: return "daytime";
+       case 15: return "netstat";
+       case 17: return "qotd";
+       case 19: return "chargen";
+       case 20: return "ftp-data";
+       case 21: return "ftp";
+       case 23: return "telnet";
+       case 25: return "smtp";
+       case 37: return "time";
+       case 39: return "rlp";
+       case 42: return "name";
+       case 43: return "whois";
+       case 53: return "domain";
+       case 57: return "apts";
+       case 59: return "apfs";
+       case 67: return "bootps";
+       case 68: return "bootpc";
+       case 69: return "tftp";
+       case 77: return "rje";
+       case 79: return "finger";
+       case 87: return "link";
+       case 95: return "supdup";
+       case 100: return "newacct";
+       case 101: return "hostnames";
+       case 102: return "iso-tsap";
+       case 103: return "x400";
+       case 104: return "x400-snd";
+       case 105: return "csnet-ns";
+       case 109: return "pop-2";
+       case 111: return "sunrpc";
+       case 113: return "auth";
+       case 115: return "sftp";
+       case 117: return "uucp-path";
+       case 119: return "nntp";
+       case 121: return "erpc";
+       case 123: return "ntp";
+       case 133: return "statsrv";
+       case 136: return "profile";
+       case 144: return "NeWS";
+       case 161: return "snmp";
+       case 162: return "snmp-trap";
+       case 170: return "print-srv";
+       default: (void) sprintf(nbuf, "%d", wks); return (nbuf);
+       }
+}
+
+/* XXX: we should use getprotobynumber() instead. */
+static const char *
+deproto(protonum)
+       int protonum;
+{
+       static char nbuf[20];
+
+       switch (protonum) {
+       case 1: return "icmp";
+       case 2: return "igmp";
+       case 3: return "ggp";
+       case 5: return "st";
+       case 6: return "tcp";
+       case 7: return "ucl";
+       case 8: return "egp";
+       case 9: return "igp";
+       case 11: return "nvp-II";
+       case 12: return "pup";
+       case 16: return "chaos";
+       case 17: return "udp";
+       default: (void) sprintf(nbuf, "%d", protonum); return (nbuf);
+       }
+}
+
+static const u_char *
+do_rrset(msg, len, cp, cnt, pflag, file, hs)
+       int cnt, pflag, len;
+       const u_char *cp, *msg;
+       const char *hs;
+       FILE *file;
+{
+       int n;
+       int sflag;
+
+       /*
+        * Print answer records.
+        */
+       sflag = (_res.pfcode & pflag);
+       if (n = ntohs( (u_short) cnt)) {
+               if ((!_res.pfcode) ||
+                   ((sflag) && (_res.pfcode & RES_PRF_HEAD1)))
+                       fprintf(file, hs);
+               while (--n >= 0) {
+                       if ((!_res.pfcode) || sflag) {
+                               cp = p_rr(cp, msg, file);
+                       } else {
+                               unsigned int dlen;
+                               cp += __dn_skipname(cp, cp + MAXCDNAME);
+                               cp += INT16SZ;
+                               cp += INT16SZ;
+                               cp += INT32SZ;
+                               dlen = _getshort((u_char*)cp);
+                               cp += INT16SZ;
+                               cp += dlen;
+                       }
+                       if ((cp - msg) > len)
+                               return (NULL);
+               }
+               if ((!_res.pfcode) ||
+                   ((sflag) && (_res.pfcode & RES_PRF_HEAD1)))
+                       putc('\n', file);
+       }
+       return (cp);
+}
+
+void
+__p_query(msg)
+       const u_char *msg;
+{
+       __fp_query(msg, stdout);
+}
+
+#ifdef ultrix
+#undef p_query
+/* ultrix 4.0's packaging has some icky packaging.  alias for it here.
+ * there is more junk of this kind over in res_comp.c.
+ */
+void
+p_query(msg)
+       const u_char *msg;
+{
+       __p_query(msg);
+}
+#endif
+
+/*
+ * Print the current options.
+ * This is intended to be primarily a debugging routine.
+ */
+void
+__fp_resstat(statp, file)
+       struct __res_state *statp;
+       FILE *file;
+{
+       register u_long mask;
+
+       fprintf(file, ";; res options:");
+       if (!statp)
+               statp = &_res;
+       for (mask = 1;  mask != 0;  mask <<= 1)
+               if (statp->options & mask)
+                       fprintf(file, " %s", p_option(mask));
+       putc('\n', file);
+}
+
+/*
+ * Print the contents of a query.
+ * This is intended to be primarily a debugging routine.
+ */
+void
+__fp_nquery(msg, len, file)
+       const u_char *msg;
+       int len;
+       FILE *file;
+{
+       register const u_char *cp, *endMark;
+       register const HEADER *hp;
+       register int n;
+
+       if ((_res.options & RES_INIT) == 0 && res_init() == -1)
+               return;
+
+#define TruncTest(x) if (x > endMark) goto trunc
+#define        ErrorTest(x) if (x == NULL) goto error
+
+       /*
+        * Print header fields.
+        */
+       hp = (HEADER *)msg;
+       cp = msg + HFIXEDSZ;
+       endMark = msg + len;
+       if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX) || hp->rcode) {
+               fprintf(file, ";; ->>HEADER<<- opcode: %s, status: %s, id: %d",
+                       _res_opcodes[hp->opcode],
+                       _res_resultcodes[hp->rcode],
+                       ntohs( (u_short) hp->id));
+               putc('\n', file);
+       }
+       if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX))
+               putc(';', file);
+       if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD2)) {
+               fprintf(file, "; flags:");
+               if (hp->qr)
+                       fprintf(file, " qr");
+               if (hp->aa)
+                       fprintf(file, " aa");
+               if (hp->tc)
+                       fprintf(file, " tc");
+               if (hp->rd)
+                       fprintf(file, " rd");
+               if (hp->ra)
+                       fprintf(file, " ra");
+               if (hp->unused)
+                       fprintf(file, " UNUSED-BIT-ON");
+               if (hp->ad)
+                       fprintf(file, " ad");
+               if (hp->cd)
+                       fprintf(file, " cd");
+       }
+       if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD1)) {
+               fprintf(file, "; Ques: %d", ntohs( (u_short) hp->qdcount));
+               fprintf(file, ", Ans: %d", ntohs( (u_short) hp->ancount));
+               fprintf(file, ", Auth: %d", ntohs( (u_short) hp->nscount));
+               fprintf(file, ", Addit: %d", ntohs( (u_short) hp->arcount));
+       }
+       if ((!_res.pfcode) || (_res.pfcode & 
+               (RES_PRF_HEADX | RES_PRF_HEAD2 | RES_PRF_HEAD1))) {
+               putc('\n',file);
+       }
+       /*
+        * Print question records.
+        */
+       if (n = ntohs( (u_short) hp->qdcount)) {
+               if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES))
+                       fprintf(file, ";; QUESTIONS:\n");
+               while (--n >= 0) {
+                       if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES))
+                               fprintf(file, ";;\t");
+                       TruncTest(cp);
+                       if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES))
+                               cp = p_cdnname(cp, msg, len, file);
+                       else {
+                               int n;
+                               char name[MAXDNAME];
+
+                               if ((n = dn_expand(msg, msg+len, cp, name,
+                                               sizeof name)) < 0)
+                                       cp = NULL;
+                               else
+                                       cp += n;
+                       }
+                       ErrorTest(cp);
+                       TruncTest(cp);
+                       if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES))
+                               fprintf(file, ", type = %s",
+                                       __p_type(_getshort((u_char*)cp)));
+                       cp += INT16SZ;
+                       TruncTest(cp);
+                       if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES))
+                               fprintf(file, ", class = %s\n",
+                                       __p_class(_getshort((u_char*)cp)));
+                       cp += INT16SZ;
+                       if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES))
+                               putc('\n', file);
+               }
+       }
+       /*
+        * Print authoritative answer records
+        */
+       TruncTest(cp);
+       cp = do_rrset(msg, len, cp, hp->ancount, RES_PRF_ANS, file,
+                     ";; ANSWERS:\n");
+       ErrorTest(cp);
+
+       /*
+        * print name server records
+        */
+       TruncTest(cp);
+       cp = do_rrset(msg, len, cp, hp->nscount, RES_PRF_AUTH, file,
+                     ";; AUTHORITY RECORDS:\n");
+       ErrorTest(cp);
+
+       TruncTest(cp);
+       /*
+        * print additional records
+        */
+       cp = do_rrset(msg, len, cp, hp->arcount, RES_PRF_ADD, file,
+                     ";; ADDITIONAL RECORDS:\n");
+       ErrorTest(cp);
+       return;
+ trunc:
+       fprintf(file, "\n;; ...truncated\n");
+       return;
+ error:
+       fprintf(file, "\n;; ...malformed\n");
+}
+
+void
+__fp_query(msg, file)
+       const u_char *msg;
+       FILE *file;
+{
+       fp_nquery(msg, PACKETSZ, file);
+}
+
+const u_char *
+__p_cdnname(cp, msg, len, file)
+       const u_char *cp, *msg;
+       int len;
+       FILE *file;
+{
+       char name[MAXDNAME];
+       int n;
+
+       if ((n = dn_expand(msg, msg + len, cp, name, sizeof name)) < 0)
+               return (NULL);
+       if (name[0] == '\0')
+               putc('.', file);
+       else
+               fputs(name, file);
+       return (cp + n);
+}
+
+const u_char *
+__p_cdname(cp, msg, file)
+       const u_char *cp, *msg;
+       FILE *file;
+{
+       return (p_cdnname(cp, msg, PACKETSZ, file));
+}
+
+
+/* Return a fully-qualified domain name from a compressed name (with
+   length supplied).  */
+
+const u_char *
+__p_fqnname(cp, msg, msglen, name, namelen)
+       const u_char *cp, *msg;
+       int msglen;
+       char *name;
+       int namelen;
+{
+       int n, newlen;
+
+       if ((n = dn_expand(msg, cp + msglen, cp, name, namelen)) < 0)
+               return (NULL);
+       newlen = strlen (name);
+       if (newlen == 0 || name[newlen - 1] != '.')
+               if (newlen+1 >= namelen)        /* Lack space for final dot */
+                       return (NULL);
+               else
+                       strcpy(name + newlen, ".");
+       return (cp + n);
+}
+
+/* XXX:        the rest of these functions need to become length-limited, too. (vix)
+ */
+
+const u_char *
+__p_fqname(cp, msg, file)
+       const u_char *cp, *msg;
+       FILE *file;
+{
+       char name[MAXDNAME];
+       const u_char *n;
+
+       n = __p_fqnname(cp, msg, MAXCDNAME, name, sizeof name);
+       if (n == NULL)
+               return (NULL);
+       fputs(name, file);
+       return (n);
+}
+
+/*
+ * Print resource record fields in human readable form.
+ */
+const u_char *
+__p_rr(cp, msg, file)
+       const u_char *cp, *msg;
+       FILE *file;
+{
+       int type, class, dlen, n, c;
+       struct in_addr inaddr;
+       const u_char *cp1, *cp2;
+       u_int32_t tmpttl, t;
+       int lcnt;
+       u_int16_t keyflags;
+       char rrname[MAXDNAME];          /* The fqdn of this RR */
+       char base64_key[MAX_KEY_BASE64];
+
+       if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+#ifndef WINNT
+               h_errno = NETDB_INTERNAL;
+#else
+               WSASetLastError(NETDB_INTERNAL);
+#endif
+               return (NULL);
+       }
+       cp = __p_fqnname(cp, msg, MAXCDNAME, rrname, sizeof rrname);
+       if (!cp)
+               return (NULL);                  /* compression error */
+       fputs(rrname, file);
+       
+       type = _getshort((u_char*)cp);
+       cp += INT16SZ;
+       class = _getshort((u_char*)cp);
+       cp += INT16SZ;
+       tmpttl = _getlong((u_char*)cp);
+       cp += INT32SZ;
+       dlen = _getshort((u_char*)cp);
+       cp += INT16SZ;
+       cp1 = cp;
+       if ((!_res.pfcode) || (_res.pfcode & RES_PRF_TTLID))
+               fprintf(file, "\t%lu", (u_long)tmpttl);
+       if ((!_res.pfcode) || (_res.pfcode & RES_PRF_CLASS))
+               fprintf(file, "\t%s", __p_class(class));
+       fprintf(file, "\t%s", __p_type(type));
+       /*
+        * Print type specific data, if appropriate
+        */
+       switch (type) {
+       case T_A:
+               switch (class) {
+               case C_IN:
+               case C_HS:
+                       bcopy(cp, (char *)&inaddr, INADDRSZ);
+                       if (dlen == 4) {
+                               fprintf(file, "\t%s", inet_ntoa(inaddr));
+                               cp += dlen;
+                       } else if (dlen == 7) {
+                               char *address;
+                               u_char protocol;
+                               u_short port;
+
+                               address = inet_ntoa(inaddr);
+                               cp += INADDRSZ;
+                               protocol = *(u_char*)cp;
+                               cp += sizeof (u_char);
+                               port = _getshort((u_char*)cp);
+                               cp += INT16SZ;
+                               fprintf(file, "\t%s\t; proto %d, port %d",
+                                       address, protocol, port);
+                       }
+                       break;
+               default:
+                       cp += dlen;
+               }
+               break;
+       case T_CNAME:
+       case T_MB:
+       case T_MG:
+       case T_MR:
+       case T_NS:
+       case T_PTR:
+               putc('\t', file);
+               if ((cp = p_fqname(cp, msg, file)) == NULL)
+                       return (NULL);
+               break;
+
+       case T_HINFO:
+       case T_ISDN:
+               cp2 = cp + dlen;
+               (void) fputs("\t\"", file);
+               if ((n = (unsigned char) *cp++) != 0) {
+                       for (c = n; c > 0 && cp < cp2; c--) {
+                               if (strchr("\n\"\\", *cp))
+                                       (void) putc('\\', file);
+                               (void) putc(*cp++, file);
+                       }
+               }
+               putc('"', file);
+               if (cp < cp2 && (n = (unsigned char) *cp++) != 0) {
+                       (void) fputs ("\t\"", file);
+                       for (c = n; c > 0 && cp < cp2; c--) {
+                               if (strchr("\n\"\\", *cp))
+                                       (void) putc('\\', file);
+                               (void) putc(*cp++, file);
+                       }
+                       putc('"', file);
+               } else if (type == T_HINFO) {
+                       (void) fputs("\"?\"", file);
+                       fprintf(file, "\n;; *** Warning *** OS-type missing");
+               }
+               break;
+
+       case T_SOA:
+               putc('\t', file);
+               if ((cp = p_fqname(cp, msg, file)) == NULL)
+                       return (NULL);
+               putc(' ', file);
+               if ((cp = p_fqname(cp, msg, file)) == NULL)
+                       return (NULL);
+               fputs(" (\n", file);
+               t = _getlong((u_char*)cp);  cp += INT32SZ;
+               fprintf(file, "\t\t\t%lu\t; serial\n", (u_long)t);
+               t = _getlong((u_char*)cp);  cp += INT32SZ;
+               fprintf(file, "\t\t\t%lu\t; refresh (%s)\n",
+                       (u_long)t, __p_time(t));
+               t = _getlong((u_char*)cp);  cp += INT32SZ;
+               fprintf(file, "\t\t\t%lu\t; retry (%s)\n",
+                       (u_long)t, __p_time(t));
+               t = _getlong((u_char*)cp);  cp += INT32SZ;
+               fprintf(file, "\t\t\t%lu\t; expire (%s)\n",
+                       (u_long)t, __p_time(t));
+               t = _getlong((u_char*)cp);  cp += INT32SZ;
+               fprintf(file, "\t\t\t%lu )\t; minimum (%s)",
+                       (u_long)t, __p_time(t));
+               break;
+
+       case T_MX:
+       case T_AFSDB:
+       case T_RT:
+               fprintf(file, "\t%d ", _getshort((u_char*)cp));
+               cp += INT16SZ;
+               if ((cp = p_fqname(cp, msg, file)) == NULL)
+                       return (NULL);
+               break;
+
+       case T_PX:
+               fprintf(file, "\t%d ", _getshort((u_char*)cp));
+               cp += INT16SZ;
+               if ((cp = p_fqname(cp, msg, file)) == NULL)
+                       return (NULL);
+               putc(' ', file);
+               if ((cp = p_fqname(cp, msg, file)) == NULL)
+                       return (NULL);
+               break;
+
+       case T_X25:
+               cp2 = cp + dlen;
+               (void) fputs("\t\"", file);
+               if ((n = (unsigned char) *cp++) != 0) {
+                       for (c = n; c > 0 && cp < cp2; c--) {
+                               if (strchr("\n\"\\", *cp))
+                                       (void) putc('\\', file);
+                               (void) putc(*cp++, file);
+                       }
+               }
+               putc('"', file);
+               break;
+
+       case T_TXT:
+               (void) putc('\t', file);
+               cp2 = cp1 + dlen;
+               while (cp < cp2) {
+                       putc('"', file);
+                       if (n = (unsigned char) *cp++) {
+                               for (c = n; c > 0 && cp < cp2; c--) {
+                                       if (strchr("\n\"\\", *cp))
+                                               (void) putc('\\', file);
+                                       (void) putc(*cp++, file);
+                               }
+                       }
+                       putc('"', file);
+                       if (cp < cp2)
+                               putc(' ', file);
+               }
+               break;
+
+       case T_NSAP:
+               (void) fprintf(file, "\t%s", inet_nsap_ntoa(dlen, cp, NULL));
+               cp += dlen;
+               break;
+
+       case T_AAAA: {
+               char t[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"];
+
+               fprintf(file, "\t%s", inet_ntop(AF_INET6, cp, t, sizeof t));
+               cp += dlen;
+               break;
+           }
+
+       case T_LOC: {
+               char t[255];
+
+               fprintf(file, "\t%s", loc_ntoa(cp, t));
+               cp += dlen;
+               break;
+           }
+
+       case T_NAPTR: {
+               u_int order, preference;
+
+               order = _getshort(cp);  cp += INT16SZ;
+               preference   = _getshort(cp);  cp += INT16SZ;
+               fprintf(file, "\t%u %u ",order, preference);
+               /* Flags */
+               n = *cp++;
+               fprintf(file,"\"%.*s\" ", (int)n, cp);
+               cp += n;
+               /* Service */
+               n = *cp++;
+               fprintf(file,"\"%.*s\" ", (int)n, cp);
+               cp += n;
+               /* Regexp */
+               n = *cp++;
+               fprintf(file,"\"%.*s\" ", (int)n, cp);
+               cp += n;
+               if ((cp = p_fqname(cp, msg, file)) == NULL)
+                       return (NULL);
+               break;
+           }
+
+       case T_SRV: {
+               u_int priority, weight, port;
+
+               priority = _getshort(cp);  cp += INT16SZ;
+               weight   = _getshort(cp);  cp += INT16SZ;
+               port     = _getshort(cp);  cp += INT16SZ;
+               fprintf(file, "\t%u %u %u ", priority, weight, port);
+               if ((cp = p_fqname(cp, msg, file)) == NULL)
+                       return (NULL);
+               break;
+           }
+
+       case T_MINFO:
+       case T_RP:
+               putc('\t', file);
+               if ((cp = p_fqname(cp, msg, file)) == NULL)
+                       return (NULL);
+               putc(' ', file);
+               if ((cp = p_fqname(cp, msg, file)) == NULL)
+                       return (NULL);
+               break;
+
+       case T_UINFO:
+               putc('\t', file);
+               fputs((char *)cp, file);
+               cp += dlen;
+               break;
+
+       case T_UID:
+       case T_GID:
+               if (dlen == 4) {
+                       fprintf(file, "\t%u", _getlong((u_char*)cp));
+                       cp += INT32SZ;
+               }
+               break;
+
+       case T_WKS:
+               if (dlen < INT32SZ + 1)
+                       break;
+               bcopy(cp, (char *)&inaddr, INADDRSZ);
+               cp += INT32SZ;
+               fprintf(file, "\t%s %s ( ",
+                       inet_ntoa(inaddr),
+                       deproto((int) *cp));
+               cp += sizeof (u_char);
+               n = 0;
+               lcnt = 0;
+               while (cp < cp1 + dlen) {
+                       c = *cp++;
+                       do {
+                               if (c & 0200) {
+                                       if (lcnt == 0) {
+                                               fputs("\n\t\t\t", file);
+                                               lcnt = 5;
+                                       }
+                                       fputs(dewks(n), file);
+                                       putc(' ', file);
+                                       lcnt--;
+                               }
+                               c <<= 1;
+                       } while (++n & 07);
+               }
+               putc(')', file);
+               break;
+
+       case T_KEY:
+               putc('\t', file);
+               keyflags = _getshort(cp);
+               cp += 2;
+               fprintf(file,"0x%04x", keyflags );      /* flags */
+               fprintf(file," %u", *cp++);     /* protocol */
+               fprintf(file," %u (", *cp++);   /* algorithm */
+
+               n = b64_ntop(cp, (cp1 + dlen) - cp,
+                            base64_key, sizeof base64_key);
+               for (c = 0; c < n; ++c) {
+                       if (0 == (c & 0x3F))
+                               fprintf(file, "\n\t");
+                       putc(base64_key[c], file);  /* public key data */
+               }
+
+               fprintf(file, " )");
+               if (n < 0)
+                       fprintf(file, "\t; BAD BASE64");
+               fflush(file);
+               cp = cp1 + dlen;
+               break;
+
+       case T_SIG:
+               type = _getshort((u_char*)cp);
+               cp += INT16SZ;
+               fprintf(file, " %s", p_type(type));
+               fprintf(file, "\t%d", *cp++);   /* algorithm */
+               /* Check label value and print error if wrong. */
+               n = *cp++;
+               c = dn_count_labels (rrname);
+               if (n != c)
+                       fprintf(file, "\t; LABELS WRONG (%d should be %d)\n\t",
+                               n, c);
+               /* orig ttl */
+               n = _getlong((u_char*)cp);
+               if ((u_int32_t)n != tmpttl)
+                       fprintf(file, " %u", n);
+               cp += INT32SZ;
+               /* sig expire */
+               fprintf(file, " (\n\t%s",
+                                    __p_secstodate(_getlong((u_char*)cp)));
+               cp += INT32SZ;
+               /* time signed */
+               fprintf(file, " %s", __p_secstodate(_getlong((u_char*)cp)));
+               cp += INT32SZ;
+               /* sig footprint */
+               fprintf(file," %u ", _getshort((u_char*)cp));
+               cp += INT16SZ;
+               /* signer's name */
+               cp = p_fqname(cp, msg, file);
+               n = b64_ntop(cp, (cp1 + dlen) - cp,
+                            base64_key, sizeof base64_key);
+               for (c = 0; c < n; c++) {
+                       if (0 == (c & 0x3F))
+                               fprintf (file, "\n\t");
+                       putc(base64_key[c], file);              /* signature */
+               }
+               /* Clean up... */
+               fprintf(file, " )");
+               if (n < 0)
+                       fprintf(file, "\t; BAD BASE64");
+               fflush(file);
+               cp = cp1+dlen;
+               break;
+
+#ifdef ALLOW_T_UNSPEC
+       case T_UNSPEC:
+               {
+                       int NumBytes = 8;
+                       u_char *DataPtr;
+                       int i;
+
+                       if (dlen < NumBytes) NumBytes = dlen;
+                       fprintf(file, "\tFirst %d bytes of hex data:",
+                               NumBytes);
+                       for (i = 0, DataPtr = cp; i < NumBytes; i++, DataPtr++)
+                               fprintf(file, " %x", *DataPtr);
+                       cp += dlen;
+               }
+               break;
+#endif /* ALLOW_T_UNSPEC */
+
+       default:
+               fprintf(file, "\t?%d?", type);
+               cp += dlen;
+       }
+#if 0
+       fprintf(file, "\t; dlen=%d, ttl %s\n", dlen, __p_time(tmpttl));
+#else
+       putc('\n', file);
+#endif
+       if (cp - cp1 != dlen) {
+               fprintf(file, ";; packet size error (found %d, dlen was %d)\n",
+                       cp - cp1, dlen);
+               cp = NULL;
+       }
+       return (cp);
+}
+
+/*
+ * Names of RR classes and qclasses.  Classes and qclasses are the same, except
+ * that C_ANY is a qclass but not a class.  (You can ask for records of class
+ * C_ANY, but you can't have any records of that class in the database.)
+ */
+const struct res_sym __p_class_syms[] = {
+       {C_IN,          "IN"},
+       {C_CHAOS,       "CHAOS"},
+       {C_HS,          "HS"},
+       {C_HS,          "HESIOD"},
+       {C_ANY,         "ANY"},
+       {C_IN,          (char *)0}
+};
+
+/*
+ * Names of RR types and qtypes.  Types and qtypes are the same, except
+ * that T_ANY is a qtype but not a type.  (You can ask for records of type
+ * T_ANY, but you can't have any records of that type in the database.)
+ */
+const struct res_sym __p_type_syms[] = {
+       {T_A,           "A",            "address"},
+       {T_NS,          "NS",           "name server"},
+       {T_MD,          "MD",           "mail destination (deprecated)"},
+       {T_MF,          "MF",           "mail forwarder (deprecated)"},
+       {T_CNAME,       "CNAME",        "canonical name"},
+       {T_SOA,         "SOA",          "start of authority"},
+       {T_MB,          "MB",           "mailbox"},
+       {T_MG,          "MG",           "mail group member"},
+       {T_MR,          "MR",           "mail rename"},
+       {T_NULL,        "NULL",         "null"},
+       {T_WKS,         "WKS",          "well-known service (deprecated)"},
+       {T_PTR,         "PTR",          "domain name pointer"},
+       {T_HINFO,       "HINFO",        "host information"},
+       {T_MINFO,       "MINFO",        "mailbox information"},
+       {T_MX,          "MX",           "mail exchanger"},
+       {T_TXT,         "TXT",          "text"},
+       {T_RP,          "RP",           "responsible person"},
+       {T_AFSDB,       "AFSDB",        "DCE or AFS server"},
+       {T_X25,         "X25",          "X25 address"},
+       {T_ISDN,        "ISDN",         "ISDN address"},
+       {T_RT,          "RT",           "router"},
+       {T_NSAP,        "NSAP",         "nsap address"},
+       {T_NSAP_PTR,    "NSAP_PTR",     "domain name pointer"},
+       {T_SIG,         "SIG",          "signature"},
+       {T_KEY,         "KEY",          "key"},
+       {T_PX,          "PX",           "mapping information"},
+       {T_GPOS,        "GPOS",         "geographical position (withdrawn)"},
+       {T_AAAA,        "AAAA",         "IPv6 address"},
+       {T_LOC,         "LOC",          "location"},
+       {T_NXT,         "NXT",          "next valid name (unimplemented)"},
+       {T_EID,         "EID",          "endpoint identifier (unimplemented)"},
+       {T_NIMLOC,      "NIMLOC",       "NIMROD locator (unimplemented)"},
+       {T_SRV,         "SRV",          "server selection"},
+       {T_ATMA,        "ATMA",         "ATM address (unimplemented)"},
+       {T_IXFR,        "IXFR",         "incremental zone transfer"},
+       {T_AXFR,        "AXFR",         "zone transfer"},
+       {T_MAILB,       "MAILB",        "mailbox-related data (deprecated)"},
+       {T_MAILA,       "MAILA",        "mail agent (deprecated)"},
+       {T_UINFO,       "UINFO",        "user information (nonstandard)"},
+       {T_UID,         "UID",          "user ID (nonstandard)"},
+       {T_GID,         "GID",          "group ID (nonstandard)"},
+       {T_NAPTR,       "NAPTR",        "URN Naming Authority"},
+#ifdef ALLOW_T_UNSPEC
+       {T_UNSPEC,      "UNSPEC",       "unspecified data (nonstandard)"},
+#endif /* ALLOW_T_UNSPEC */
+       {T_ANY,         "ANY",          "\"any\""},
+       {0,             NULL,           NULL}
+};
+
+int
+__sym_ston(syms, name, success)
+       const struct res_sym *syms;
+       char *name;
+       int *success;
+{
+       for (NULL; syms->name != 0; syms++) {
+               if (strcasecmp (name, syms->name) == 0) {
+                       if (success)
+                               *success = 1;
+                       return (syms->number);
+               }
+       }
+       if (success)
+               *success = 0;
+       return (syms->number);          /* The default value. */
+}
+
+const char *
+__sym_ntos(syms, number, success)
+       const struct res_sym *syms;
+       int number;
+       int *success;
+{
+       static char unname[20];
+
+       for (NULL; syms->name != 0; syms++) {
+               if (number == syms->number) {
+                       if (success)
+                               *success = 1;
+                       return (syms->name);
+               }
+       }
+
+       sprintf (unname, "%d", number);
+       if (success)
+               *success = 0;
+       return (unname);
+}
+
+
+const char *
+__sym_ntop(syms, number, success)
+       const struct res_sym *syms;
+       int number;
+       int *success;
+{
+       static char unname[20];
+
+       for (NULL; syms->name != 0; syms++) {
+               if (number == syms->number) {
+                       if (success)
+                               *success = 1;
+                       return (syms->humanname);
+               }
+       }
+       sprintf(unname, "%d", number);
+       if (success)
+               *success = 0;
+       return (unname);
+}
+
+/*
+ * Return a string for the type
+ */
+const char *
+__p_type(type)
+       int type;
+{
+       return (__sym_ntos (__p_type_syms, type, (int *)0));
+}
+
+/*
+ * Return a mnemonic for class
+ */
+const char *
+__p_class(class)
+       int class;
+{
+       return (__sym_ntos (__p_class_syms, class, (int *)0));
+}
+
+/*
+ * Return a mnemonic for an option
+ */
+const char *
+__p_option(option)
+       u_long option;
+{
+       static char nbuf[40];
+
+       switch (option) {
+       case RES_INIT:          return "init";
+       case RES_DEBUG:         return "debug";
+       case RES_AAONLY:        return "aaonly(unimpl)";
+       case RES_USEVC:         return "usevc";
+       case RES_PRIMARY:       return "primry(unimpl)";
+       case RES_IGNTC:         return "igntc";
+       case RES_RECURSE:       return "recurs";
+       case RES_DEFNAMES:      return "defnam";
+       case RES_STAYOPEN:      return "styopn";
+       case RES_DNSRCH:        return "dnsrch";
+       case RES_INSECURE1:     return "insecure1";
+       case RES_INSECURE2:     return "insecure2";
+       default:                sprintf(nbuf, "?0x%lx?", (u_long)option);
+                               return (nbuf);
+       }
+}
+
+/*
+ * Return a mnemonic for a time to live
+ */
+const char *
+p_time(value)
+       u_int32_t value;
+{
+       static char nbuf[40];
+       int secs, mins, hours, days;
+       register char *p;
+
+       if (value == 0) {
+               strcpy(nbuf, "0 secs");
+               return (nbuf);
+       }
+
+       secs = value % 60;
+       value /= 60;
+       mins = value % 60;
+       value /= 60;
+       hours = value % 24;
+       value /= 24;
+       days = value;
+       value = 0;
+
+#define        PLURALIZE(x)    x, (x == 1) ? "" : "s"
+       p = nbuf;
+       if (days) {
+               (void)sprintf(p, "%d day%s", PLURALIZE(days));
+               while (*++p);
+       }
+       if (hours) {
+               if (days)
+                       *p++ = ' ';
+               (void)sprintf(p, "%d hour%s", PLURALIZE(hours));
+               while (*++p);
+       }
+       if (mins) {
+               if (days || hours)
+                       *p++ = ' ';
+               (void)sprintf(p, "%d min%s", PLURALIZE(mins));
+               while (*++p);
+       }
+       if (secs || ! (days || hours || mins)) {
+               if (days || hours || mins)
+                       *p++ = ' ';
+               (void)sprintf(p, "%d sec%s", PLURALIZE(secs));
+       }
+       return (nbuf);
+}
+
+/*
+ * routines to convert between on-the-wire RR format and zone file format.
+ * Does not contain conversion to/from decimal degrees; divide or multiply
+ * by 60*60*1000 for that.
+ */
+
+static unsigned int poweroften[10] = {1, 10, 100, 1000, 10000, 100000,
+                                     1000000,10000000,100000000,1000000000};
+
+/* takes an XeY precision/size value, returns a string representation. */
+static const char *
+precsize_ntoa(prec)
+       u_int8_t prec;
+{
+       static char retbuf[sizeof "90000000.00"];
+       unsigned long val;
+       int mantissa, exponent;
+
+       mantissa = (int)((prec >> 4) & 0x0f) % 10;
+       exponent = (int)((prec >> 0) & 0x0f) % 10;
+
+       val = mantissa * poweroften[exponent];
+
+       (void) sprintf(retbuf, "%ld.%.2ld", val/100, val%100);
+       return (retbuf);
+}
+
+/* converts ascii size/precision X * 10**Y(cm) to 0xXY.  moves pointer. */
+static u_int8_t
+precsize_aton(strptr)
+       char **strptr;
+{
+       u_int8_t retval = 0;
+       char *cp;
+       int exponent = 0;
+       int mantissa = 0;
+
+       cp = *strptr;
+       while (isdigit(*cp)) {
+               if (mantissa == 0)
+                       mantissa = *cp - '0';
+               else
+                       exponent++;
+               cp++;
+       }
+
+       if (*cp == '.') {
+               cp++;
+               if (isdigit(*cp)) {
+                       if (mantissa == 0)
+                               mantissa = *cp - '0';
+                       else
+                               exponent++;
+                       cp++;
+
+                       if (isdigit(*cp)) {
+                               if (mantissa == 0)
+                                       mantissa = *cp - '0';
+                               else
+                                       exponent++;
+                               cp++;
+                       }
+                       else
+                               exponent++;
+               }
+       }
+       else
+               exponent += 2;
+
+       if (mantissa == 0)
+               exponent = 0;
+       retval = (mantissa << 4) | exponent;
+       *strptr = cp;
+       return (retval);
+}
+
+/* converts ascii lat/lon to unsigned encoded 32-bit number.  moves pointer. */
+static u_int32_t
+latlon2ul(latlonstrptr,which)
+       char **latlonstrptr;
+       int *which;
+{
+       register char *cp;
+       u_int32_t retval;
+       int deg = 0, min = 0, secs = 0, secsfrac = 0;
+
+       cp = *latlonstrptr;
+
+       while (isdigit(*cp))
+               deg = deg * 10 + (*cp++ - '0');
+
+       while (isspace(*cp))
+               cp++;
+
+       if (!(isdigit(*cp)))
+               goto fndhemi;
+
+       while (isdigit(*cp))
+               min = min * 10 + (*cp++ - '0');
+
+       while (isspace(*cp))
+               cp++;
+
+       if (!(isdigit(*cp)))
+               goto fndhemi;
+
+       while (isdigit(*cp))
+               secs = secs * 10 + (*cp++ - '0');
+
+       if (*cp == '.') {               /* decimal seconds */
+               cp++;
+               if (isdigit(*cp)) {
+                       secsfrac = (*cp++ - '0') * 100;
+                       if (isdigit(*cp)) {
+                               secsfrac += (*cp++ - '0') * 10;
+                               if (isdigit(*cp)) {
+                                       secsfrac += (*cp++ - '0');
+                               }
+                       }
+               }
+       }
+
+       while (!isspace(*cp))   /* if any trailing garbage */
+               cp++;
+
+       while (isspace(*cp))
+               cp++;
+
+ fndhemi:
+       switch (*cp) {
+       case 'N': case 'n':
+       case 'E': case 'e':
+               retval = ((unsigned)1<<31)
+                       + (((((deg * 60) + min) * 60) + secs) * 1000)
+                       + secsfrac;
+               break;
+       case 'S': case 's':
+       case 'W': case 'w':
+               retval = ((unsigned)1<<31)
+                       - (((((deg * 60) + min) * 60) + secs) * 1000)
+                       - secsfrac;
+               break;
+       default:
+               retval = 0;     /* invalid value -- indicates error */
+               break;
+       }
+
+       switch (*cp) {
+       case 'N': case 'n':
+       case 'S': case 's':
+               *which = 1;     /* latitude */
+               break;
+       case 'E': case 'e':
+       case 'W': case 'w':
+               *which = 2;     /* longitude */
+               break;
+       default:
+               *which = 0;     /* error */
+               break;
+       }
+
+       cp++;                   /* skip the hemisphere */
+
+       while (!isspace(*cp))   /* if any trailing garbage */
+               cp++;
+
+       while (isspace(*cp))    /* move to next field */
+               cp++;
+
+       *latlonstrptr = cp;
+
+       return (retval);
+}
+
+/* converts a zone file representation in a string to an RDATA on-the-wire
+ * representation. */
+int
+loc_aton(ascii, binary)
+       const char *ascii;
+       u_char *binary;
+{
+       const char *cp, *maxcp;
+       u_char *bcp;
+
+       u_int32_t latit = 0, longit = 0, alt = 0;
+       u_int32_t lltemp1 = 0, lltemp2 = 0;
+       int altmeters = 0, altfrac = 0, altsign = 1;
+       u_int8_t hp = 0x16;     /* default = 1e6 cm = 10000.00m = 10km */
+       u_int8_t vp = 0x13;     /* default = 1e3 cm = 10.00m */
+       u_int8_t siz = 0x12;    /* default = 1e2 cm = 1.00m */
+       int which1 = 0, which2 = 0;
+
+       cp = ascii;
+       maxcp = cp + strlen(ascii);
+
+       lltemp1 = latlon2ul(&cp, &which1);
+
+       lltemp2 = latlon2ul(&cp, &which2);
+
+       switch (which1 + which2) {
+       case 3:                 /* 1 + 2, the only valid combination */
+               if ((which1 == 1) && (which2 == 2)) { /* normal case */
+                       latit = lltemp1;
+                       longit = lltemp2;
+               } else if ((which1 == 2) && (which2 == 1)) { /* reversed */
+                       longit = lltemp1;
+                       latit = lltemp2;
+               } else {        /* some kind of brokenness */
+                       return (0);
+               }
+               break;
+       default:                /* we didn't get one of each */
+               return (0);
+       }
+
+       /* altitude */
+       if (*cp == '-') {
+               altsign = -1;
+               cp++;
+       }
+    
+       if (*cp == '+')
+               cp++;
+
+       while (isdigit(*cp))
+               altmeters = altmeters * 10 + (*cp++ - '0');
+
+       if (*cp == '.') {               /* decimal meters */
+               cp++;
+               if (isdigit(*cp)) {
+                       altfrac = (*cp++ - '0') * 10;
+                       if (isdigit(*cp)) {
+                               altfrac += (*cp++ - '0');
+                       }
+               }
+       }
+
+       alt = (10000000 + (altsign * (altmeters * 100 + altfrac)));
+
+       while (!isspace(*cp) && (cp < maxcp)) /* if trailing garbage or m */
+               cp++;
+
+       while (isspace(*cp) && (cp < maxcp))
+               cp++;
+
+       if (cp >= maxcp)
+               goto defaults;
+
+       siz = precsize_aton(&cp);
+       
+       while (!isspace(*cp) && (cp < maxcp))   /* if trailing garbage or m */
+               cp++;
+
+       while (isspace(*cp) && (cp < maxcp))
+               cp++;
+
+       if (cp >= maxcp)
+               goto defaults;
+
+       hp = precsize_aton(&cp);
+
+       while (!isspace(*cp) && (cp < maxcp))   /* if trailing garbage or m */
+               cp++;
+
+       while (isspace(*cp) && (cp < maxcp))
+               cp++;
+
+       if (cp >= maxcp)
+               goto defaults;
+
+       vp = precsize_aton(&cp);
+
+ defaults:
+
+       bcp = binary;
+       *bcp++ = (u_int8_t) 0;  /* version byte */
+       *bcp++ = siz;
+       *bcp++ = hp;
+       *bcp++ = vp;
+       PUTLONG(latit,bcp);
+       PUTLONG(longit,bcp);
+       PUTLONG(alt,bcp);
+    
+       return (16);            /* size of RR in octets */
+}
+
+/* takes an on-the-wire LOC RR and formats it in a human readable format. */
+const char *
+loc_ntoa(binary, ascii)
+       const u_char *binary;
+       char *ascii;
+{
+       static char *error = "?";
+       register const u_char *cp = binary;
+
+       int latdeg, latmin, latsec, latsecfrac;
+       int longdeg, longmin, longsec, longsecfrac;
+       char northsouth, eastwest;
+       int altmeters, altfrac, altsign;
+
+       const int referencealt = 100000 * 100;
+
+       int32_t latval, longval, altval;
+       u_int32_t templ;
+       u_int8_t sizeval, hpval, vpval, versionval;
+    
+       char *sizestr, *hpstr, *vpstr;
+
+       versionval = *cp++;
+
+       if (versionval) {
+               sprintf(ascii, "; error: unknown LOC RR version");
+               return (ascii);
+       }
+
+       sizeval = *cp++;
+
+       hpval = *cp++;
+       vpval = *cp++;
+
+       GETLONG(templ, cp);
+       latval = (templ - ((unsigned)1<<31));
+
+       GETLONG(templ, cp);
+       longval = (templ - ((unsigned)1<<31));
+
+       GETLONG(templ, cp);
+       if (templ < (u_int32_t)referencealt) { /* below WGS 84 spheroid */
+               altval = referencealt - templ;
+               altsign = -1;
+       } else {
+               altval = templ - referencealt;
+               altsign = 1;
+       }
+
+       if (latval < 0) {
+               northsouth = 'S';
+               latval = -latval;
+       } else
+               northsouth = 'N';
+
+       latsecfrac = latval % 1000;
+       latval = latval / 1000;
+       latsec = latval % 60;
+       latval = latval / 60;
+       latmin = latval % 60;
+       latval = latval / 60;
+       latdeg = latval;
+
+       if (longval < 0) {
+               eastwest = 'W';
+               longval = -longval;
+       } else
+               eastwest = 'E';
+
+       longsecfrac = longval % 1000;
+       longval = longval / 1000;
+       longsec = longval % 60;
+       longval = longval / 60;
+       longmin = longval % 60;
+       longval = longval / 60;
+       longdeg = longval;
+
+       altfrac = altval % 100;
+       altmeters = (altval / 100) * altsign;
+
+       if ((sizestr = strdup(precsize_ntoa(sizeval))) == NULL)
+               sizestr = error;
+       if ((hpstr = strdup(precsize_ntoa(hpval))) == NULL)
+               hpstr = error;
+       if ((vpstr = strdup(precsize_ntoa(vpval))) == NULL)
+               vpstr = error;
+
+       sprintf(ascii,
+             "%d %.2d %.2d.%.3d %c %d %.2d %.2d.%.3d %c %d.%.2dm %sm %sm %sm",
+               latdeg, latmin, latsec, latsecfrac, northsouth,
+               longdeg, longmin, longsec, longsecfrac, eastwest,
+               altmeters, altfrac, sizestr, hpstr, vpstr);
+
+       if (sizestr != error)
+               free(sizestr);
+       if (hpstr != error)
+               free(hpstr);
+       if (vpstr != error)
+               free(vpstr);
+
+       return (ascii);
+}
+
+
+/* Return the number of DNS hierarchy levels in the name. */
+int
+__dn_count_labels(name)
+       char *name;
+{
+       int i, len, count;
+
+       len = strlen(name);
+
+       for(i = 0, count = 0; i < len; i++) {
+               if (name[i] == '.')
+                       count++;
+       }
+
+       /* don't count initial wildcard */
+       if (name[0] == '*')
+               if (count)
+                       count--;
+
+       /* don't count the null label for root. */
+       /* if terminating '.' not found, must adjust */
+       /* count to include last label */
+       if (len > 0 && name[len-1] != '.')
+               count++;
+       return (count);
+}
+
+
+/* 
+ * Make dates expressed in seconds-since-Jan-1-1970 easy to read.  
+ * SIG records are required to be printed like this, by the Secure DNS RFC.
+ */
+char *
+__p_secstodate (secs)
+       unsigned long secs;
+{
+       static char output[15];         /* YYYYMMDDHHMMSS and null */
+       time_t clock = secs;
+       struct tm *time;
+       
+       time = gmtime(&clock);
+       time->tm_year += 1900;
+       time->tm_mon += 1;
+       sprintf(output, "%04d%02d%02d%02d%02d%02d",
+               time->tm_year, time->tm_mon, time->tm_mday,
+               time->tm_hour, time->tm_min, time->tm_sec);
+       return (output);
+}
diff --git a/bindlib_w32/res_init.c b/bindlib_w32/res_init.c
new file mode 100644 (file)
index 0000000..12a979e
--- /dev/null
@@ -0,0 +1,685 @@
+/*
+ * ++Copyright++ 1985, 1989, 1993
+ * -
+ * Copyright (c) 1985, 1989, 1993
+ *    The Regents of the University of California.  All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ * 
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93";
+static char rcsid[] = "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#ifndef WINNT
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <netinet/in.h>
+#endif /* WINNT */
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+
+#include <stdio.h>
+#include <ctype.h>
+#include <resolv.h>
+#if defined(BSD) && (BSD >= 199103)
+# include <unistd.h>
+# include <stdlib.h>
+# include <string.h>
+#else
+#include "conf/portability.h"
+#endif
+
+#ifdef WINNT
+#include <netdb.h>
+#include "conf/portability.h"
+extern char *pathresconf;
+extern int res_paths_initialized;
+extern init_res_paths();
+#endif
+
+/*-------------------------------------- info about "sortlist" --------------
+ * Marc Majka          1994/04/16
+ * Allan Nathanson     1994/10/29 (BIND 4.9.3.x)
+ *
+ * NetInfo resolver configuration directory support.
+ *
+ * Allow a NetInfo directory to be created in the hierarchy which
+ * contains the same information as the resolver configuration file.
+ *
+ * - The local domain name is stored as the value of the "domain" property.
+ * - The Internet address(es) of the name server(s) are stored as values
+ *   of the "nameserver" property.
+ * - The name server addresses are stored as values of the "nameserver"
+ *   property.
+ * - The search list for host-name lookup is stored as values of the
+ *   "search" property.
+ * - The sortlist comprised of IP address netmask pairs are stored as
+ *   values of the "sortlist" property. The IP address and optional netmask
+ *   should be seperated by a slash (/) or ampersand (&) character.
+ * - Internal resolver variables can be set from the value of the "options"
+ *   property.
+ */
+#if defined(NeXT)
+#  include <netinfo/ni.h>
+#  define NI_PATH_RESCONF "/locations/resolver"
+#  define NI_TIMEOUT 10
+static int netinfo_res_init __P((int *haveenv, int *havesearch));
+#endif
+
+#if defined(USE_OPTIONS_H)
+# include "conf/options.h"
+#endif
+
+static void res_setoptions __P((char *, char *));
+
+#ifdef RESOLVSORT
+static const char sort_mask[] = "/&";
+#define ISSORTMASK(ch) (strchr(sort_mask, ch) != NULL)
+static u_int32_t net_mask __P((struct in_addr));
+#endif
+
+#if !defined(isascii)  /* XXX - could be a function */
+# define isascii(c) (!(c & 0200))
+#endif
+
+/*
+ * Resolver state default settings.
+ */
+
+struct __res_state _res
+# if defined(__BIND_RES_TEXT)
+       = { RES_TIMEOUT, }      /* Motorola, et al. */
+# endif
+       ;
+
+/*
+ * Set up default settings.  If the configuration file exist, the values
+ * there will have precedence.  Otherwise, the server address is set to
+ * INADDR_ANY and the default domain name comes from the gethostname().
+ *
+ * An interrim version of this code (BIND 4.9, pre-4.4BSD) used 127.0.0.1
+ * rather than INADDR_ANY ("0.0.0.0") as the default name server address
+ * since it was noted that INADDR_ANY actually meant ``the first interface
+ * you "ifconfig"'d at boot time'' and if this was a SLIP or PPP interface,
+ * it had to be "up" in order for you to reach your own name server.  It
+ * was later decided that since the recommended practice is to always 
+ * install local static routes through 127.0.0.1 for all your network
+ * interfaces, that we could solve this problem without a code change.
+ *
+ * The configuration file should always be used, since it is the only way
+ * to specify a default domain.  If you are running a server on your local
+ * machine, you should say "nameserver 0.0.0.0" or "nameserver 127.0.0.1"
+ * in the configuration file.
+ *
+ * Return 0 if completes successfully, -1 on error
+ */
+int
+res_init()
+{
+       register FILE *fp;
+       register char *cp, **pp;
+       register int n;
+       char buf[MAXDNAME];
+       int nserv = 0;    /* number of nameserver records read from file */
+       int haveenv = 0;
+       int havesearch = 0;
+#ifdef RESOLVSORT
+       int nsort = 0;
+       char *net;
+#endif
+#ifndef RFC1535
+       int dots;
+#endif
+
+
+#ifdef WINNT
+       WORD wVersionRequested;
+       WSADATA wsaData;
+
+       wVersionRequested = MAKEWORD(1,1);
+       if (WSAStartup(wVersionRequested, &wsaData)) {
+               syslog(LOG_ERR, "No useable winsock.dll: %m");
+               return (-1);
+       }
+#endif /* WINNT */
+
+       /*
+        * These three fields used to be statically initialized.  This made
+        * it hard to use this code in a shared library.  It is necessary,
+        * now that we're doing dynamic initialization here, that we preserve
+        * the old semantics: if an application modifies one of these three
+        * fields of _res before res_init() is called, res_init() will not
+        * alter them.  Of course, if an application is setting them to
+        * _zero_ before calling res_init(), hoping to override what used
+        * to be the static default, we can't detect it and unexpected results
+        * will follow.  Zero for any of these fields would make no sense,
+        * so one can safely assume that the applications were already getting
+        * unexpected results.
+        *
+        * _res.options is tricky since some apps were known to diddle the bits
+        * before res_init() was first called. We can't replicate that semantic
+        * with dynamic initialization (they may have turned bits off that are
+        * set in RES_DEFAULT).  Our solution is to declare such applications
+        * "broken".  They could fool us by setting RES_INIT but none do (yet).
+        */
+       if (!_res.retrans)
+               _res.retrans = RES_TIMEOUT;
+       if (!_res.retry)
+               _res.retry = 4;
+       if (!(_res.options & RES_INIT))
+               _res.options = RES_DEFAULT;
+
+       /*
+        * This one used to initialize implicitly to zero, so unless the app
+        * has set it to something in particular, we can randomize it now.
+        */
+       if (!_res.id)
+               _res.id = res_randomid();
+
+#ifdef USELOOPBACK
+       _res.nsaddr.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1);
+#else
+       _res.nsaddr.sin_addr.s_addr = INADDR_ANY;
+#endif
+       _res.nsaddr.sin_family = AF_INET;
+       _res.nsaddr.sin_port = htons(NAMESERVER_PORT);
+       _res.nscount = 1;
+       _res.ndots = 1;
+       _res.pfcode = 0;
+
+       /* Allow user to override the local domain definition */
+       if ((cp = getenv("LOCALDOMAIN")) != NULL) {
+               (void)strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1);
+               haveenv++;
+
+               /*
+                * Set search list to be blank-separated strings
+                * from rest of env value.  Permits users of LOCALDOMAIN
+                * to still have a search list, and anyone to set the
+                * one that they want to use as an individual (even more
+                * important now that the rfc1535 stuff restricts searches)
+                */
+               cp = _res.defdname;
+               pp = _res.dnsrch;
+               *pp++ = cp;
+               for (n = 0; *cp && pp < _res.dnsrch + MAXDNSRCH; cp++) {
+                       if (*cp == '\n')        /* silly backwards compat */
+                               break;
+                       else if (*cp == ' ' || *cp == '\t') {
+                               *cp = 0;
+                               n = 1;
+                       } else if (n) {
+                               *pp++ = cp;
+                               n = 0;
+                               havesearch = 1;
+                       }
+               }
+               /* null terminate last domain if there are excess */
+               while (*cp != '\0' && *cp != ' ' && *cp != '\t' && *cp != '\n')
+                       cp++;
+               *cp = '\0';
+               *pp++ = 0;
+       }
+
+#define        MATCH(line, name) \
+       (!strncmp(line, name, sizeof(name) - 1) && \
+       (line[sizeof(name) - 1] == ' ' || \
+        line[sizeof(name) - 1] == '\t'))
+
+#ifdef NeXT
+       if (netinfo_res_init(&haveenv, &havesearch) == 0)
+#endif
+#ifndef WINNT
+       if ((fp = fopen(_PATH_RESCONF, "r")) != NULL) {
+#else
+       if (!res_paths_initialized)
+         init_res_paths();
+
+       if ((fp = fopen(pathresconf, "r")) != NULL) {
+
+#endif
+           /* read the config file */
+           while (fgets(buf, sizeof(buf), fp) != NULL) {
+               /* skip comments */
+               if (*buf == ';' || *buf == '#')
+                       continue;
+               /* read default domain name */
+               if (MATCH(buf, "domain")) {
+                   if (haveenv)        /* skip if have from environ */
+                           continue;
+                   cp = buf + sizeof("domain") - 1;
+                   while (*cp == ' ' || *cp == '\t')
+                           cp++;
+                   if ((*cp == '\0') || (*cp == '\n'))
+                           continue;
+                   strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1);
+                   if ((cp = strpbrk(_res.defdname, " \t\n")) != NULL)
+                           *cp = '\0';
+                   havesearch = 0;
+                   continue;
+               }
+               /* set search list */
+               if (MATCH(buf, "search")) {
+                   if (haveenv)        /* skip if have from environ */
+                           continue;
+                   cp = buf + sizeof("search") - 1;
+                   while (*cp == ' ' || *cp == '\t')
+                           cp++;
+                   if ((*cp == '\0') || (*cp == '\n'))
+                           continue;
+                   strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1);
+                   if ((cp = strchr(_res.defdname, '\n')) != NULL)
+                           *cp = '\0';
+                   /*
+                    * Set search list to be blank-separated strings
+                    * on rest of line.
+                    */
+                   cp = _res.defdname;
+                   pp = _res.dnsrch;
+                   *pp++ = cp;
+                   for (n = 0; *cp && pp < _res.dnsrch + MAXDNSRCH; cp++) {
+                           if (*cp == ' ' || *cp == '\t') {
+                                   *cp = 0;
+                                   n = 1;
+                           } else if (n) {
+                                   *pp++ = cp;
+                                   n = 0;
+                           }
+                   }
+                   /* null terminate last domain if there are excess */
+                   while (*cp != '\0' && *cp != ' ' && *cp != '\t')
+                           cp++;
+                   *cp = '\0';
+                   *pp++ = 0;
+                   havesearch = 1;
+                   continue;
+               }
+               /* read nameservers to query */
+               if (MATCH(buf, "nameserver") && nserv < MAXNS) {
+                   struct in_addr a;
+
+                   cp = buf + sizeof("nameserver") - 1;
+                   while (*cp == ' ' || *cp == '\t')
+                       cp++;
+                   if ((*cp != '\0') && (*cp != '\n') && inet_aton(cp, &a)) {
+                       _res.nsaddr_list[nserv].sin_addr = a;
+                       _res.nsaddr_list[nserv].sin_family = AF_INET;
+                       _res.nsaddr_list[nserv].sin_port =
+                               htons(NAMESERVER_PORT);
+                       nserv++;
+                   }
+                   continue;
+               }
+#ifdef RESOLVSORT
+               if (MATCH(buf, "sortlist")) {
+                   struct in_addr a;
+
+                   cp = buf + sizeof("sortlist") - 1;
+                   while (nsort < MAXRESOLVSORT) {
+                       while (*cp == ' ' || *cp == '\t')
+                           cp++;
+                       if (*cp == '\0' || *cp == '\n' || *cp == ';')
+                           break;
+                       net = cp;
+                       while (*cp && !ISSORTMASK(*cp) && *cp != ';' &&
+                              isascii(*cp) && !isspace(*cp))
+                               cp++;
+                       n = *cp;
+                       *cp = 0;
+                       if (inet_aton(net, &a)) {
+                           _res.sort_list[nsort].addr = a;
+                           if (ISSORTMASK(n)) {
+                               *cp++ = n;
+                               net = cp;
+                               while (*cp && *cp != ';' &&
+                                       isascii(*cp) && !isspace(*cp))
+                                   cp++;
+                               n = *cp;
+                               *cp = 0;
+                               if (inet_aton(net, &a)) {
+                                   _res.sort_list[nsort].mask = a.s_addr;
+                               } else {
+                                   _res.sort_list[nsort].mask = 
+                                       net_mask(_res.sort_list[nsort].addr);
+                               }
+                           } else {
+                               _res.sort_list[nsort].mask = 
+                                   net_mask(_res.sort_list[nsort].addr);
+                           }
+                           nsort++;
+                       }
+                       *cp = n;
+                   }
+                   continue;
+               }
+#endif
+               if (MATCH(buf, "options")) {
+                   res_setoptions(buf + sizeof("options") - 1, "conf");
+                   continue;
+               }
+           }
+           if (nserv > 1) 
+               _res.nscount = nserv;
+#ifdef RESOLVSORT
+           _res.nsort = nsort;
+#endif
+           (void) fclose(fp);
+       }
+       if (_res.defdname[0] == 0 &&
+           gethostname(buf, sizeof(_res.defdname) - 1) == 0 &&
+           (cp = strchr(buf, '.')) != NULL)
+               strcpy(_res.defdname, cp + 1);
+
+       /* find components of local domain that might be searched */
+       if (havesearch == 0) {
+               pp = _res.dnsrch;
+               *pp++ = _res.defdname;
+               *pp = NULL;
+
+#ifndef RFC1535
+               dots = 0;
+               for (cp = _res.defdname; *cp; cp++)
+                       dots += (*cp == '.');
+
+               cp = _res.defdname;
+               while (pp < _res.dnsrch + MAXDFLSRCH) {
+                       if (dots < LOCALDOMAINPARTS)
+                               break;
+                       cp = strchr(cp, '.') + 1;    /* we know there is one */
+                       *pp++ = cp;
+                       dots--;
+               }
+               *pp = NULL;
+#ifdef DEBUG
+               if (_res.options & RES_DEBUG) {
+                       printf(";; res_init()... default dnsrch list:\n");
+                       for (pp = _res.dnsrch; *pp; pp++)
+                               printf(";;\t%s\n", *pp);
+                       printf(";;\t..END..\n");
+               }
+#endif /* DEBUG */
+#endif /* !RFC1535 */
+       }
+
+       if ((cp = getenv("RES_OPTIONS")) != NULL)
+               res_setoptions(cp, "env");
+       _res.options |= RES_INIT;
+       return (0);
+}
+
+static void
+res_setoptions(options, source)
+       char *options, *source;
+{
+       char *cp = options;
+       int i;
+
+#ifdef DEBUG
+       if (_res.options & RES_DEBUG)
+               printf(";; res_setoptions(\"%s\", \"%s\")...\n",
+                      options, source);
+#endif
+       while (*cp) {
+               /* skip leading and inner runs of spaces */
+               while (*cp == ' ' || *cp == '\t')
+                       cp++;
+               /* search for and process individual options */
+               if (!strncmp(cp, "ndots:", sizeof("ndots:") - 1)) {
+                       i = atoi(cp + sizeof("ndots:") - 1);
+                       if (i <= RES_MAXNDOTS)
+                               _res.ndots = i;
+                       else
+                               _res.ndots = RES_MAXNDOTS;
+#ifdef DEBUG
+                       if (_res.options & RES_DEBUG)
+                               printf(";;\tndots=%d\n", _res.ndots);
+#endif
+               } else if (!strncmp(cp, "debug", sizeof("debug") - 1)) {
+#ifdef DEBUG
+                       if (!(_res.options & RES_DEBUG)) {
+                               printf(";; res_setoptions(\"%s\", \"%s\")..\n",
+                                      options, source);
+                               _res.options |= RES_DEBUG;
+                       }
+                       printf(";;\tdebug\n");
+#endif
+               } else if (!strncmp(cp, "inet6", sizeof("inet6") - 1)) {
+                       _res.options |= RES_USE_INET6;
+               } else {
+                       /* XXX - print a warning here? */
+               }
+               /* skip to next run of spaces */
+               while (*cp && *cp != ' ' && *cp != '\t')
+                       cp++;
+       }
+}
+
+#ifdef RESOLVSORT
+/* XXX - should really support CIDR which means explicit masks always. */
+static u_int32_t
+net_mask(in)           /* XXX - should really use system's version of this */
+       struct in_addr in;
+{
+       register u_int32_t i = ntohl(in.s_addr);
+
+       if (IN_CLASSA(i))
+               return (htonl(IN_CLASSA_NET));
+       else if (IN_CLASSB(i))
+               return (htonl(IN_CLASSB_NET));
+       return (htonl(IN_CLASSC_NET));
+}
+#endif
+
+#ifdef NeXT
+static int
+netinfo_res_init(haveenv, havesearch)
+       int *haveenv;
+       int *havesearch;
+{
+    register   int n;
+    void       *domain, *parent;
+    ni_id      dir;
+    ni_status  status;
+    ni_namelist        nl;
+    int                nserv = 0;
+#ifdef RESOLVSORT
+    int                nsort = 0;
+#endif
+
+    status = ni_open(NULL, ".", &domain);
+    if (status == NI_OK) {
+       ni_setreadtimeout(domain, NI_TIMEOUT);
+       ni_setabort(domain, 1);
+
+       /* climb the NetInfo hierarchy to find a resolver directory */
+       while (status == NI_OK) {
+           status = ni_pathsearch(domain, &dir, NI_PATH_RESCONF);
+           if (status == NI_OK) {
+           /* found a resolver directory */
+
+               if (*haveenv == 0) {
+                   /* get the default domain name */
+                   status = ni_lookupprop(domain, &dir, "domain", &nl);
+                   if (status == NI_OK && nl.ni_namelist_len > 0) {
+                       (void)strncpy(_res.defdname,
+                                     nl.ni_namelist_val[0],
+                                     sizeof(_res.defdname) - 1);
+                       _res.defdname[sizeof(_res.defdname) - 1] = '\0';
+                       ni_namelist_free(&nl);
+                       *havesearch = 0;
+                   }
+
+                   /* get search list */
+                   status = ni_lookupprop(domain, &dir, "search", &nl);
+                   if (status == NI_OK && nl.ni_namelist_len > 0) {
+                       (void)strncpy(_res.defdname,
+                                     nl.ni_namelist_val[0],
+                                     sizeof(_res.defdname) - 1);
+                       _res.defdname[sizeof(_res.defdname) - 1] = '\0';
+                       /* copy  */
+                       for (n = 0;
+                            n < nl.ni_namelist_len && n < MAXDNSRCH;
+                            n++) {
+                            /* duplicate up to MAXDNSRCH servers */
+                            char *cp = nl.ni_namelist_val[n];
+                           _res.dnsrch[n] =
+                               strcpy((char *)malloc(strlen(cp) + 1), cp);
+                       }
+                       ni_namelist_free(&nl);
+                       *havesearch = 1;
+                   }
+               }
+
+               /* get list of nameservers */
+               status = ni_lookupprop(domain, &dir, "nameserver", &nl);
+               if (status == NI_OK && nl.ni_namelist_len > 0) {
+                   /* copy up to MAXNS servers */
+                   for (n = 0;
+                        n < nl.ni_namelist_len && nserv < MAXNS;
+                        n++) {
+                       struct in_addr a;
+
+                       if (inet_aton(nl.ni_namelist_val[n], &a)) {
+                           _res.nsaddr_list[nserv].sin_addr = a;
+                           _res.nsaddr_list[nserv].sin_family = AF_INET;
+                           _res.nsaddr_list[nserv].sin_port =
+                               htons(NAMESERVER_PORT);
+                           nserv++;
+                       }
+                   }
+                   ni_namelist_free(&nl);
+               }
+               
+               if (nserv > 1)
+                   _res.nscount = nserv;
+
+#ifdef RESOLVSORT
+               /* get sort order */
+               status = ni_lookupprop(domain, &dir, "sortlist", &nl);
+               if (status == NI_OK && nl.ni_namelist_len > 0) {
+
+                   /* copy up to MAXRESOLVSORT address/netmask pairs */
+                   for (n = 0;
+                        n < nl.ni_namelist_len && nsort < MAXRESOLVSORT;
+                        n++) {
+                       char ch;
+                       char *cp;
+                       const char *sp;
+                       struct in_addr a;
+
+                       cp = NULL;
+                       for (sp = sort_mask; *sp; sp++) {
+                               char *cp1;
+                               cp1 = strchr(nl.ni_namelist_val[n], *sp);
+                               if (cp && cp1)
+                                       cp = (cp < cp1)? cp : cp1;
+                               else if (cp1)
+                                       cp = cp1;
+                       }
+                       if (cp != NULL) {
+                               ch = *cp;
+                               *cp = '\0';
+                               break;
+                       }
+                       if (inet_aton(nl.ni_namelist_val[n], &a)) {
+                           _res.sort_list[nsort].addr = a;
+                           if (*cp && ISSORTMASK(ch)) {
+                               *cp++ = ch;
+                               if (inet_aton(cp, &a)) {
+                                   _res.sort_list[nsort].mask = a.s_addr;
+                               } else {
+                                   _res.sort_list[nsort].mask =
+                                       net_mask(_res.sort_list[nsort].addr);
+                               }
+                           } else {
+                               _res.sort_list[nsort].mask =
+                                   net_mask(_res.sort_list[nsort].addr);
+                           }
+                           nsort++;
+                       }
+                   }
+                   ni_namelist_free(&nl);
+               }
+
+               _res.nsort = nsort;
+#endif
+
+               /* get resolver options */
+               status = ni_lookupprop(domain, &dir, "options", &nl);
+               if (status == NI_OK && nl.ni_namelist_len > 0) {
+                   res_setoptions(nl.ni_namelist_val[0], "conf");
+                   ni_namelist_free(&nl);
+               }
+
+               ni_free(domain);
+               return(1);      /* using DNS configuration from NetInfo */
+           }
+
+           status = ni_open(domain, "..", &parent);
+           ni_free(domain);
+           if (status == NI_OK)
+               domain = parent;
+       }
+    }
+    return(0); /* if not using DNS configuration from NetInfo */
+}
+#endif /* NeXT */
+
+u_int
+res_randomid()
+{
+       struct timeval now;
+
+       gettimeofday(&now, NULL);
+       return (0xffff & (now.tv_sec ^ now.tv_usec ^ getpid()));
+}
diff --git a/bindlib_w32/res_mkquery.c b/bindlib_w32/res_mkquery.c
new file mode 100644 (file)
index 0000000..ef86ed7
--- /dev/null
@@ -0,0 +1,196 @@
+/*
+ * ++Copyright++ 1985, 1993
+ * -
+ * Copyright (c) 1985, 1993
+ *    The Regents of the University of California.  All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ * 
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)res_mkquery.c      8.1 (Berkeley) 6/4/93";
+static char rcsid[] = "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#ifndef WINNT
+#include <sys/param.h>
+#include <netinet/in.h>
+#endif
+#include <arpa/nameser.h>
+
+#include <stdio.h>
+#include <netdb.h>
+#include <resolv.h>
+#if defined(BSD) && (BSD >= 199103)
+# include <string.h>
+#else
+# include "conf/portability.h"
+#endif
+
+#if defined(USE_OPTIONS_H)
+# include <conf/options.h>
+#endif
+
+/*
+ * Form all types of queries.
+ * Returns the size of the result or -1.
+ */
+int
+res_mkquery(op, dname, class, type, data, datalen, newrr_in, buf, buflen)
+       int op;                 /* opcode of query */
+       const char *dname;      /* domain name */
+       int class, type;        /* class and type of query */
+       const u_char *data;     /* resource record data */
+       int datalen;            /* length of data */
+       const u_char *newrr_in; /* new rr for modify or append */
+       u_char *buf;            /* buffer to put query */
+       int buflen;             /* size of buffer */
+{
+       register HEADER *hp;
+       register u_char *cp;
+       register int n;
+       u_char *dnptrs[20], **dpp, **lastdnptr;
+
+       if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+#ifndef WINNT
+               h_errno = NETDB_INTERNAL;
+#else
+               WSASetLastError(NETDB_INTERNAL);
+#endif
+               return (-1);
+       }
+#ifdef DEBUG
+       if (_res.options & RES_DEBUG)
+               printf(";; res_mkquery(%d, %s, %d, %d)\n",
+                      op, dname, class, type);
+#endif
+       /*
+        * Initialize header fields.
+        */
+       if ((buf == NULL) || (buflen < HFIXEDSZ))
+               return (-1);
+       bzero(buf, HFIXEDSZ);
+       hp = (HEADER *) buf;
+       hp->id = htons(++_res.id);
+       hp->opcode = op;
+       hp->rd = (_res.options & RES_RECURSE) != 0;
+       hp->rcode = NOERROR;
+       cp = buf + HFIXEDSZ;
+       buflen -= HFIXEDSZ;
+       dpp = dnptrs;
+       *dpp++ = buf;
+       *dpp++ = NULL;
+       lastdnptr = dnptrs + sizeof dnptrs / sizeof dnptrs[0];
+       /*
+        * perform opcode specific processing
+        */
+       switch (op) {
+       case QUERY:     /*FALLTHROUGH*/
+       case NS_NOTIFY_OP:
+               if ((buflen -= QFIXEDSZ) < 0)
+                       return (-1);
+               if ((n = dn_comp(dname, cp, buflen, dnptrs, lastdnptr)) < 0)
+                       return (-1);
+               cp += n;
+               buflen -= n;
+               __putshort(type, cp);
+               cp += INT16SZ;
+               __putshort(class, cp);
+               cp += INT16SZ;
+               hp->qdcount = htons(1);
+               if (op == QUERY || data == NULL)
+                       break;
+               /*
+                * Make an additional record for completion domain.
+                */
+               buflen -= RRFIXEDSZ;
+               n = dn_comp((char *)data, cp, buflen, dnptrs, lastdnptr);
+               if (n < 0)
+                       return (-1);
+               cp += n;
+               buflen -= n;
+               __putshort(T_NULL, cp);
+               cp += INT16SZ;
+               __putshort(class, cp);
+               cp += INT16SZ;
+               __putlong(0, cp);
+               cp += INT32SZ;
+               __putshort(0, cp);
+               cp += INT16SZ;
+               hp->arcount = htons(1);
+               break;
+
+       case IQUERY:
+               /*
+                * Initialize answer section
+                */
+               if (buflen < 1 + RRFIXEDSZ + datalen)
+                       return (-1);
+               *cp++ = '\0';   /* no domain name */
+               __putshort(type, cp);
+               cp += INT16SZ;
+               __putshort(class, cp);
+               cp += INT16SZ;
+               __putlong(0, cp);
+               cp += INT32SZ;
+               __putshort(datalen, cp);
+               cp += INT16SZ;
+               if (datalen) {
+                       bcopy(data, cp, datalen);
+                       cp += datalen;
+               }
+               hp->ancount = htons(1);
+               break;
+
+       default:
+               return (-1);
+       }
+       return (cp - buf);
+}
diff --git a/bindlib_w32/res_nt_misc.c b/bindlib_w32/res_nt_misc.c
new file mode 100644 (file)
index 0000000..90b4044
--- /dev/null
@@ -0,0 +1,48 @@
+/* this function for Windows NT specific resolver stuff L. Kahn */
+
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <resolv.h>
+#include <netdb.h>
+#include "conf/portability.h"
+
+char *pathnetworks, *pathhosts, *pathresconf;
+int res_paths_initialized = 0;
+
+
+/* lgk new function to initialize path variables that are outside the scope of the main */
+/* for backwards compatibility allow either resolv.conf or resolv.ini */
+void init_res_paths()
+{
+   FILE *fp;
+   
+       pathhosts = (char *)malloc(MAX_PATH);
+       if (!ExpandEnvironmentStrings(_PATH_HOSTS, pathhosts, MAX_PATH)) 
+               syslog(LOG_ERR, "ExpandEnvironmentStrings(_PATH_HOSTS) failed: %m\n");
+
+       pathnetworks = (char *)malloc(MAX_PATH);
+       if (!ExpandEnvironmentStrings(_PATH_NETWORKS, pathnetworks, MAX_PATH))
+               syslog(LOG_ERR, "ExpandEnvironmentStrings(_PATH_NETWORKS) failed: %m\n");
+
+       pathresconf = (char *)malloc(MAX_PATH);
+       if (!ExpandEnvironmentStrings(_PATH_RESCONF, pathresconf, MAX_PATH)) 
+               syslog(LOG_ERR, "ExpandEnvironmentStrings(_PATH_RESCONF) failed: %m\n");
+
+       else
+          {
+            if ((fp = fopen(pathresconf, "r")) == NULL)
+              {
+                /* try alternate name */
+               if (!ExpandEnvironmentStrings(_ALT_PATH_RESCONF, pathresconf, MAX_PATH)) 
+                 syslog(LOG_ERR, "ExpandEnvironmentStrings(_ALT_PATH_RESCONF) failed: %m\n");
+              }
+            else fclose(fp);
+         }
+
+               
+    res_paths_initialized = 1;
+}
+
+
diff --git a/bindlib_w32/res_query.c b/bindlib_w32/res_query.c
new file mode 100644 (file)
index 0000000..75409d7
--- /dev/null
@@ -0,0 +1,473 @@
+/*
+ * ++Copyright++ 1988, 1993
+ * -
+ * Copyright (c) 1988, 1993
+ *    The Regents of the University of California.  All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ * 
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)res_query.c        8.1 (Berkeley) 6/4/93";
+static char rcsid[] = "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#ifndef WINNT
+#include <sys/param.h>
+#include <netinet/in.h>
+#endif
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+
+#include <stdio.h>
+#include <netdb.h>
+#include <resolv.h>
+#include <ctype.h>
+#include <errno.h>
+#if defined(BSD) && (BSD >= 199306)
+# include <stdlib.h>
+# include <string.h>
+#else
+# include "conf/portability.h"
+#endif
+
+#if defined(USE_OPTIONS_H)
+# include <conf/options.h>
+#endif
+
+#if PACKETSZ > 1024
+#define MAXPACKET      PACKETSZ
+#else
+#define MAXPACKET      1024
+#endif
+
+const char *hostalias __P((const char *));
+#ifndef WINNT
+int h_errno;
+#endif
+
+/*
+ * Formulate a normal query, send, and await answer.
+ * Returned answer is placed in supplied buffer "answer".
+ * Perform preliminary check of answer, returning success only
+ * if no error is indicated and the answer count is nonzero.
+ * Return the size of the response on success, -1 on error.
+ * Error number is left in h_errno.
+ *
+ * Caller must parse answer and determine whether it answers the question.
+ */
+int
+res_query(name, class, type, answer, anslen)
+       const char *name;       /* domain name */
+       int class, type;        /* class and type of query */
+       u_char *answer;         /* buffer to put answer */
+       int anslen;             /* size of answer buffer */
+{
+       u_char buf[MAXPACKET];
+       register HEADER *hp = (HEADER *) answer;
+       int n;
+
+       hp->rcode = NOERROR;    /* default */
+
+       if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+#ifndef WINNT
+               h_errno = NETDB_INTERNAL;
+#else
+               WSASetLastError(NETDB_INTERNAL);
+#endif
+               return (-1);
+       }
+#ifdef DEBUG
+       if (_res.options & RES_DEBUG)
+               printf(";; res_query(%s, %d, %d)\n", name, class, type);
+#endif
+
+       n = res_mkquery(QUERY, name, class, type, NULL, 0, NULL,
+                       buf, sizeof(buf));
+       if (n <= 0) {
+#ifdef DEBUG
+               if (_res.options & RES_DEBUG)
+                       printf(";; res_query: mkquery failed\n");
+#endif
+#ifndef WINNT
+               h_errno = NO_RECOVERY;
+#else
+               WSASetLastError(NO_RECOVERY);
+#endif
+               return (n);
+       }
+       n = res_send(buf, n, answer, anslen);
+       if (n < 0) {
+#ifdef DEBUG
+               if (_res.options & RES_DEBUG)
+                       printf(";; res_query: send error\n");
+#endif
+#ifndef WINNT
+               h_errno = TRY_AGAIN;
+#else
+               WSASetLastError(TRY_AGAIN);
+#endif
+               return (n);
+       }
+
+       if (hp->rcode != NOERROR || ntohs( (u_short) hp->ancount) == 0) {
+#ifdef DEBUG
+               if (_res.options & RES_DEBUG)
+                       printf(";; rcode = %d, ancount=%d\n", hp->rcode,
+                           ntohs( (u_short) hp->ancount));
+#endif
+               switch (hp->rcode) {
+               case NXDOMAIN:
+#ifndef WINNT
+                       h_errno = HOST_NOT_FOUND;
+#else
+                       WSASetLastError(HOST_NOT_FOUND);
+#endif
+                       break;
+               case SERVFAIL:
+#ifndef WINNT
+                       h_errno = TRY_AGAIN;
+#else
+                       WSASetLastError(TRY_AGAIN);
+#endif
+                       break;
+               case NOERROR:
+#ifndef WINNT
+                       h_errno = NO_DATA;
+#else
+                       WSASetLastError(NO_DATA);
+#endif
+                       break;
+               case FORMERR:
+               case NOTIMP:
+               case REFUSED:
+               default:
+#ifndef WINNT
+                       h_errno = NO_RECOVERY;
+#else
+                       WSASetLastError(NO_RECOVERY);
+#endif
+                       break;
+               }
+               return (-1);
+       }
+       return (n);
+}
+
+/*
+ * Formulate a normal query, send, and retrieve answer in supplied buffer.
+ * Return the size of the response on success, -1 on error.
+ * If enabled, implement search rules until answer or unrecoverable failure
+ * is detected.  Error code, if any, is left in h_errno.
+ */
+int
+res_search(name, class, type, answer, anslen)
+       const char *name;       /* domain name */
+       int class, type;        /* class and type of query */
+       u_char *answer;         /* buffer to put answer */
+       int anslen;             /* size of answer */
+{
+       register const char *cp, * const *domain;
+       HEADER *hp = (HEADER *) answer;
+       u_int dots;
+       int trailing_dot, ret, saved_herrno;
+       int got_nodata = 0, got_servfail = 0, tried_as_is = 0;
+
+       if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+#ifndef WINNT
+               h_errno = NETDB_INTERNAL;
+#else
+               WSASetLastError(NETDB_INTERNAL);
+#endif
+               return (-1);
+       }
+#ifndef WINNT
+       errno = 0;
+       h_errno = HOST_NOT_FOUND;       /* default, if we never query */
+#else
+       WSASetLastError(HOST_NOT_FOUND);
+       SetLastError(0);
+#endif
+       dots = 0;
+       for (cp = name; *cp; cp++)
+               dots += (*cp == '.');
+       trailing_dot = 0;
+       if (cp > name && *--cp == '.')
+               trailing_dot++;
+
+       /*
+        * if there aren't any dots, it could be a user-level alias
+        */
+       if (!dots && (cp = __hostalias(name)) != NULL)
+               return (res_query(cp, class, type, answer, anslen));
+
+       /*
+        * If there are dots in the name already, let's just give it a try
+        * 'as is'.  The threshold can be set with the "ndots" option.
+        */
+       saved_herrno = -1;
+       if (dots >= _res.ndots) {
+               ret = res_querydomain(name, NULL, class, type, answer, anslen);
+               if (ret > 0)
+                       return (ret);
+#ifndef WINNT
+               saved_herrno = h_errno;
+#else
+                saved_herrno = WSAGetLastError();
+#endif
+               tried_as_is++;
+       }
+
+       /*
+        * We do at least one level of search if
+        *      - there is no dot and RES_DEFNAME is set, or
+        *      - there is at least one dot, there is no trailing dot,
+        *        and RES_DNSRCH is set.
+        */
+       if ((!dots && (_res.options & RES_DEFNAMES)) ||
+           (dots && !trailing_dot && (_res.options & RES_DNSRCH))) {
+               int done = 0;
+
+               for (domain = (const char * const *)_res.dnsrch;
+                    *domain && !done;
+                    domain++) {
+
+                       ret = res_querydomain(name, *domain, class, type,
+                                             answer, anslen);
+                       if (ret > 0)
+                               return (ret);
+
+                       /*
+                        * If no server present, give up.
+                        * If name isn't found in this domain,
+                        * keep trying higher domains in the search list
+                        * (if that's enabled).
+                        * On a NO_DATA error, keep trying, otherwise
+                        * a wildcard entry of another type could keep us
+                        * from finding this entry higher in the domain.
+                        * If we get some other error (negative answer or
+                        * server failure), then stop searching up,
+                        * but try the input name below in case it's
+                        * fully-qualified.
+                        */
+                       if (errno == ECONNREFUSED) {
+#ifndef WINNT
+                               h_errno = TRY_AGAIN;
+#else
+                               WSASetLastError(TRY_AGAIN);
+#endif
+                               return (-1);
+                       }
+
+                       switch (h_errno) {
+                       case NO_DATA:
+                               got_nodata++;
+                               /* FALLTHROUGH */
+                       case HOST_NOT_FOUND:
+                               /* keep trying */
+                               break;
+                       case TRY_AGAIN:
+                               if (hp->rcode == SERVFAIL) {
+                                       /* try next search element, if any */
+                                       got_servfail++;
+                                       break;
+                               }
+                               /* FALLTHROUGH */
+                       default:
+                               /* anything else implies that we're done */
+                               done++;
+                       }
+
+                       /* if we got here for some reason other than DNSRCH,
+                        * we only wanted one iteration of the loop, so stop.
+                        */
+                       if (!(_res.options & RES_DNSRCH))
+                               done++;
+               }
+       }
+
+       /* if we have not already tried the name "as is", do that now.
+        * note that we do this regardless of how many dots were in the
+        * name or whether it ends with a dot.
+        */
+       if (!tried_as_is) {
+               ret = res_querydomain(name, NULL, class, type, answer, anslen);
+               if (ret > 0)
+                       return (ret);
+       }
+
+       /* if we got here, we didn't satisfy the search.
+        * if we did an initial full query, return that query's h_errno
+        * (note that we wouldn't be here if that query had succeeded).
+        * else if we ever got a nodata, send that back as the reason.
+        * else send back meaningless h_errno, that being the one from
+        * the last DNSRCH we did.
+        */
+#ifndef WINNT
+       if (saved_herrno != -1)
+               h_errno = saved_herrno;
+       else if (got_nodata)
+               h_errno = NO_DATA;
+       else if (got_servfail)
+               h_errno = TRY_AGAIN;
+#else
+       if (saved_herrno != -1)
+               WSASetLastError(saved_herrno);
+       else if (got_nodata)
+               WSASetLastError(NO_DATA);
+       else if (got_servfail)
+               WSASetLastError(TRY_AGAIN);
+#endif
+       return (-1);
+}
+
+/*
+ * Perform a call on res_query on the concatenation of name and domain,
+ * removing a trailing dot from name if domain is NULL.
+ */
+int
+res_querydomain(name, domain, class, type, answer, anslen)
+       const char *name, *domain;
+       int class, type;        /* class and type of query */
+       u_char *answer;         /* buffer to put answer */
+       int anslen;             /* size of answer */
+{
+       char nbuf[MAXDNAME];
+       const char *longname = nbuf;
+       int n, d;
+
+       if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+#ifndef WINNT
+               h_errno = NETDB_INTERNAL;
+#else
+               WSASetLastError(NETDB_INTERNAL);
+#endif
+               return (-1);
+       }
+#ifdef DEBUG
+       if (_res.options & RES_DEBUG)
+               printf(";; res_querydomain(%s, %s, %d, %d)\n",
+                      name, domain?domain:"<Nil>", class, type);
+#endif
+       if (domain == NULL) {
+               /*
+                * Check for trailing '.';
+                * copy without '.' if present.
+                */
+               n = strlen(name);
+               if (n >= MAXDNAME) {
+#ifndef WINNT
+               h_errno = NO_RECOVERY;
+#else
+               WSASetLastError(NO_RECOVERY);
+#endif
+                       return (-1);
+               }
+               n--;
+               if (n >= 0 && name[n] == '.') {
+                       strncpy(nbuf, name, n);
+                       nbuf[n] = '\0';
+               } else
+                       longname = name;
+       } else {
+               n = strlen(name);
+               d = strlen(domain);
+               if (n + d + 1 >= MAXDNAME) {
+#ifndef WINNT
+               h_errno = NO_RECOVERY;
+#else
+               WSASetLastError(NO_RECOVERY);
+#endif
+                       return (-1);
+               }
+               sprintf(nbuf, "%s.%s", name, domain);
+       }
+       return (res_query(longname, class, type, answer, anslen));
+}
+
+const char *
+hostalias(name)
+       register const char *name;
+{
+       register char *cp1, *cp2;
+       FILE *fp;
+       char *file;
+       char buf[BUFSIZ];
+       static char abuf[MAXDNAME];
+
+       if (_res.options & RES_NOALIASES)
+               return (NULL);
+       file = getenv("HOSTALIASES");
+       if (file == NULL || (fp = fopen(file, "r")) == NULL)
+               return (NULL);
+       setbuf(fp, NULL);
+       buf[sizeof(buf) - 1] = '\0';
+       while (fgets(buf, sizeof(buf), fp)) {
+               for (cp1 = buf; *cp1 && !isspace(*cp1); ++cp1)
+                       ;
+               if (!*cp1)
+                       break;
+               *cp1 = '\0';
+               if (!strcasecmp(buf, name)) {
+                       while (isspace(*++cp1))
+                               ;
+                       if (!*cp1)
+                               break;
+                       for (cp2 = cp1 + 1; *cp2 && !isspace(*cp2); ++cp2)
+                               ;
+                       abuf[sizeof(abuf) - 1] = *cp2 = '\0';
+                       strncpy(abuf, cp1, sizeof(abuf) - 1);
+                       fclose(fp);
+                       return (abuf);
+               }
+       }
+       fclose(fp);
+       return (NULL);
+}
diff --git a/bindlib_w32/res_send.c b/bindlib_w32/res_send.c
new file mode 100644 (file)
index 0000000..670a87e
--- /dev/null
@@ -0,0 +1,970 @@
+/*
+ * ++Copyright++ 1985, 1989, 1993
+ * -
+ * Copyright (c) 1985, 1989, 1993
+ *    The Regents of the University of California.  All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ * 
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)res_send.c 8.1 (Berkeley) 6/4/93";
+static char rcsid[] = "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+       /* change this to "0"
+        * if you talk to a lot
+        * of multi-homed SunOS
+        * ("broken") name servers.
+        */
+#define        CHECK_SRVR_ADDR 1       /* XXX - should be in options.h */
+
+/*
+ * Send query to name server and wait for reply.
+ */
+
+#include <sys/types.h>
+#ifndef WINNT
+#include <sys/param.h>
+#include <sys/time.h>
+#include <sys/socket.h>
+#include <sys/uio.h>
+#include <netinet/in.h>
+#endif
+#include <arpa/nameser.h>
+#include <arpa/inet.h>
+
+#include <stdio.h>
+#include <netdb.h>
+#include <errno.h>
+#include <resolv.h>
+#if defined(BSD) && (BSD >= 199306)
+# include <stdlib.h>
+# include <string.h>
+# include <unistd.h>
+#else
+# include "conf/portability.h"
+#endif
+
+#if defined(USE_OPTIONS_H)
+# include <conf/options.h>
+#endif
+
+#ifndef WINNT
+static int s = -1;     /* socket used for communications */
+#else
+static SOCKET s = INVALID_SOCKET;
+typedef char * caddr_t;
+#endif
+static int connected = 0;      /* is the socket connected */
+static int vc = 0;     /* is the socket a virtual ciruit? */
+
+#ifndef FD_SET
+/* XXX - should be in portability.h */
+#define        NFDBITS         32
+#define        FD_SETSIZE      32
+#define        FD_SET(n, p)    ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
+#define        FD_CLR(n, p)    ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
+#define        FD_ISSET(n, p)  ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
+#define FD_ZERO(p)     bzero((char *)(p), sizeof(*(p)))
+#endif
+
+/* XXX - this should be done in portability.h */
+#if (defined(BSD) && (BSD >= 199103)) || defined(linux)
+# define CAN_RECONNECT 1
+#else
+# define CAN_RECONNECT 0
+#endif
+
+#ifndef DEBUG
+#   define Dprint(cond, args) /*empty*/
+#   define DprintQ(cond, args, query, size) /*empty*/
+#   define Aerror(file, string, error, address) /*empty*/
+#   define Perror(file, string, error) /*empty*/
+#else
+#   define Dprint(cond, args) if (cond) {fprintf args;} else {}
+#   define DprintQ(cond, args, query, size) if (cond) {\
+                       fprintf args;\
+                       __fp_nquery(query, size, stdout);\
+               } else {}
+    static void
+    Aerror(file, string, error, address)
+       FILE *file;
+       char *string;
+       int error;
+       struct sockaddr_in address;
+    {
+       int save = errno;
+
+       if (_res.options & RES_DEBUG) {
+               fprintf(file, "res_send: %s ([%s].%u): %s\n",
+                       string,
+                       inet_ntoa(address.sin_addr),
+                       ntohs(address.sin_port),
+                       strerror(error));
+       }
+#ifndef WINNT
+       errno = save;
+#else
+       WSASetLastError(save);
+       SetLastError(save);
+#endif
+    }
+    static void
+    Perror(file, string, error)
+       FILE *file;
+       char *string;
+       int error;
+    {
+       int save = errno;
+
+       if (_res.options & RES_DEBUG) {
+               fprintf(file, "res_send: %s: %s\n",
+                       string, strerror(error));
+       }
+#ifndef WINNT
+       errno = save;
+#else
+       SetLastError(save);
+#endif
+    }
+#endif
+
+static res_send_qhook Qhook = NULL;
+static res_send_rhook Rhook = NULL;
+
+void
+res_send_setqhook(hook)
+       res_send_qhook hook;
+{
+
+       Qhook = hook;
+}
+
+void
+res_send_setrhook(hook)
+       res_send_rhook hook;
+{
+
+       Rhook = hook;
+}
+
+/* int
+ * res_isourserver(ina)
+ *     looks up "ina" in _res.ns_addr_list[]
+ * returns:
+ *     0  : not found
+ *     >0 : found
+ * author:
+ *     paul vixie, 29may94
+ */
+int
+res_isourserver(inp)
+       const struct sockaddr_in *inp;
+{
+       struct sockaddr_in ina;
+       register int ns, ret;
+
+       ina = *inp;
+       ret = 0;
+       for (ns = 0;  ns < _res.nscount;  ns++) {
+               register const struct sockaddr_in *srv = &_res.nsaddr_list[ns];
+
+               if (srv->sin_family == ina.sin_family &&
+                   srv->sin_port == ina.sin_port &&
+                   (srv->sin_addr.s_addr == INADDR_ANY ||
+                    srv->sin_addr.s_addr == ina.sin_addr.s_addr)) {
+                       ret++;
+                       break;
+               }
+       }
+       return (ret);
+}
+
+/* int
+ * res_nameinquery(name, type, class, buf, eom)
+ *     look for (name,type,class) in the query section of packet (buf,eom)
+ * requires:
+ *     buf + HFIXESDZ <= eom
+ * returns:
+ *     -1 : format error
+ *     0  : not found
+ *     >0 : found
+ * author:
+ *     paul vixie, 29may94
+ */
+int
+res_nameinquery(name, type, class, buf, eom)
+       const char *name;
+       register int type, class;
+       const u_char *buf, *eom;
+{
+       register const u_char *cp = buf + HFIXEDSZ;
+       int qdcount = ntohs( (u_short) ((HEADER*)buf)->qdcount);
+
+       while (qdcount-- > 0) {
+               char tname[MAXDNAME+1];
+               register int n, ttype, tclass;
+
+               n = dn_expand(buf, eom, cp, tname, sizeof tname);
+               if (n < 0)
+                       return (-1);
+               cp += n;
+               if (cp + 2 * INT16SZ > eom)
+                       return (-1);
+               ttype = _getshort(cp); cp += INT16SZ;
+               tclass = _getshort(cp); cp += INT16SZ;
+               if (ttype == type &&
+                   tclass == class &&
+                   strcasecmp(tname, name) == 0)
+                       return (1);
+       }
+       return (0);
+}
+
+/* int
+ * res_queriesmatch(buf1, eom1, buf2, eom2)
+ *     is there a 1:1 mapping of (name,type,class)
+ *     in (buf1,eom1) and (buf2,eom2)?
+ * returns:
+ *     -1 : format error
+ *     0  : not a 1:1 mapping
+ *     >0 : is a 1:1 mapping
+ * author:
+ *     paul vixie, 29may94
+ */
+int
+res_queriesmatch(buf1, eom1, buf2, eom2)
+       const u_char *buf1, *eom1;
+       const u_char *buf2, *eom2;
+{
+       register const u_char *cp = buf1 + HFIXEDSZ;
+       int qdcount = ntohs( (u_short) ((HEADER*)buf1)->qdcount);
+
+       if (buf1 + HFIXEDSZ > eom1 || buf2 + HFIXEDSZ > eom2)
+               return (-1);
+
+       if (qdcount != ntohs( (u_short) ((HEADER*)buf2)->qdcount))
+               return (0);
+       while (qdcount-- > 0) {
+               char tname[MAXDNAME+1];
+               register int n, ttype, tclass;
+
+               n = dn_expand(buf1, eom1, cp, tname, sizeof tname);
+               if (n < 0)
+                       return (-1);
+               cp += n;
+               if (cp + 2 * INT16SZ > eom1)
+                       return (-1);
+               ttype = _getshort(cp);  cp += INT16SZ;
+               tclass = _getshort(cp); cp += INT16SZ;
+               if (!res_nameinquery(tname, ttype, tclass, buf2, eom2))
+                       return (0);
+       }
+       return (1);
+}
+
+int
+res_send(buf, buflen, ans, anssiz)
+       const u_char *buf;
+       int buflen;
+       u_char *ans;
+       int anssiz;
+{
+       HEADER *hp = (HEADER *) buf;
+       HEADER *anhp = (HEADER *) ans;
+       int gotsomewhere, connreset, terrno, try, v_circuit, resplen, ns;
+       register int n;
+       u_int badns;    /* XXX NSMAX can't exceed #/bits in this var */
+#ifdef WINNT
+       int optionValue = SO_SYNCHRONOUS_NONALERT;
+       DWORD BytesRead;
+#endif
+
+       if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+               /* errno should have been set by res_init() in this case. */
+               return (-1);
+       }
+       if (anssiz < HFIXEDSZ) {
+#ifndef WINNT
+        errno = EINVAL;
+#else
+       SetLastError(EINVAL);
+#endif
+               return (-1);
+       }
+       DprintQ((_res.options & RES_DEBUG) || (_res.pfcode & RES_PRF_QUERY),
+               (stdout, ";; res_send()\n"), buf, buflen);
+       v_circuit = (_res.options & RES_USEVC) || buflen > PACKETSZ;
+       gotsomewhere = 0;
+       connreset = 0;
+       terrno = ETIMEDOUT;
+       badns = 0;
+
+       /*
+        * Send request, RETRY times, or until successful
+        */
+       for (try = 0; try < _res.retry; try++) {
+           for (ns = 0; ns < _res.nscount; ns++) {
+               struct sockaddr_in *nsap = &_res.nsaddr_list[ns];
+    same_ns:
+               if (badns & (1 << ns)) {
+                       res_close();
+                       goto next_ns;
+               }
+
+               if (Qhook) {
+                       int done = 0, loops = 0;
+
+                       do {
+                               res_sendhookact act;
+
+                               act = (*Qhook)(&nsap, &buf, &buflen,
+                                              ans, anssiz, &resplen);
+                               switch (act) {
+                               case res_goahead:
+                                       done = 1;
+                                       break;
+                               case res_nextns:
+                                       res_close();
+                                       goto next_ns;
+                               case res_done:
+                                       return (resplen);
+                               case res_modified:
+                                       /* give the hook another try */
+                                       if (++loops < 42) /*doug adams*/
+                                               break;
+                                       /*FALLTHROUGH*/
+                               case res_error:
+                                       /*FALLTHROUGH*/
+                               default:
+                                       return (-1);
+                               }
+                       } while (!done);
+               }
+
+               Dprint(_res.options & RES_DEBUG,
+                      (stdout, ";; Querying server (# %d) address = %s\n",
+                       ns + 1, inet_ntoa(nsap->sin_addr)));
+
+               if (v_circuit) {
+                       int truncated;
+                       struct iovec iov[2];
+                       u_short len;
+                       u_char *cp;
+#ifdef WINNT
+                       /* set up things so that subsequent socket()
+                          calls will open blocking sockets */
+                       if (setsockopt(INVALID_SOCKET, SOL_SOCKET,
+                                       SO_OPENTYPE, (char *)&optionValue,
+                                       sizeof(optionValue)) != NO_ERROR) {
+                                               Perror(stderr, "cannot open nonoverlapped socket", errno);
+                                               return (-1);
+                       }
+#endif
+                       /*
+                        * Use virtual circuit;
+                        * at most one attempt per server.
+                        */
+                       try = _res.retry;
+                       truncated = 0;
+                       if ((s < 0) || (!vc)) {
+                               if (s >= 0)
+                                       res_close();
+
+                               s = socket(PF_INET, SOCK_STREAM, 0);
+#ifndef WINNT
+                               if (s < 0) {
+#else
+                               if (s == INVALID_SOCKET) {
+#endif
+                                       terrno = errno;
+                                       Perror(stderr, "socket(vc)", errno);
+                                       return (-1);
+                               }
+#ifndef WINNT
+                               errno = 0;
+#else
+                               SetLastError(0);
+#endif
+                               if (connect(s, (struct sockaddr *)nsap,
+                                           sizeof(struct sockaddr)) < 0) {
+                                       terrno = errno;
+                                       Aerror(stderr, "connect/vc",
+                                              errno, *nsap);
+                                       badns |= (1 << ns);
+                                       res_close();
+                                       goto next_ns;
+                               }
+                               vc = 1;
+                       }
+                       /*
+                        * Send length & message
+                        */
+                       putshort((u_short)buflen, (u_char*)&len);
+                       iov[0].iov_base = (caddr_t)&len;
+                       iov[0].iov_len = INT16SZ;
+                       iov[1].iov_base = (caddr_t)buf;
+                       iov[1].iov_len = buflen;
+                       if (writev(s, iov, 2) != (INT16SZ + buflen)) {
+                               terrno = errno;
+                               Perror(stderr, "write failed", errno);
+                               badns |= (1 << ns);
+                               res_close();
+                               goto next_ns;
+                       }
+                       /*
+                        * Receive length & response
+                        */
+read_len:
+                       cp = ans;
+                       len = INT16SZ;
+#ifndef WINNT
+                       while ((n = read(s, (char *)cp, (int)len)) > 0) {
+#else
+                       while (ReadFile((HANDLE)s, (char *)cp, (DWORD)len,
+                                            &BytesRead, NULL) &&
+                                  (n = (int)BytesRead) > 0) {
+#endif
+                               cp += n;
+                               if ((len -= n) <= 0)
+                                       break;
+                       }
+                       if (n <= 0) {
+                               terrno = errno;
+                               Perror(stderr, "read failed", errno);
+                               res_close();
+                               /*
+                                * A long running process might get its TCP
+                                * connection reset if the remote server was
+                                * restarted.  Requery the server instead of
+                                * trying a new one.  When there is only one
+                                * server, this means that a query might work
+                                * instead of failing.  We only allow one reset
+                                * per query to prevent looping.
+                                */
+                               if (terrno == ECONNRESET && !connreset) {
+                                       connreset = 1;
+                                       res_close();
+                                       goto same_ns;
+                               }
+                               res_close();
+                               goto next_ns;
+                       }
+                       resplen = _getshort(ans);
+                       if (resplen > anssiz) {
+                               Dprint(_res.options & RES_DEBUG,
+                                      (stdout, ";; response truncated\n")
+                                      );
+                               truncated = 1;
+                               len = anssiz;
+                       } else
+                               len = resplen;
+                       if (len < HFIXEDSZ) {
+                               /*
+                                * Undersized message.
+                                */
+                               Dprint(_res.options & RES_DEBUG,
+                                      (stdout, ";; undersized: %d\n", len));
+#ifndef WINNT
+                               terrno = EMSGSIZE;
+#else
+                               terrno = WSAEMSGSIZE;
+#endif
+                               badns |= (1 << ns);
+                               res_close();
+                               goto next_ns;
+                       }
+                       cp = ans;
+                       while (len != 0 &&
+#ifndef WINNT
+                              (n = read(s, (char *)cp, (int)len)) > 0) {
+#else
+                                       ReadFile((HANDLE)s, (char *)cp, (DWORD)len,
+                                            &BytesRead, NULL) &&
+                                   (n = (int)BytesRead) > 0) {
+#endif
+                               cp += n;
+                               len -= n;
+                       }
+                       if (n <= 0) {
+                               terrno = errno;
+                               Perror(stderr, "read(vc)", errno);
+                               res_close();
+                               goto next_ns;
+                       }
+                       if (truncated) {
+                               /*
+                                * Flush rest of answer
+                                * so connection stays in synch.
+                                */
+                               anhp->tc = 1;
+                               len = resplen - anssiz;
+                               while (len != 0) {
+                                       char junk[PACKETSZ];
+
+                                       n = (len > sizeof(junk)
+                                            ? sizeof(junk)
+                                            : len);
+#ifndef WINNT
+                                       if ((n = read(s, junk, n)) > 0)
+#else
+                                       if (ReadFile((HANDLE)s, (char *)junk, (DWORD)n,
+                                            &BytesRead, NULL) &&
+                                       (n = (int)BytesRead) > 0)
+#endif
+                                               len -= n;
+                                       else
+                                               break;
+                               }
+                       }
+                       /*
+                        * The calling applicating has bailed out of
+                        * a previous call and failed to arrange to have
+                        * the circuit closed or the server has got
+                        * itself confused. Anyway drop the packet and
+                        * wait for the correct one.
+                        */
+                       if (hp->id != anhp->id) {
+                               DprintQ((_res.options & RES_DEBUG) ||
+                                       (_res.pfcode & RES_PRF_REPLY),
+                                       (stdout, ";; old answer (unexpected):\n"),
+                                       ans, (resplen>anssiz)?anssiz:resplen);
+                               goto read_len;
+                       }
+               } else {
+                       /*
+                        * Use datagrams.
+                        */
+                       struct timeval timeout;
+                       fd_set dsmask;
+                       struct sockaddr_in from;
+                       int fromlen;
+
+#ifndef WINNT
+                       if ((s < 0) || vc) {
+#else
+                       if ((s == INVALID_SOCKET) || vc) {
+#endif
+                               if (vc)
+                                       res_close();
+                               s = socket(PF_INET, SOCK_DGRAM, 0);
+#ifndef WINNT
+                               if (s < 0) {
+#else
+                               if (s == INVALID_SOCKET) {
+#endif
+#if !CAN_RECONNECT
+ bad_dg_sock:
+#endif
+                                       terrno = errno;
+                                       Perror(stderr, "socket(dg)", errno);
+                                       return (-1);
+                               }
+                               connected = 0;
+                       }
+                       /*
+                        * On a 4.3BSD+ machine (client and server,
+                        * actually), sending to a nameserver datagram
+                        * port with no nameserver will cause an
+                        * ICMP port unreachable message to be returned.
+                        * If our datagram socket is "connected" to the
+                        * server, we get an ECONNREFUSED error on the next
+                        * socket operation, and select returns if the
+                        * error message is received.  We can thus detect
+                        * the absence of a nameserver without timing out.
+                        * If we have sent queries to at least two servers,
+                        * however, we don't want to remain connected,
+                        * as we wish to receive answers from the first
+                        * server to respond.
+                        */
+#ifndef WINNT
+                       if (_res.nscount == 1 || (try == 0 && ns == 0)) {
+                               /*
+                                * Connect only if we are sure we won't
+                                * receive a response from another server.
+                                */
+                               if (!connected) {
+                                       if (connect(s, (struct sockaddr *)nsap,
+                                                   sizeof(struct sockaddr)
+                                                   ) < 0) {
+                                               Aerror(stderr,
+                                                      "connect(dg)",
+                                                      errno, *nsap);
+                                               badns |= (1 << ns);
+                                               res_close();
+                                               goto next_ns;
+                                       }
+                                       connected = 1;
+                               }
+                               if (send(s, (char*)buf, buflen, 0) != buflen) {
+                                       Perror(stderr, "send", errno);
+                                       badns |= (1 << ns);
+                                       res_close();
+                                       goto next_ns;
+                               }
+                       } else {
+#endif /* WINNT */
+                               /*
+                                * Disconnect if we want to listen
+                                * for responses from more than one server.
+                                */
+                               if (connected) {
+#if CAN_RECONNECT
+                                       struct sockaddr_in no_addr;
+
+                                       no_addr.sin_family = AF_INET;
+                                       no_addr.sin_addr.s_addr = INADDR_ANY;
+                                       no_addr.sin_port = 0;
+                                       (void) connect(s,
+                                                      (struct sockaddr *)
+                                                       &no_addr,
+                                                      sizeof(no_addr));
+#else
+                                       int s1 = socket(PF_INET, SOCK_DGRAM,0);
+#ifndef WINNT
+                                       if (s1 < 0)
+#else
+                                       if (s1 == INVALID_SOCKET)
+#endif
+                                               goto bad_dg_sock;
+                                       (void) dup2(s1, s);
+                                       (void) close(s1);
+                                       Dprint(_res.options & RES_DEBUG,
+                                              (stdout, ";; new DG socket\n"))
+#endif
+                                       connected = 0;
+#ifndef WINNT
+                                       errno = 0;
+#else
+                                       SetLastError(0);
+#endif
+                               }
+                               if (sendto(s, (char*)buf, buflen, 0,
+                                          (struct sockaddr *)nsap,
+                                          sizeof(struct sockaddr))
+                                   != buflen) {
+                                       Aerror(stderr, "sendto", errno, *nsap);
+                                       badns |= (1 << ns);
+                                       res_close();
+                                       goto next_ns;
+                               }
+#ifndef WINNT
+                       }
+#endif
+
+                       /*
+                        * Wait for reply
+                        */
+                       timeout.tv_sec = (_res.retrans << try);
+                       if (try > 0)
+                               timeout.tv_sec /= _res.nscount;
+                       if ((long) timeout.tv_sec <= 0)
+                               timeout.tv_sec = 1;
+                       timeout.tv_usec = 0;
+    wait:
+                       if (s < 0 || s >= FD_SETSIZE) {
+                               Perror(stderr, "s out-of-bounds", EMFILE);
+                               res_close();
+                               goto next_ns;
+                       }
+                       FD_ZERO(&dsmask);
+                       FD_SET(s, &dsmask);
+                       n = select(s+1, &dsmask, (fd_set *)NULL,
+                                  (fd_set *)NULL, &timeout);
+                       if (n < 0) {
+#ifndef WINNT
+                               if (errno == EINTR)
+#else
+                               if (errno == WSAEINTR)
+#endif
+                                       goto wait;
+                               Perror(stderr, "select", errno);
+                               res_close();
+                               goto next_ns;
+                       }
+                       if (n == 0) {
+                               /*
+                                * timeout
+                                */
+                               Dprint(_res.options & RES_DEBUG,
+                                      (stdout, ";; timeout\n"));
+                               gotsomewhere = 1;
+                               res_close();
+                               goto next_ns;
+                       }
+#ifndef WINNT
+                       errno = 0;
+#else
+                       WSASetLastError(0);
+                       SetLastError(0);
+#endif
+                       fromlen = sizeof(struct sockaddr_in);
+                       resplen = recvfrom(s, (char*)ans, anssiz, 0,
+                                          (struct sockaddr *)&from, &fromlen);
+                       if (resplen <= 0) {
+#ifndef WINNT
+                               Perror(stderr, "recvfrom", errno);
+#else
+                               Perror(stderr, "recvfrom", WSAGetLastError());
+#endif
+                               res_close();
+                               goto next_ns;
+                       }
+                       gotsomewhere = 1;
+                       if (resplen < HFIXEDSZ) {
+                               /*
+                                * Undersized message.
+                                */
+                               Dprint(_res.options & RES_DEBUG,
+                                      (stdout, ";; undersized: %d\n",
+                                       resplen));
+#ifndef WINNT
+                               terrno = EMSGSIZE;
+#else
+                               terrno = WSAEMSGSIZE;
+#endif
+                               badns |= (1 << ns);
+                               res_close();
+                               goto next_ns;
+                       }
+                       if (hp->id != anhp->id) {
+                               /*
+                                * response from old query, ignore it.
+                                * XXX - potential security hazard could
+                                *       be detected here.
+                                */
+                               DprintQ((_res.options & RES_DEBUG) ||
+                                       (_res.pfcode & RES_PRF_REPLY),
+                                       (stdout, ";; old answer:\n"),
+                                       ans, (resplen>anssiz)?anssiz:resplen);
+                               goto wait;
+                       }
+#if CHECK_SRVR_ADDR
+                       if (!(_res.options & RES_INSECURE1) &&
+                           !res_isourserver(&from)) {
+                               /*
+                                * response from wrong server? ignore it.
+                                * XXX - potential security hazard could
+                                *       be detected here.
+                                */
+                               DprintQ((_res.options & RES_DEBUG) ||
+                                       (_res.pfcode & RES_PRF_REPLY),
+                                       (stdout, ";; not our server:\n"),
+                                       ans, (resplen>anssiz)?anssiz:resplen);
+                               goto wait;
+                       }
+#endif
+                       if (!(_res.options & RES_INSECURE2) &&
+                           !res_queriesmatch(buf, buf + buflen,
+                                             ans, ans + anssiz)) {
+                               /*
+                                * response contains wrong query? ignore it.
+                                * XXX - potential security hazard could
+                                *       be detected here.
+                                */
+                               DprintQ((_res.options & RES_DEBUG) ||
+                                       (_res.pfcode & RES_PRF_REPLY),
+                                       (stdout, ";; wrong query name:\n"),
+                                       ans, (resplen>anssiz)?anssiz:resplen);
+                               goto wait;
+                       }
+                       if (anhp->rcode == SERVFAIL ||
+                           anhp->rcode == NOTIMP ||
+                           anhp->rcode == REFUSED) {
+                               DprintQ(_res.options & RES_DEBUG,
+                                       (stdout, "server rejected query:\n"),
+                                       ans, (resplen>anssiz)?anssiz:resplen);
+                               badns |= (1 << ns);
+                               res_close();
+                               /* don't retry if called from dig */
+                               if (!_res.pfcode)
+                                       goto next_ns;
+                       }
+                       if (!(_res.options & RES_IGNTC) && anhp->tc) {
+                               /*
+                                * get rest of answer;
+                                * use TCP with same server.
+                                */
+                               Dprint(_res.options & RES_DEBUG,
+                                      (stdout, ";; truncated answer\n"));
+                               v_circuit = 1;
+                               res_close();
+                               goto same_ns;
+                       }
+               } /*if vc/dg*/
+               Dprint((_res.options & RES_DEBUG) ||
+                      ((_res.pfcode & RES_PRF_REPLY) &&
+                       (_res.pfcode & RES_PRF_HEAD1)),
+                      (stdout, ";; got answer:\n"));
+               DprintQ((_res.options & RES_DEBUG) ||
+                       (_res.pfcode & RES_PRF_REPLY),
+                       (stdout, ""),
+                       ans, (resplen>anssiz)?anssiz:resplen);
+               /*
+                * If using virtual circuits, we assume that the first server
+                * is preferred over the rest (i.e. it is on the local
+                * machine) and only keep that one open.
+                * If we have temporarily opened a virtual circuit,
+                * or if we haven't been asked to keep a socket open,
+                * close the socket.
+                */
+               if ((v_circuit && (!(_res.options & RES_USEVC) || ns != 0)) ||
+                   !(_res.options & RES_STAYOPEN)) {
+                       res_close();
+               }
+               if (Rhook) {
+                       int done = 0, loops = 0;
+
+                       do {
+                               res_sendhookact act;
+
+                               act = (*Rhook)(nsap, buf, buflen,
+                                              ans, anssiz, &resplen);
+                               switch (act) {
+                               case res_goahead:
+                               case res_done:
+                                       done = 1;
+                                       break;
+                               case res_nextns:
+                                       res_close();
+                                       goto next_ns;
+                               case res_modified:
+                                       /* give the hook another try */
+                                       if (++loops < 42) /*doug adams*/
+                                               break;
+                                       /*FALLTHROUGH*/
+                               case res_error:
+                                       /*FALLTHROUGH*/
+                               default:
+                                       return (-1);
+                               }
+                       } while (!done);
+
+               }
+               return (resplen);
+    next_ns: ;
+          } /*foreach ns*/
+       } /*foreach retry*/
+       res_close();
+       if (!v_circuit)
+               if (!gotsomewhere) {
+#ifndef WINNT
+                       errno = ECONNREFUSED;   /* no nameservers found */
+#else
+                       WSASetLastError(ECONNREFUSED);
+                       SetLastError(ECONNREFUSED);
+#endif
+               } else {
+#ifndef WINNT
+                       errno = ETIMEDOUT;      /* no answer obtained */
+#else
+                       WSASetLastError(ETIMEDOUT);
+                       SetLastError(ETIMEDOUT);
+#endif
+               } else {
+#ifndef WINNT
+               errno = terrno;
+#else
+               WSASetLastError(terrno);
+               SetLastError(terrno);
+#endif
+       return (-1);
+ }
+}
+
+/*
+ * This routine is for closing the socket if a virtual circuit is used and
+ * the program wants to close it.  This provides support for endhostent()
+ * which expects to close the socket.
+ *
+ * This routine is not expected to be user visible.
+ */
+void
+res_close()
+{
+       if (s >= 0) {
+#ifndef WINNT
+               (void) close(s);
+#else
+    (void) closesocket(s);
+#endif
+
+#ifndef WINNT
+               s = -1;
+#else
+               s = INVALID_SOCKET;
+#endif
+               connected = 0;
+               vc = 0;
+       }
+}
+
+#ifdef ultrix
+/* ultrix 4.0 had some icky packaging in its libc.a.  alias for it here.
+ * there is more gunk of this kind over in res_debug.c.
+ */
+
+void
+_res_close()
+{
+       res_close();
+}
+
+#undef res_send
+int
+res_send(buf, buflen, ans, anssiz)
+       const u_char *buf;
+       int buflen;
+       u_char *ans;
+       int anssiz;
+{
+       return (__res_send(buf, buflen, ans, anssiz));
+}
+#endif /* Ultrix 4.0 hackery */
diff --git a/bindlib_w32/resolv.h b/bindlib_w32/resolv.h
new file mode 100644 (file)
index 0000000..8e2e61d
--- /dev/null
@@ -0,0 +1,308 @@
+/*
+ * ++Copyright++ 1983, 1987, 1989, 1993
+ * -
+ * Copyright (c) 1983, 1987, 1989, 1993
+ *    The Regents of the University of California.  All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ * 
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+
+/*
+ *     @(#)resolv.h    8.1 (Berkeley) 6/2/93
+ *     $Id$
+ */
+
+#ifndef _RESOLV_H_
+#define        _RESOLV_H_
+
+#ifndef WINNT
+#include <sys/param.h>
+#endif
+#if (!defined(BSD)) || (BSD < 199306)
+#include <sys/bitypes.h>
+#else
+#include <sys/types.h>
+#endif
+#include <sys/cdefs.h>
+#include <stdio.h>
+#ifdef WINNT
+#define FD_SETSIZE 512
+#include <winsock.h>
+#include "conf\portability.h"
+#endif
+
+/*
+ * Revision information.  This is the release date in YYYYMMDD format.
+ * It can change every day so the right thing to do with it is use it
+ * in preprocessor commands such as "#if (__RES > 19931104)".  Do not
+ * compare for equality; rather, use it to determine whether your resolver
+ * is new enough to contain a certain feature.
+ */
+
+#define        __RES   19960801
+
+/*
+ * Resolver configuration file.
+ * Normally not present, but may contain the address of the
+ * inital name server(s) to query and the domain search list.
+ */
+
+#ifndef _PATH_RESCONF
+#ifndef WINNT
+#define _PATH_RESCONF        "/etc/resolv.conf"
+#else
+#define _PATH_RESCONF           "%windir%\\RESOLV.CONF"
+#define _ALT_PATH_RESCONF       "%windir%\\RESOLV.INI"
+#endif /* WINNT */
+#endif
+
+/*
+ * Global defines and variables for resolver stub.
+ */
+#define        MAXNS                   3       /* max # name servers we'll track */
+#define        MAXDFLSRCH              3       /* # default domain levels to try */
+#define        MAXDNSRCH               6       /* max # domains in search path */
+#define        LOCALDOMAINPARTS        2       /* min levels in name that is "local" */
+
+#define        RES_TIMEOUT             5       /* min. seconds between retries */
+#define        MAXRESOLVSORT           10      /* number of net to sort on */
+#define        RES_MAXNDOTS            15      /* should reflect bit field size */
+
+struct __res_state {
+       int     retrans;                /* retransmition time interval */
+       int     retry;                  /* number of times to retransmit */
+       u_long  options;                /* option flags - see below. */
+       int     nscount;                /* number of name servers */
+       struct sockaddr_in
+               nsaddr_list[MAXNS];     /* address of name server */
+#define        nsaddr  nsaddr_list[0]          /* for backward compatibility */
+       u_short id;                     /* current message id */
+       char    *dnsrch[MAXDNSRCH+1];   /* components of domain to search */
+       char    defdname[256];          /* default domain (deprecated) */
+       u_long  pfcode;                 /* RES_PRF_ flags - see below. */
+       unsigned ndots:4;               /* threshold for initial abs. query */
+       unsigned nsort:4;               /* number of elements in sort_list[] */
+       char    unused[3];
+       struct {
+               struct in_addr  addr;
+               u_int32_t       mask;
+       } sort_list[MAXRESOLVSORT];
+       char    pad[72];                /* on an i386 this means 512b total */
+};
+
+/*
+ * Resolver options (keep these in synch with res_debug.c, please)
+ */
+#define RES_INIT       0x00000001      /* address initialized */
+#define RES_DEBUG      0x00000002      /* print debug messages */
+#define RES_AAONLY     0x00000004      /* authoritative answers only (!IMPL)*/
+#define RES_USEVC      0x00000008      /* use virtual circuit */
+#define RES_PRIMARY    0x00000010      /* query primary server only (!IMPL) */
+#define RES_IGNTC      0x00000020      /* ignore trucation errors */
+#define RES_RECURSE    0x00000040      /* recursion desired */
+#define RES_DEFNAMES   0x00000080      /* use default domain name */
+#define RES_STAYOPEN   0x00000100      /* Keep TCP socket open */
+#define RES_DNSRCH     0x00000200      /* search up local domain tree */
+#define        RES_INSECURE1   0x00000400      /* type 1 security disabled */
+#define        RES_INSECURE2   0x00000800      /* type 2 security disabled */
+#define        RES_NOALIASES   0x00001000      /* shuts off HOSTALIASES feature */
+#define        RES_USE_INET6   0x00002000      /* use/map IPv6 in gethostbyname() */
+
+#define RES_DEFAULT    (RES_RECURSE | RES_DEFNAMES | RES_DNSRCH)
+
+/*
+ * Resolver "pfcode" values.  Used by dig.
+ */
+#define RES_PRF_STATS  0x00000001
+/*                     0x00000002      */
+#define RES_PRF_CLASS   0x00000004
+#define RES_PRF_CMD    0x00000008
+#define RES_PRF_QUES   0x00000010
+#define RES_PRF_ANS    0x00000020
+#define RES_PRF_AUTH   0x00000040
+#define RES_PRF_ADD    0x00000080
+#define RES_PRF_HEAD1  0x00000100
+#define RES_PRF_HEAD2  0x00000200
+#define RES_PRF_TTLID  0x00000400
+#define RES_PRF_HEADX  0x00000800
+#define RES_PRF_QUERY  0x00001000
+#define RES_PRF_REPLY  0x00002000
+#define RES_PRF_INIT    0x00004000
+/*                     0x00008000      */
+
+/* hooks are still experimental as of 4.9.2 */
+typedef enum { res_goahead, res_nextns, res_modified, res_done, res_error }
+       res_sendhookact;
+
+typedef res_sendhookact (*res_send_qhook)__P((struct sockaddr_in * const *ns,
+                                             const u_char **query,
+                                             int *querylen,
+                                             u_char *ans,
+                                             int anssiz,
+                                             int *resplen));
+
+typedef res_sendhookact (*res_send_rhook)__P((const struct sockaddr_in *ns,
+                                             const u_char *query,
+                                             int querylen,
+                                             u_char *ans,
+                                             int anssiz,
+                                             int *resplen));
+
+struct res_sym {
+       int     number;         /* Identifying number, like T_MX */
+       char *  name;           /* Its symbolic name, like "MX" */
+       char *  humanname;      /* Its fun name, like "mail exchanger" */
+};
+
+extern struct __res_state _res;
+extern const struct res_sym __p_class_syms[];
+extern const struct res_sym __p_type_syms[];
+
+/* Private routines shared between libc/net, named, nslookup and others. */
+#define        res_hnok        __res_hnok
+#define        res_ownok       __res_ownok
+#define        res_mailok      __res_mailok
+#define        res_dnok        __res_dnok
+#define        sym_ston        __sym_ston
+#define        sym_ntos        __sym_ntos
+#define        sym_ntop        __sym_ntop
+#define b64_ntop       __b64_ntop
+#define        b64_pton        __b64_pton
+#define        loc_ntoa        __loc_ntoa
+#define        loc_aton        __loc_aton
+#define        dn_skipname     __dn_skipname
+#define        fp_resstat      __fp_resstat
+#define        fp_query        __fp_query
+#define        fp_nquery       __fp_nquery
+#define        hostalias       __hostalias
+#define        putlong         __putlong
+#define        putshort        __putshort
+#define p_class                __p_class
+#define p_time         __p_time
+#define p_type         __p_type
+#define        p_query         __p_query
+#define        p_cdnname       __p_cdnname
+#define        p_cdname        __p_cdname
+#define        p_fqnname       __p_fqnname
+#define        p_fqname        __p_fqname
+#define        p_rr            __p_rr
+#define        p_option        __p_option
+#define        p_secstodate    __p_secstodate
+#define        dn_count_labels __dn_count_labels
+#define        dn_comp         __dn_comp
+#define        res_randomid    __res_randomid
+#define        res_isourserver __res_isourserver
+#define        res_nameinquery __res_nameinquery
+#define        res_queriesmatch __res_queriesmatch
+#define        res_close       __res_close
+
+#ifdef BIND_RES_POSIX3
+#define        dn_expand       __dn_expand
+#define        res_init        __res_init
+#define        res_query       __res_query
+#define        res_search      __res_search
+#define        res_querydomain __res_querydomain
+#define        res_mkquery     __res_mkquery
+#define        res_send        __res_send
+#endif
+
+__BEGIN_DECLS
+int            res_hnok __P((const char *));
+int            res_ownok __P((const char *));
+int            res_mailok __P((const char *));
+int            res_dnok __P((const char *));
+int            sym_ston __P((const struct res_sym *, char *, int *));
+const char *   sym_ntos __P((const struct res_sym *, int, int *));
+const char *   sym_ntop __P((const struct res_sym *, int, int *));
+int            b64_ntop __P((u_char const *, size_t, char *, size_t));
+int            b64_pton __P((char const *, u_char *, size_t));
+int            loc_aton __P((const char *, u_char *));
+const char *   loc_ntoa __P((const u_char *, char *));
+int            dn_skipname __P((const u_char *, const u_char *));
+void           fp_resstat __P((struct __res_state *, FILE *));
+void           fp_query __P((const u_char *, FILE *));
+void           fp_nquery __P((const u_char *, int, FILE *));
+const char *   hostalias __P((const char *));
+void           putlong __P((u_int32_t, u_char *));
+void           putshort __P((u_int16_t, u_char *));
+const char *   p_class __P((int));
+const char *   p_time __P((u_int32_t));
+const char *   p_type __P((int));
+void           p_query __P((const u_char *));
+const u_char * p_cdnname __P((const u_char *, const u_char *, int, FILE *));
+const u_char * p_cdname __P((const u_char *, const u_char *, FILE *));
+const u_char * p_fqnname __P((const u_char *cp, const u_char *msg,
+                              int, char *, int));
+const u_char * p_fqname __P((const u_char *, const u_char *, FILE *));
+const u_char * p_rr __P((const u_char *, const u_char *, FILE *));
+const char *   p_option __P((u_long option));
+char *         p_secstodate __P((u_long));
+int            dn_count_labels __P((char *));
+int            dn_comp __P((const char *, u_char *, int,
+                            u_char **, u_char **));
+int            dn_expand __P((const u_char *, const u_char *, const u_char *,
+                              char *, int));
+int            res_init __P((void));
+u_int          res_randomid __P((void));
+int            res_query __P((const char *, int, int, u_char *, int));
+int            res_search __P((const char *, int, int, u_char *, int));
+int            res_querydomain __P((const char *, const char *, int, int,
+                                    u_char *, int));
+int            res_mkquery __P((int, const char *, int, int, const u_char *, int,
+                                const u_char *, u_char *, int));
+int            res_send __P((const u_char *, int, u_char *, int));
+int            res_isourserver __P((const struct sockaddr_in *));
+int            res_nameinquery __P((const char *, int, int,
+                                    const u_char *, const u_char *));
+int            res_queriesmatch __P((const u_char *, const u_char *,
+                                     const u_char *, const u_char *));
+void           res_close __P((void));
+__END_DECLS
+
+#endif /* !_RESOLV_H_ */
diff --git a/bindlib_w32/sethostent.c b/bindlib_w32/sethostent.c
new file mode 100644 (file)
index 0000000..79f9c6a
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 1985, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)sethostent.c       8.1 (Berkeley) 6/4/93";
+static char rcsid[] = "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#ifndef WINNT
+#include <sys/param.h>
+#include <netinet/in.h>
+#endif
+#include <arpa/nameser.h>
+#include <netdb.h>
+#include <resolv.h>
+
+void
+sethostent(stayopen)
+       int stayopen;
+{
+       if ((_res.options & RES_INIT) == 0 && res_init() == -1)
+               return;
+       if (stayopen)
+               _res.options |= RES_STAYOPEN | RES_USEVC;
+}
+
+void
+endhostent()
+{
+       _res.options &= ~(RES_STAYOPEN | RES_USEVC);
+       res_close();
+}
diff --git a/bindlib_w32/sys/Makefile b/bindlib_w32/sys/Makefile
new file mode 100644 (file)
index 0000000..0f23fc4
--- /dev/null
@@ -0,0 +1,72 @@
+# $Id$
+
+# ++Copyright++
+# -
+# Copyright (c)  Regents of the University of California.
+# All rights reserved.
+# 
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+# 3. All advertising materials mentioning features or use of this software
+#    must display the following acknowledgement:
+#      This product includes software developed by the University of
+#      California, Berkeley and its contributors.
+# 4. Neither the name of the University nor the names of its contributors
+#    may be used to endorse or promote products derived from this software
+#    without specific prior written permission.
+# 
+# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+# -
+# Portions Copyright (c) 1993 by Digital Equipment Corporation.
+# 
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies, and that
+# the name of Digital Equipment Corporation not be used in advertising or
+# publicity pertaining to distribution of the document or software without
+# specific, written prior permission.
+# 
+# THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+# WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
+# CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+# PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+# SOFTWARE.
+# -
+# --Copyright--
+
+HFILES = cdefs.h bitypes.h
+
+DESTDIR=
+DESTINC= /usr/include
+
+all depend:
+
+clean:
+       rm -f *~ *.BAK *.CKP *.orig
+
+install: ${DESTDIR}${DESTINC}/sys
+       for x in ${HFILES}; do \
+               ${INSTALL} -c -m 444 $$x ${DESTDIR}${DESTINC}/sys/$$x; \
+       done
+
+${DESTDIR}${DESTINC}/sys:
+       mkdir $@
diff --git a/bindlib_w32/sys/bitypes.h b/bindlib_w32/sys/bitypes.h
new file mode 100644 (file)
index 0000000..f36b369
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * $Id$
+ */
+
+/*
+ * ++Copyright++ 1993
+ * -
+ * Copyright (c) 1993 Regents of the University of California.
+ * All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ * 
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+
+#ifndef __BIT_TYPES_DEFINED__
+# if (defined(BSD) && (BSD >= 199306)) || \
+     (defined(_BSDI_VERSION) && (_BSDI_VERSION >= 199312)) 
+#  define __BIT_TYPES_DEFINED__
+# endif
+#endif
+
+#ifndef __BIT_TYPES_DEFINED__
+#define __BIT_TYPES_DEFINED__
+
+#ifdef __linux__
+#include <linux/types.h>
+#endif
+
+       /*
+        * Basic integral types.  Omit the typedef if
+        * not possible for a machine/compiler combination.
+        */
+       typedef /*signed*/ char            int8_t;
+       typedef unsigned char            u_int8_t;
+       typedef short                     int16_t;
+       typedef unsigned short          u_int16_t;
+       typedef int                       int32_t;
+       typedef unsigned int            u_int32_t;
+
+# if 0 /* don't fight with these unless you need them */
+       typedef long long                 int64_t;
+       typedef unsigned long long      u_int64_t;
+# endif
+
+#endif /* __BIT_TYPES_DEFINED__ */
diff --git a/bindlib_w32/sys/cdefs.h b/bindlib_w32/sys/cdefs.h
new file mode 100644 (file)
index 0000000..e19b3e5
--- /dev/null
@@ -0,0 +1,143 @@
+/*
+ * Copyright (c) 1991, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Berkeley Software Design, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *     @(#)cdefs.h     8.7 (Berkeley) 1/21/94
+ */
+
+#ifndef        _CDEFS_H_
+#define        _CDEFS_H_
+
+/* POSIX.2 feature test macro: enable POSIX.1 and/or more */
+#if _POSIX_C_SOURCE == 1 || _POSIX_C_SOURCE == 2
+#define        _POSIX_SOURCE
+#endif
+
+#if defined(_POSIX_SOURCE) || defined(__STRICT_ANSI__)
+#define        _ANSI_SOURCE
+#endif
+
+#if defined(__cplusplus)
+#define        __BEGIN_DECLS   extern "C" {
+#define        __END_DECLS     };
+#else
+#define        __BEGIN_DECLS
+#define        __END_DECLS
+#endif
+
+/*
+ * The __CONCAT macro is used to concatenate parts of symbol names, e.g.
+ * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo.
+ * The __CONCAT macro is a bit tricky -- make sure you don't put spaces
+ * in between its arguments.  __CONCAT can also concatenate double-quoted
+ * strings produced by the __STRING macro, but this only works with ANSI C.
+ */
+#if defined(__STDC__) || defined(__cplusplus)
+#define        __P(protos)     protos          /* full-blown ANSI C */
+#define        __CONCAT(x,y)   x ## y
+#define        __STRING(x)     #x
+
+#define        __const         const           /* define reserved names to standard */
+#define        __signed        signed
+#define        __volatile      volatile
+#if defined(__cplusplus)
+#define        __inline        inline          /* convert to C++ keyword */
+#else
+#ifndef __GNUC__
+#define        __inline                        /* delete GCC keyword */
+#endif /* !__GNUC__ */
+#endif /* !__cplusplus */
+
+#else  /* !(__STDC__ || __cplusplus) */
+#define        __P(protos)     ()              /* traditional C preprocessor */
+#define        __CONCAT(x,y)   x/**/y
+#define        __STRING(x)     "x"
+
+#ifndef WINNT
+#ifndef __GNUC__
+#define        __const                         /* delete pseudo-ANSI C keywords */
+#define        __inline
+#define        __signed
+#define        __volatile
+#endif
+/*
+ * In non-ANSI C environments, new programs will want ANSI-only C keywords
+ * deleted from the program and old programs will want them left alone.
+ * When using a compiler other than gcc, programs using the ANSI C keywords
+ * const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS.
+ * When using "gcc -traditional", we assume that this is the intent; if
+ * __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone.
+ */
+#ifndef NO_ANSI_KEYWORDS
+#define        const                           /* delete ANSI C keywords */
+#define        inline
+#define        signed
+#define        volatile
+#endif /* WINNT */
+#endif /* !__GNUC__ */
+#endif /* !(__STDC__ || __cplusplus) */
+
+/*
+ * GCC1 and some versions of GCC2 declare dead (non-returning) and
+ * pure (no side effects) functions using "volatile" and "const";
+ * unfortunately, these then cause warnings under "-ansi -pedantic".
+ * GCC2 uses a new, peculiar __attribute__((attrs)) style.  All of
+ * these work for GNU C++ (modulo a slight glitch in the C++ grammar
+ * in the distribution version of 2.5.5).
+ */
+#if !defined(__GNUC__) || __GNUC__ < 2 || __GNUC_MINOR__ < 5
+#define        __attribute__(x)        /* delete __attribute__ if non-gcc or gcc1 */
+#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
+#define        __dead          __volatile
+#define        __pure          __const
+#endif
+#endif
+/* The following lines were added for newer versions of GNU C
+ *   Ed Lewis - Sept 1996 lewis@tis.com
+ */    
+#if __GNUC__ == 2 &&  __GNUC_MINOR__ >= 5 || __GNUC__ >= 3
+#define __dead
+#define __dead2     __attribute__((noreturn))
+#define __pure
+#define __pure2     __attribute__((const))
+#endif
+
+
+/* Delete pseudo-keywords wherever they are not available or needed. */
+#ifndef __dead
+#define        __dead
+#define        __pure
+#endif
+
+#endif /* !_CDEFS_H_ */
diff --git a/bindlib_w32/writev.c b/bindlib_w32/writev.c
new file mode 100644 (file)
index 0000000..ded962e
--- /dev/null
@@ -0,0 +1,131 @@
+#ifndef LINT
+static char rcsid[] = "$Id$";
+#endif
+
+/* writev() emulations contained in this source file for the following systems:
+ *
+ *     Cray UNICOS
+ *     SCO
+ *  WindowsNT
+ */
+
+#if defined(_CRAY)
+#define OWN_WRITEV
+#include <sys/types.h>
+#include <sys/uio.h>
+#include <sys/stat.h>
+#include <sys/socket.h>
+
+int
+__writev(int fd, struct iovec *iov, int iovlen)
+{
+       struct stat statbuf;
+
+       if (fstat(fd, &statbuf) < 0)
+               return (-1);
+
+       /*
+        * Allow for atomic writes to network.
+        */
+       if (statbuf.st_mode & S_IFSOCK) {
+               struct msghdr   mesg;           
+
+               mesg.msg_name = 0;
+               mesg.msg_namelen = 0;
+               mesg.msg_iov = iov;
+               mesg.msg_iovlen = iovlen;
+               mesg.msg_accrights = 0;
+               mesg.msg_accrightslen = 0;
+               return (sendmsg(fd, &mesg, 0));
+       } else {
+               register struct iovec *tv;
+               register int i, rcode = 0, count = 0;
+
+               for (i = 0, tv = iov; i <= iovlen; tv++) {
+                       rcode = write(fd, tv->iov_base, tv->iov_len);
+
+                       if (rcode < 0)
+                               break;
+
+                       count += rcode;
+               }
+
+               if (count == 0)
+                       return (rcode);
+               else
+                       return (count);
+       }
+}
+#endif
+
+#if defined (M_UNIX) && !defined(_SCO_DS) || defined (NEED_WRITEV)
+#define OWN_WRITEV
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/uio.h>
+
+int
+__writev(fd, vp, vpcount)
+       int fd;
+       const struct iovec *vp;
+       register int vpcount;
+{
+       register int count = 0;
+
+       while (vpcount-- > 0) {
+               register int written = write(fd, vp->iov_base, vp->iov_len);
+
+               if (written <= 0)
+                       return (-1);
+               count += written;
+               vp++;
+       }
+       return (count);
+}
+#endif
+
+#ifdef WINNT
+#define OWN_WRITEV
+#define TIMEOUT_SEC 120
+#include <stdarg.h>
+#include "conf/portability.h"
+
+
+/*
+ * writev --
+ * simplistic writev implementation for WindowsNT using the WriteFile WIN32API.
+ */    
+/* lgk win95 does not support overlapped/async file operations so change it to
+   synchronous */
+/* Zeev:  We don't compile the whole bindlib, so stay with Windows 95's implementation
+ * (we dont have the hReadWriteEvent handle available)
+ */
+
+int
+writev(fd, iov, iovcnt)
+       int fd;
+       struct iovec *iov;
+       int iovcnt;
+{
+       int i;
+       char *base;
+       DWORD BytesWritten, TotalBytesWritten = 0, len;
+       BOOL ret; 
+
+       for (i=0; i<iovcnt; i++) {
+               base = iov[i].iov_base;
+               len = (DWORD)iov[i].iov_len;
+               ret = WriteFile((HANDLE)fd, (char *)base, len,
+                             (LPDWORD)&BytesWritten, NULL);
+               if (ret == FALSE)
+                  return (-1);
+               TotalBytesWritten += BytesWritten;
+       }
+       return((int)TotalBytesWritten);
+}
+
+#endif // winnt
+
+#ifndef OWN_WRITEV
+int __bindcompat_writev;
+#endif