summaryrefslogtreecommitdiff
path: root/usr/src/lib/libresolv2/common/resolv
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/lib/libresolv2/common/resolv')
-rw-r--r--usr/src/lib/libresolv2/common/resolv/herror.c43
-rw-r--r--usr/src/lib/libresolv2/common/resolv/mtctxres.c135
-rw-r--r--usr/src/lib/libresolv2/common/resolv/res_comp.c89
-rw-r--r--usr/src/lib/libresolv2/common/resolv/res_data.c109
-rw-r--r--usr/src/lib/libresolv2/common/resolv/res_debug.c322
-rw-r--r--usr/src/lib/libresolv2/common/resolv/res_debug.h24
-rw-r--r--usr/src/lib/libresolv2/common/resolv/res_findzonecut.c79
-rw-r--r--usr/src/lib/libresolv2/common/resolv/res_init.c220
-rw-r--r--usr/src/lib/libresolv2/common/resolv/res_mkquery.c189
-rw-r--r--usr/src/lib/libresolv2/common/resolv/res_mkupdate.c126
-rw-r--r--usr/src/lib/libresolv2/common/resolv/res_mkupdate.h24
-rw-r--r--usr/src/lib/libresolv2/common/resolv/res_private.h9
-rw-r--r--usr/src/lib/libresolv2/common/resolv/res_query.c109
-rw-r--r--usr/src/lib/libresolv2/common/resolv/res_send.c255
-rw-r--r--usr/src/lib/libresolv2/common/resolv/res_sendsigned.c74
-rw-r--r--usr/src/lib/libresolv2/common/resolv/res_update.c34
16 files changed, 1065 insertions, 776 deletions
diff --git a/usr/src/lib/libresolv2/common/resolv/herror.c b/usr/src/lib/libresolv2/common/resolv/herror.c
index 1101057748..703ab8fe4d 100644
--- a/usr/src/lib/libresolv2/common/resolv/herror.c
+++ b/usr/src/lib/libresolv2/common/resolv/herror.c
@@ -1,9 +1,4 @@
/*
- * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
-/*
* Copyright (c) 1987, 1993
* The Regents of the University of California. All rights reserved.
*
@@ -37,27 +32,25 @@
*/
/*
+ * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Portions Copyright (c) 1996-1999 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.
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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.
*/
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#if defined(LIBC_SCCS) && !defined(lint)
static const char sccsid[] = "@(#)herror.c 8.1 (Berkeley) 6/4/93";
-static const char rcsid[] = "$Id: herror.c,v 8.13 2001/06/18 14:44:06 marka Exp $";
+static const char rcsid[] = "$Id: herror.c,v 1.4 2005/04/27 04:56:41 sra Exp $";
#endif /* LIBC_SCCS and not lint */
#include "port_before.h"
@@ -76,20 +69,22 @@ static const char rcsid[] = "$Id: herror.c,v 8.13 2001/06/18 14:44:06 marka Exp
#include <irs.h>
#include "port_after.h"
-#undef h_errno
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 */
+ "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] };
+#if !(__GLIBC__ > 2 || __GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)
+#undef h_errno
int h_errno;
+#endif
-/*
+/*%
* herror --
* print the error indicated by the h_errno value.
*/
@@ -118,7 +113,7 @@ herror(const char *s) {
writev(STDERR_FILENO, iov, (v - iov) + 1);
}
-/*
+/*%
* hstrerror --
* return the string associated with a given "host" errno value.
*/
@@ -130,3 +125,5 @@ hstrerror(int err) {
return (h_errlist[err]);
return ("Unknown resolver error");
}
+
+/*! \file */
diff --git a/usr/src/lib/libresolv2/common/resolv/mtctxres.c b/usr/src/lib/libresolv2/common/resolv/mtctxres.c
new file mode 100644
index 0000000000..2e79b1e7b4
--- /dev/null
+++ b/usr/src/lib/libresolv2/common/resolv/mtctxres.c
@@ -0,0 +1,135 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+
+#include <port_before.h>
+#ifdef DO_PTHREADS
+#include <pthread.h>
+#endif
+#include <errno.h>
+#include <netdb.h>
+#include <stdlib.h>
+#include <string.h>
+#include <resolv_mt.h>
+#include <irs.h>
+#include <port_after.h>
+
+#ifdef DO_PTHREADS
+static pthread_key_t key;
+static int mt_key_initialized = 0;
+
+static int __res_init_ctx(void);
+static void __res_destroy_ctx(void *);
+
+#if defined(sun) && !defined(__GNUC__)
+#pragma init (_mtctxres_init)
+#endif
+#endif
+
+static mtctxres_t sharedctx;
+
+#ifdef DO_PTHREADS
+/*
+ * Initialize the TSD key. By doing this at library load time, we're
+ * implicitly running without interference from other threads, so there's
+ * no need for locking.
+ */
+static void
+_mtctxres_init(void) {
+ int pthread_keycreate_ret;
+
+ pthread_keycreate_ret = pthread_key_create(&key, __res_destroy_ctx);
+ if (pthread_keycreate_ret == 0)
+ mt_key_initialized = 1;
+}
+#endif
+
+/*
+ * To support binaries that used the private MT-safe interface in
+ * Solaris 8, we still need to provide the __res_enable_mt()
+ * and __res_disable_mt() entry points. They're do-nothing routines.
+ */
+int
+__res_enable_mt(void) {
+ return (-1);
+}
+
+int
+__res_disable_mt(void) {
+ return (0);
+}
+
+#ifdef DO_PTHREADS
+static int
+__res_init_ctx(void) {
+
+ mtctxres_t *mt;
+ int ret;
+
+
+ if (pthread_getspecific(key) != 0) {
+ /* Already exists */
+ return (0);
+ }
+
+ if ((mt = malloc(sizeof (mtctxres_t))) == 0) {
+ errno = ENOMEM;
+ return (-1);
+ }
+
+ memset(mt, 0, sizeof (mtctxres_t));
+
+ if ((ret = pthread_setspecific(key, mt)) != 0) {
+ free(mt);
+ errno = ret;
+ return (-1);
+ }
+
+ return (0);
+}
+
+static void
+__res_destroy_ctx(void *value) {
+
+ mtctxres_t *mt = (mtctxres_t *)value;
+
+ if (mt != 0)
+ free(mt);
+}
+#endif
+
+mtctxres_t *
+___mtctxres(void) {
+#ifdef DO_PTHREADS
+ mtctxres_t *mt;
+
+ /*
+ * This if clause should only be executed if we are linking
+ * statically. When linked dynamically _mtctxres_init() should
+ * be called at binding time due the #pragma above.
+ */
+ if (!mt_key_initialized) {
+ static pthread_mutex_t keylock = PTHREAD_MUTEX_INITIALIZER;
+ if (pthread_mutex_lock(&keylock) == 0) {
+ _mtctxres_init();
+ (void) pthread_mutex_unlock(&keylock);
+ }
+ }
+
+ /*
+ * If we have already been called in this thread return the existing
+ * context. Otherwise recreat a new context and return it. If
+ * that fails return a global context.
+ */
+ if (mt_key_initialized) {
+ if (((mt = pthread_getspecific(key)) != 0) ||
+ (__res_init_ctx() == 0 &&
+ (mt = pthread_getspecific(key)) != 0)) {
+ return (mt);
+ }
+ }
+#endif
+ return (&sharedctx);
+}
diff --git a/usr/src/lib/libresolv2/common/resolv/res_comp.c b/usr/src/lib/libresolv2/common/resolv/res_comp.c
index a0a3d9abb2..59d5acc8ca 100644
--- a/usr/src/lib/libresolv2/common/resolv/res_comp.c
+++ b/usr/src/lib/libresolv2/common/resolv/res_comp.c
@@ -1,8 +1,9 @@
/*
- * Copyright 2003 by Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
+
/*
* Copyright (c) 1985, 1993
* The Regents of the University of California. All rights reserved.
@@ -57,27 +58,25 @@
*/
/*
+ * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Portions Copyright (c) 1996-1999 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.
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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.
*/
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#if defined(LIBC_SCCS) && !defined(lint)
static const char sccsid[] = "@(#)res_comp.c 8.1 (Berkeley) 6/4/93";
-static const char rcsid[] = "$Id: res_comp.c,v 8.16 2002/08/07 03:47:34 marka Exp $";
+static const char rcsid[] = "$Id: res_comp.c,v 1.5 2005/07/28 06:51:50 marka Exp $";
#endif /* LIBC_SCCS and not lint */
#include "port_before.h"
@@ -92,20 +91,21 @@ static const char rcsid[] = "$Id: res_comp.c,v 8.16 2002/08/07 03:47:34 marka Ex
#include <unistd.h>
#include "port_after.h"
-#ifdef ORIGINAL_ISC_CODE
-#else
+#ifndef ORIGINAL_ISC_CODE
#pragma weak __dn_skipname = dn_skipname
#pragma weak __res_dnok = res_dnok
#pragma weak __res_hnok = res_hnok
#pragma weak __res_mailok = res_mailok
#pragma weak __res_ownok = res_ownok
#endif /* ORIGINAL_ISC_CODE */
-/*
+
+/*%
* Expand compressed domain name 'src' to full domain name.
- * 'msg' is a pointer to the begining of the message,
- * 'eom' points to the first location after the message,
- * 'dst' is a pointer to a buffer of size 'dstsiz' for the result.
- * Return size of compressed name or -1 if there was an error.
+ *
+ * \li 'msg' is a pointer to the begining of the message,
+ * \li 'eom' points to the first location after the message,
+ * \li 'dst' is a pointer to a buffer of size 'dstsiz' for the result.
+ * \li Return size of compressed name or -1 if there was an error.
*/
int
dn_expand(const u_char *msg, const u_char *eom, const u_char *src,
@@ -118,10 +118,11 @@ dn_expand(const u_char *msg, const u_char *eom, const u_char *src,
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'.
+ *
+ * \li Return the size of the compressed name or -1.
+ * \li 'length' is the size of the array pointed to by 'comp_dn'.
*/
int
dn_comp(const char *src, u_char *dst, int dstsiz,
@@ -132,7 +133,8 @@ dn_comp(const char *src, u_char *dst, int dstsiz,
(const u_char **)lastdnptr));
}
-/*
+
+/*%
* Skip over a compressed domain name. Return the size or -1.
*/
int
@@ -144,11 +146,9 @@ dn_skipname(const u_char *ptr, const u_char *eom) {
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
@@ -176,7 +176,7 @@ dn_skipname(const u_char *ptr, const u_char *eom) {
int
res_hnok(const char *dn) {
- int ppch = '\0', pch = PERIOD, ch = *dn++;
+ int pch = PERIOD, ch = *dn++;
while (ch != '\0') {
int nch = *dn++;
@@ -193,12 +193,12 @@ res_hnok(const char *dn) {
if (!middlechar(ch))
return (0);
}
- ppch = pch, pch = ch, ch = nch;
+ 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.
*/
@@ -213,7 +213,7 @@ res_ownok(const char *dn) {
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.
*/
@@ -241,8 +241,8 @@ res_mailok(const char *dn) {
return (0);
}
-/*
- * This function is quite liberal, since RFC 1034's character sets are only
+/*%
+ * This function is quite liberal, since RFC1034's character sets are only
* recommendations.
*/
int
@@ -256,7 +256,7 @@ res_dnok(const char *dn) {
}
#ifdef BIND_4_COMPAT
-/*
+/*%
* This module must export the following externally-visible symbols:
* ___putlong
* ___putshort
@@ -264,17 +264,18 @@ res_dnok(const char *dn) {
* __getshort
* Note that one _ comes from C and the others come from us.
*/
-#ifdef ORIGINAL_ISC_CODE
-#else
-#ifdef __putlong
-#undef __putlong
+
+#ifdef SOLARIS2
+#ifdef __putlong
+#undef __putlong
#endif
-#ifdef __putshort
-#undef __putshort
+#ifdef __putshort
+#undef __putshort
#endif
-#pragma weak putlong = __putlong
-#pragma weak putshort = __putshort
-#endif /* ORIGINAL_ISC_CODE */
+#pragma weak putlong = __putlong
+#pragma weak putshort = __putshort
+#endif /* SOLARIS2 */
+
void __putlong(u_int32_t src, u_char *dst) { ns_put32(src, dst); }
void __putshort(u_int16_t src, u_char *dst) { ns_put16(src, dst); }
#ifndef __ultrix__
@@ -282,3 +283,5 @@ u_int32_t _getlong(const u_char *src) { return (ns_get32(src)); }
u_int16_t _getshort(const u_char *src) { return (ns_get16(src)); }
#endif /*__ultrix__*/
#endif /*BIND_4_COMPAT*/
+
+/*! \file */
diff --git a/usr/src/lib/libresolv2/common/resolv/res_data.c b/usr/src/lib/libresolv2/common/resolv/res_data.c
index 50368f6600..9297fe311f 100644
--- a/usr/src/lib/libresolv2/common/resolv/res_data.c
+++ b/usr/src/lib/libresolv2/common/resolv/res_data.c
@@ -1,29 +1,28 @@
/*
- * Copyright 2003 by Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
+
/*
+ * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1995-1999 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.
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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.
*/
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: res_data.c,v 8.18 2000/12/23 08:14:58 vixie Exp $";
+static const char rcsid[] = "$Id: res_data.c,v 1.7 2008/12/11 09:59:00 marka Exp $";
#endif /* LIBC_SCCS and not lint */
#include "port_before.h"
@@ -47,22 +46,21 @@ static const char rcsid[] = "$Id: res_data.c,v 8.18 2000/12/23 08:14:58 vixie Ex
#include <unistd.h>
#include "port_after.h"
-#undef _res
-#ifdef ORIGINAL_ISC_CODE
-#else
+#ifndef ORIGINAL_ISC_CODE
#pragma weak __fp_nquery = fp_nquery
#pragma weak __fp_query = fp_query
#pragma weak __p_query = p_query
#pragma weak __hostalias = hostalias
+#pragma weak __res_randomid = res_randomid
#endif
const char *_res_opcodes[] = {
"QUERY",
"IQUERY",
"CQUERYM",
- "CQUERYU", /* experimental */
- "NOTIFY", /* experimental */
+ "CQUERYU", /*%< experimental */
+ "NOTIFY", /*%< experimental */
"UPDATE",
"6",
"7",
@@ -85,13 +83,18 @@ const char *_res_sectioncodes[] = {
};
#endif
+#undef _res
#ifndef __BIND_NOSTATIC
struct __res_state _res
# if defined(__BIND_RES_TEXT)
- = { RES_TIMEOUT, } /* Motorola, et al. */
+ = { RES_TIMEOUT, } /*%< Motorola, et al. */
# endif
;
+#if defined(DO_PTHREADS) || defined(__linux)
+#define _res (*__res_state())
+#endif
+
/* Proto. */
int res_ourserver_p(const res_state, const struct sockaddr_in *);
@@ -131,7 +134,7 @@ res_init(void) {
* has set it to something in particular, we can randomize it now.
*/
if (!_res.id)
- _res.id = res_randomid();
+ _res.id = res_nrandomid(&_res);
return (__res_vinit(&_res, 1));
}
@@ -148,23 +151,23 @@ fp_query(const u_char *msg, FILE *file) {
void
fp_nquery(const u_char *msg, int len, FILE *file) {
- if ((_res.options & RES_INIT) == 0 && res_init() == -1)
+ if ((_res.options & RES_INIT) == 0U && res_init() == -1)
return;
res_pquery(&_res, msg, len, file);
}
int
-res_mkquery(int op, /* opcode of query */
- const char *dname, /* domain name */
- int class, int 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 */
+res_mkquery(int op, /*!< opcode of query */
+ const char *dname, /*!< domain name */
+ int class, int 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 */
{
- if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ if ((_res.options & RES_INIT) == 0U && res_init() == -1) {
RES_SET_H_ERRNO(&_res, NETDB_INTERNAL);
return (-1);
}
@@ -175,7 +178,7 @@ res_mkquery(int op, /* opcode of query */
int
res_mkupdate(ns_updrec *rrecp_in, u_char *buf, int buflen) {
- if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ if ((_res.options & RES_INIT) == 0U && res_init() == -1) {
RES_SET_H_ERRNO(&_res, NETDB_INTERNAL);
return (-1);
}
@@ -184,12 +187,12 @@ res_mkupdate(ns_updrec *rrecp_in, u_char *buf, int buflen) {
}
int
-res_query(const char *name, /* domain name */
- int class, int type, /* class and type of query */
- u_char *answer, /* buffer to put answer */
- int anslen) /* size of answer buffer */
+res_query(const char *name, /*!< domain name */
+ int class, int type, /*!< class and type of query */
+ u_char *answer, /*!< buffer to put answer */
+ int anslen) /*!< size of answer buffer */
{
- if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ if ((_res.options & RES_INIT) == 0U && res_init() == -1) {
RES_SET_H_ERRNO(&_res, NETDB_INTERNAL);
return (-1);
}
@@ -213,7 +216,7 @@ res_isourserver(const struct sockaddr_in *inp) {
int
res_send(const u_char *buf, int buflen, u_char *ans, int anssiz) {
- if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ if ((_res.options & RES_INIT) == 0U && res_init() == -1) {
/* errno should have been set by res_init() in this case. */
return (-1);
}
@@ -225,7 +228,7 @@ int
res_sendsigned(const u_char *buf, int buflen, ns_tsig_key *key,
u_char *ans, int anssiz)
{
- if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ if ((_res.options & RES_INIT) == 0U && res_init() == -1) {
/* errno should have been set by res_init() in this case. */
return (-1);
}
@@ -240,7 +243,7 @@ res_close(void) {
int
res_update(ns_updrec *rrecp_in) {
- if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ if ((_res.options & RES_INIT) == 0U && res_init() == -1) {
RES_SET_H_ERRNO(&_res, NETDB_INTERNAL);
return (-1);
}
@@ -249,12 +252,12 @@ res_update(ns_updrec *rrecp_in) {
}
int
-res_search(const char *name, /* domain name */
- int class, int type, /* class and type of query */
- u_char *answer, /* buffer to put answer */
- int anslen) /* size of answer */
+res_search(const char *name, /*!< domain name */
+ int class, int type, /*!< class and type of query */
+ u_char *answer, /*!< buffer to put answer */
+ int anslen) /*!< size of answer */
{
- if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ if ((_res.options & RES_INIT) == 0U && res_init() == -1) {
RES_SET_H_ERRNO(&_res, NETDB_INTERNAL);
return (-1);
}
@@ -265,11 +268,11 @@ res_search(const char *name, /* domain name */
int
res_querydomain(const char *name,
const char *domain,
- int class, int type, /* class and type of query */
- u_char *answer, /* buffer to put answer */
- int anslen) /* size of answer */
+ int class, int type, /*!< class and type of query */
+ u_char *answer, /*!< buffer to put answer */
+ int anslen) /*!< size of answer */
{
- if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ if ((_res.options & RES_INIT) == 0U && res_init() == -1) {
RES_SET_H_ERRNO(&_res, NETDB_INTERNAL);
return (-1);
}
@@ -279,6 +282,16 @@ res_querydomain(const char *name,
answer, anslen));
}
+u_int
+res_randomid(void) {
+ if ((_res.options & RES_INIT) == 0U && res_init() == -1) {
+ RES_SET_H_ERRNO(&_res, NETDB_INTERNAL);
+ return (-1);
+ }
+
+ return (res_nrandomid(&_res));
+}
+
const char *
hostalias(const char *name) {
static char abuf[MAXDNAME];
@@ -304,3 +317,5 @@ local_hostname_length(const char *hostname) {
#endif /*ultrix*/
#endif
+
+/*! \file */
diff --git a/usr/src/lib/libresolv2/common/resolv/res_debug.c b/usr/src/lib/libresolv2/common/resolv/res_debug.c
index 838ed3fd8a..4300ea2722 100644
--- a/usr/src/lib/libresolv2/common/resolv/res_debug.c
+++ b/usr/src/lib/libresolv2/common/resolv/res_debug.c
@@ -1,12 +1,30 @@
/*
- * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
+
+/*
+ * Portions Copyright (C) 2004, 2005, 2008, 2009 Internet Systems Consortium, Inc. ("ISC")
+ * Portions Copyright (C) 1996-2003 Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and/or 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 ISC DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS. IN NO EVENT SHALL ISC 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 (c) 1985
* 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:
@@ -22,7 +40,7 @@
* 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
@@ -38,14 +56,14 @@
/*
* 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
@@ -81,28 +99,9 @@
* IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
-/*
- * Portions Copyright (c) 1996-1999 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.
- */
-
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#if defined(LIBC_SCCS) && !defined(lint)
static const char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93";
-static const char rcsid[] = "$Id: res_debug.c,v 8.50 2003/04/16 04:55:40 marka Exp $";
+static const char rcsid[] = "$Id: res_debug.c,v 1.19 2009/02/26 11:20:20 tbox Exp $";
#endif /* LIBC_SCCS and not lint */
#include "port_before.h"
@@ -120,6 +119,7 @@ static const char rcsid[] = "$Id: res_debug.c,v 8.50 2003/04/16 04:55:40 marka E
#include <math.h>
#include <netdb.h>
#include <resolv.h>
+#include <resolv_mt.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -136,15 +136,13 @@ static const char rcsid[] = "$Id: res_debug.c,v 8.50 2003/04/16 04:55:40 marka E
extern const char *_res_opcodes[];
extern const char *_res_sectioncodes[];
-#ifdef ORIGINAL_ISC_CODE
-#else
+#ifndef ORIGINAL_ISC_CODE
#pragma weak __dn_count_labels = dn_count_labels
#pragma weak __fp_resstat = fp_resstat
#pragma weak __loc_aton = loc_aton
#pragma weak __loc_ntoa = loc_ntoa
#pragma weak __p_cdname = p_cdname
#pragma weak __p_class = p_class
-#pragma weak __p_secstodate = p_secstodate
#pragma weak __p_section = p_section
#pragma weak __p_time = p_time
#pragma weak __p_type = p_type
@@ -153,7 +151,7 @@ extern const char *_res_sectioncodes[];
#pragma weak __sym_ston = sym_ston
#endif /* ORIGINAL_ISC_CODE */
-/*
+/*%
* Print the current options.
*/
void
@@ -161,7 +159,7 @@ fp_resstat(const res_state statp, FILE *file) {
u_long mask;
fprintf(file, ";; res options:");
- for (mask = 1; mask != 0; mask <<= 1)
+ for (mask = 1; mask != 0U; mask <<= 1)
if (statp->options & mask)
fprintf(file, " %s", p_option(mask));
putc('\n', file);
@@ -212,10 +210,56 @@ do_section(const res_state statp,
p_type(ns_rr_type(rr)),
p_class(ns_rr_class(rr)));
else if (section == ns_s_ar && ns_rr_type(rr) == ns_t_opt) {
+ u_int16_t optcode, optlen, rdatalen = ns_rr_rdlen(rr);
u_int32_t ttl = ns_rr_ttl(rr);
+
fprintf(file,
"; EDNS: version: %u, udp=%u, flags=%04x\n",
(ttl>>16)&0xff, ns_rr_class(rr), ttl&0xffff);
+
+ while (rdatalen >= 4) {
+ const u_char *cp = ns_rr_rdata(rr);
+ int i;
+
+ GETSHORT(optcode, cp);
+ GETSHORT(optlen, cp);
+
+ if (optcode == NS_OPT_NSID) {
+ fputs("; NSID: ", file);
+ if (optlen == 0) {
+ fputs("; NSID\n", file);
+ } else {
+ fputs("; NSID: ", file);
+ for (i = 0; i < optlen; i++)
+ fprintf(file, "%02x ",
+ cp[i]);
+ fputs(" (",file);
+ for (i = 0; i < optlen; i++)
+ fprintf(file, "%c",
+ isprint(cp[i])?
+ cp[i] : '.');
+ fputs(")\n", file);
+ }
+ } else {
+ if (optlen == 0) {
+ fprintf(file, "; OPT=%u\n",
+ optcode);
+ } else {
+ fprintf(file, "; OPT=%u: ",
+ optcode);
+ for (i = 0; i < optlen; i++)
+ fprintf(file, "%02x ",
+ cp[i]);
+ fputs(" (",file);
+ for (i = 0; i < optlen; i++)
+ fprintf(file, "%c",
+ isprint(cp[i]) ?
+ cp[i] : '.');
+ fputs(")\n", file);
+ }
+ }
+ rdatalen -= 4 + optlen;
+ }
} else {
n = ns_sprintrr(handle, &rr, NULL, NULL,
buf, buflen);
@@ -227,7 +271,7 @@ do_section(const res_state statp,
buf = malloc(buflen += 1024);
if (buf == NULL) {
fprintf(file,
- ";; memory allocation failure\n");
+ ";; memory allocation failure\n");
return;
}
continue;
@@ -246,7 +290,7 @@ do_section(const res_state statp,
free(buf);
}
-/*
+/*%
* Print the contents of a query.
* This is intended to be primarily a debugging routine.
*/
@@ -306,7 +350,7 @@ res_pquery(const res_state statp, const u_char *msg, int len, FILE *file) {
fprintf(file, ", %s: %d",
p_section(ns_s_ar, opcode), arcount);
}
- if ((!statp->pfcode) || (statp->pfcode &
+ if ((!statp->pfcode) || (statp->pfcode &
(RES_PRF_HEADX | RES_PRF_HEAD2 | RES_PRF_HEAD1))) {
putc('\n',file);
}
@@ -341,7 +385,8 @@ p_cdname(const u_char *cp, const u_char *msg, FILE *file) {
return (p_cdnname(cp, msg, PACKETSZ, file));
}
-/* Return a fully-qualified domain name from a compressed name (with
+/*%
+ * Return a fully-qualified domain name from a compressed name (with
length supplied). */
const u_char *
@@ -357,7 +402,7 @@ p_fqnname(cp, msg, msglen, name, namelen)
return (NULL);
newlen = strlen(name);
if (newlen == 0 || name[newlen - 1] != '.') {
- if (newlen + 1 >= namelen) /* Lack space for final dot */
+ if (newlen + 1 >= namelen) /*%< Lack space for final dot */
return (NULL);
else
strcpy(name + newlen, ".");
@@ -379,13 +424,14 @@ p_fqname(const u_char *cp, const u_char *msg, FILE *file) {
return (n);
}
-/*
+/*%
* 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", (char *)0},
+ {C_CHAOS, "CH", (char *)0},
{C_CHAOS, "CHAOS", (char *)0},
{C_HS, "HS", (char *)0},
{C_HS, "HESIOD", (char *)0},
@@ -394,7 +440,7 @@ const struct res_sym __p_class_syms[] = {
{C_IN, (char *)0, (char *)0}
};
-/*
+/*%
* Names of message sections.
*/
const struct res_sym __p_default_section_syms[] = {
@@ -402,7 +448,7 @@ const struct res_sym __p_default_section_syms[] = {
{ns_s_an, "ANSWER", (char *)0},
{ns_s_ns, "AUTHORITY", (char *)0},
{ns_s_ar, "ADDITIONAL", (char *)0},
- {0, (char *)0, (char *)0}
+ {0, (char *)0, (char *)0}
};
const struct res_sym __p_update_section_syms[] = {
@@ -410,7 +456,7 @@ const struct res_sym __p_update_section_syms[] = {
{S_PREREQ, "PREREQUISITE", (char *)0},
{S_UPDATE, "UPDATE", (char *)0},
{S_ADDT, "ADDITIONAL", (char *)0},
- {0, (char *)0, (char *)0}
+ {0, (char *)0, (char *)0}
};
const struct res_sym __p_key_syms[] = {
@@ -431,7 +477,7 @@ const struct res_sym __p_cert_syms[] = {
{0, NULL, NULL}
};
-/*
+/*%
* 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.)
@@ -471,6 +517,24 @@ const struct res_sym __p_type_syms[] = {
{ns_t_nimloc, "NIMLOC", "NIMROD locator (unimplemented)"},
{ns_t_srv, "SRV", "server selection"},
{ns_t_atma, "ATMA", "ATM address (unimplemented)"},
+ {ns_t_naptr, "NAPTR", "naptr"},
+ {ns_t_kx, "KX", "key exchange"},
+ {ns_t_cert, "CERT", "certificate"},
+ {ns_t_a6, "A", "IPv6 address (experminental)"},
+ {ns_t_dname, "DNAME", "non-terminal redirection"},
+ {ns_t_opt, "OPT", "opt"},
+ {ns_t_apl, "apl", "apl"},
+ {ns_t_ds, "DS", "delegation signer"},
+ {ns_t_sshfp, "SSFP", "SSH fingerprint"},
+ {ns_t_ipseckey, "IPSECKEY", "IPSEC key"},
+ {ns_t_rrsig, "RRSIG", "rrsig"},
+ {ns_t_nsec, "NSEC", "nsec"},
+ {ns_t_dnskey, "DNSKEY", "DNS key"},
+ {ns_t_dhcid, "DHCID", "dynamic host configuration identifier"},
+ {ns_t_nsec3, "NSEC3", "nsec3"},
+ {ns_t_nsec3param, "NSEC3PARAM", "NSEC3 parameters"},
+ {ns_t_hip, "HIP", "host identity protocol"},
+ {ns_t_spf, "SPF", "sender policy framework"},
{ns_t_tkey, "TKEY", "tkey"},
{ns_t_tsig, "TSIG", "transaction signature"},
{ns_t_ixfr, "IXFR", "incremental zone transfer"},
@@ -486,10 +550,11 @@ const struct res_sym __p_type_syms[] = {
{ns_t_sink, "SINK", "Kitchen Sink (experimental)"},
{ns_t_opt, "OPT", "EDNS Options"},
{ns_t_any, "ANY", "\"any\""},
+ {ns_t_dlv, "DLV", "DNSSEC look-aside validation"},
{0, NULL, NULL}
};
-/*
+/*%
* Names of DNS rcodes.
*/
const struct res_sym __p_rcode_syms[] = {
@@ -522,16 +587,12 @@ sym_ston(const struct res_sym *syms, const char *name, int *success) {
}
if (success)
*success = 0;
- return (syms->number); /* The default value. */
+ return (syms->number); /*%< The default value. */
}
const char *
sym_ntos(const struct res_sym *syms, int number, int *success) {
-#ifdef SUNW_MT_RESOLVER
- char *unname = sym_ntos_unname;
-#else
- static char unname[20];
-#endif /* SUNW_MT_RESOLVER */
+ char *unname = sym_ntos_unname;
for ((void)NULL; syms->name != 0; syms++) {
if (number == syms->number) {
@@ -541,7 +602,7 @@ sym_ntos(const struct res_sym *syms, int number, int *success) {
}
}
- sprintf(unname, "%d", number); /* XXX nonreentrant */
+ sprintf(unname, "%d", number); /*%< XXX nonreentrant */
if (success)
*success = 0;
return (unname);
@@ -549,11 +610,7 @@ sym_ntos(const struct res_sym *syms, int number, int *success) {
const char *
sym_ntop(const struct res_sym *syms, int number, int *success) {
-#ifdef SUNW_MT_RESOLVER
- char *unname = sym_ntop_unname;
-#else
- static char unname[20];
-#endif /* SUNW_MT_RESOLVER */
+ char *unname = sym_ntop_unname;
for ((void)NULL; syms->name != 0; syms++) {
if (number == syms->number) {
@@ -562,13 +619,13 @@ sym_ntop(const struct res_sym *syms, int number, int *success) {
return (syms->humanname);
}
}
- sprintf(unname, "%d", number); /* XXX nonreentrant */
+ sprintf(unname, "%d", number); /*%< XXX nonreentrant */
if (success)
*success = 0;
return (unname);
}
-/*
+/*%
* Return a string for the type.
*/
const char *
@@ -580,13 +637,13 @@ p_type(int type) {
result = sym_ntos(__p_type_syms, type, &success);
if (success)
return (result);
- if (type < 0 || type > 0xfff)
+ if (type < 0 || type > 0xffff)
return ("BADTYPE");
sprintf(typebuf, "TYPE%d", type);
return (typebuf);
}
-/*
+/*%
* Return a string for the type.
*/
const char *
@@ -604,7 +661,7 @@ p_section(int section, int opcode) {
return (sym_ntos(symbols, section, (int *)0));
}
-/*
+/*%
* Return a mnemonic for class.
*/
const char *
@@ -616,26 +673,18 @@ p_class(int class) {
result = sym_ntos(__p_class_syms, class, &success);
if (success)
return (result);
- if (class < 0 || class > 0xfff)
+ if (class < 0 || class > 0xffff)
return ("BADCLASS");
sprintf(classbuf, "CLASS%d", class);
return (classbuf);
}
-/*
+/*%
* Return a mnemonic for an option
*/
const char *
-#ifdef ORIGINAL_ISC_CODE
p_option(u_long option) {
-#else
-p_option(u_int option) {
-#endif
-#ifdef SUNW_MT_RESOLVER
- char *nbuf = p_option_nbuf;
-#else
- static char nbuf[40];
-#endif /* SUNW_MT_RESOLVER */
+ char *nbuf = p_option_nbuf;
switch (option) {
case RES_INIT: return "init";
@@ -652,8 +701,9 @@ p_option(u_int option) {
case RES_INSECURE2: return "insecure2";
case RES_NOALIASES: return "noaliases";
case RES_USE_INET6: return "inet6";
-#ifdef RES_USE_EDNS0 /* KAME extension */
+#ifdef RES_USE_EDNS0 /*%< KAME extension */
case RES_USE_EDNS0: return "edns0";
+ case RES_NSID: return "nsid";
#endif
#ifdef RES_USE_DNAME
case RES_USE_DNAME: return "dname";
@@ -664,33 +714,28 @@ p_option(u_int option) {
#ifdef RES_NOTLDQUERY
case RES_NOTLDQUERY: return "no-tld-query";
#endif
-#ifdef ORIGINAL_ISC_CODE
+#ifdef RES_NO_NIBBLE2
+ case RES_NO_NIBBLE2: return "no-nibble2";
+#endif
/* XXX nonreentrant */
default: sprintf(nbuf, "?0x%lx?", (u_long)option);
-#else
- default: sprintf(nbuf, "?0x%x?", (u_int)option);
-#endif
return (nbuf);
}
}
-/*
+/*%
* Return a mnemonic for a time to live.
*/
const char *
p_time(u_int32_t value) {
-#ifdef SUNW_MT_RESOLVER
- char *nbuf = p_time_nbuf;
-#else
- static char nbuf[40]; /* XXX nonreentrant */
-#endif /* SUNW_MT_RESOLVER */
+ char *nbuf = p_time_nbuf;
if (ns_format_ttl(value, nbuf, sizeof nbuf) < 0)
sprintf(nbuf, "%u", value);
return (nbuf);
}
-/*
+/*%
* Return a string for the rcode.
*/
const char *
@@ -698,7 +743,7 @@ p_rcode(int rcode) {
return (sym_ntos(__p_rcode_syms, rcode, (int *)0));
}
-/*
+/*%
* Return a string for a res_sockaddr_union.
*/
const char *
@@ -718,14 +763,14 @@ p_sockun(union res_sockaddr_union u, char *buf, size_t size) {
sprintf(ret, "[af%d]", u.sin.sin_family);
break;
}
- if (size > 0) {
+ if (size > 0U) {
strncpy(buf, ret, size - 1);
buf[size - 1] = '0';
}
return (buf);
}
-/*
+/*%
* 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.
@@ -734,16 +779,12 @@ p_sockun(union res_sockaddr_union u, char *buf, size_t size) {
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. */
+/*% takes an XeY precision/size value, returns a string representation. */
static const char *
precsize_ntoa(prec)
u_int8_t prec;
{
-#ifdef SUNW_MT_RESOLVER
- char *retbuf = precsize_ntoa_retbuf;
-#else
- static char retbuf[sizeof "90000000.00"]; /* XXX nonreentrant */
-#endif /* SUNW_MT_RESOLVER */
+ char *retbuf = precsize_ntoa_retbuf;
unsigned long val;
int mantissa, exponent;
@@ -756,7 +797,7 @@ precsize_ntoa(prec)
return (retbuf);
}
-/* converts ascii size/precision X * 10**Y(cm) to 0xXY. moves pointer. */
+/*% converts ascii size/precision X * 10**Y(cm) to 0xXY. moves pointer. */
static u_int8_t
precsize_aton(const char **strptr) {
unsigned int mval = 0, cmval = 0;
@@ -770,7 +811,7 @@ precsize_aton(const char **strptr) {
while (isdigit((unsigned char)*cp))
mval = mval * 10 + (*cp++ - '0');
- if (*cp == '.') { /* centimeters */
+ if (*cp == '.') { /*%< centimeters */
cp++;
if (isdigit((unsigned char)*cp)) {
cmval = (*cp++ - '0') * 10;
@@ -796,7 +837,7 @@ precsize_aton(const char **strptr) {
return (retval);
}
-/* converts ascii lat/lon to unsigned encoded 32-bit number. moves pointer. */
+/*% converts ascii lat/lon to unsigned encoded 32-bit number. moves pointer. */
static u_int32_t
latlon2ul(const char **latlonstrptr, int *which) {
const char *cp;
@@ -826,7 +867,7 @@ latlon2ul(const char **latlonstrptr, int *which) {
while (isdigit((unsigned char)*cp))
secs = secs * 10 + (*cp++ - '0');
- if (*cp == '.') { /* decimal seconds */
+ if (*cp == '.') { /*%< decimal seconds */
cp++;
if (isdigit((unsigned char)*cp)) {
secsfrac = (*cp++ - '0') * 100;
@@ -839,7 +880,7 @@ latlon2ul(const char **latlonstrptr, int *which) {
}
}
- while (!isspace((unsigned char)*cp)) /* if any trailing garbage */
+ while (!isspace((unsigned char)*cp)) /*%< if any trailing garbage */
cp++;
while (isspace((unsigned char)*cp))
@@ -860,30 +901,29 @@ latlon2ul(const char **latlonstrptr, int *which) {
- secsfrac;
break;
default:
- retval = 0; /* invalid value -- indicates error */
+ retval = 0; /*%< invalid value -- indicates error */
break;
}
switch (*cp) {
case 'N': case 'n':
case 'S': case 's':
- *which = 1; /* latitude */
+ *which = 1; /*%< latitude */
break;
case 'E': case 'e':
case 'W': case 'w':
- *which = 2; /* longitude */
+ *which = 2; /*%< longitude */
break;
default:
- *which = 0; /* error */
+ *which = 0; /*%< error */
break;
}
- cp++; /* skip the hemisphere */
-
- while (!isspace((unsigned char)*cp)) /* if any trailing garbage */
+ cp++; /*%< skip the hemisphere */
+ while (!isspace((unsigned char)*cp)) /*%< if any trailing garbage */
cp++;
- while (isspace((unsigned char)*cp)) /* move to next field */
+ while (isspace((unsigned char)*cp)) /*%< move to next field */
cp++;
*latlonstrptr = cp;
@@ -891,7 +931,8 @@ latlon2ul(const char **latlonstrptr, int *which) {
return (retval);
}
-/* converts a zone file representation in a string to an RDATA on-the-wire
+/*%
+ * converts a zone file representation in a string to an RDATA on-the-wire
* representation. */
int
loc_aton(ascii, binary)
@@ -904,9 +945,9 @@ loc_aton(ascii, binary)
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 */
+ 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;
@@ -917,18 +958,18 @@ loc_aton(ascii, binary)
lltemp2 = latlon2ul(&cp, &which2);
switch (which1 + which2) {
- case 3: /* 1 + 2, the only valid combination */
- if ((which1 == 1) && (which2 == 2)) { /* normal case */
+ 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 */
+ } else if ((which1 == 2) && (which2 == 1)) { /*%< reversed */
longit = lltemp1;
latit = lltemp2;
- } else { /* some kind of brokenness */
+ } else { /*%< some kind of brokenness */
return (0);
}
break;
- default: /* we didn't get one of each */
+ default: /*%< we didn't get one of each */
return (0);
}
@@ -937,14 +978,14 @@ loc_aton(ascii, binary)
altsign = -1;
cp++;
}
-
+
if (*cp == '+')
cp++;
while (isdigit((unsigned char)*cp))
altmeters = altmeters * 10 + (*cp++ - '0');
- if (*cp == '.') { /* decimal meters */
+ if (*cp == '.') { /*%< decimal meters */
cp++;
if (isdigit((unsigned char)*cp)) {
altfrac = (*cp++ - '0') * 10;
@@ -956,7 +997,7 @@ loc_aton(ascii, binary)
alt = (10000000 + (altsign * (altmeters * 100 + altfrac)));
- while (!isspace((unsigned char)*cp) && (cp < maxcp)) /* if trailing garbage or m */
+ while (!isspace((unsigned char)*cp) && (cp < maxcp)) /*%< if trailing garbage or m */
cp++;
while (isspace((unsigned char)*cp) && (cp < maxcp))
@@ -966,8 +1007,8 @@ loc_aton(ascii, binary)
goto defaults;
siz = precsize_aton(&cp);
-
- while (!isspace((unsigned char)*cp) && (cp < maxcp)) /* if trailing garbage or m */
+
+ while (!isspace((unsigned char)*cp) && (cp < maxcp)) /*%< if trailing garbage or m */
cp++;
while (isspace((unsigned char)*cp) && (cp < maxcp))
@@ -978,7 +1019,7 @@ loc_aton(ascii, binary)
hp = precsize_aton(&cp);
- while (!isspace((unsigned char)*cp) && (cp < maxcp)) /* if trailing garbage or m */
+ while (!isspace((unsigned char)*cp) && (cp < maxcp)) /*%< if trailing garbage or m */
cp++;
while (isspace((unsigned char)*cp) && (cp < maxcp))
@@ -992,30 +1033,26 @@ loc_aton(ascii, binary)
defaults:
bcp = binary;
- *bcp++ = (u_int8_t) 0; /* version byte */
+ *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 */
+
+ return (16); /*%< size of RR in octets */
}
-/* takes an on-the-wire LOC RR and formats it in a human readable format. */
+/*% 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 const char *error = "?";
-#ifdef SUNW_MT_RESOLVER
- char *tmpbuf = loc_ntoa_tmpbuf;
-#else
static char tmpbuf[sizeof
"1000 60 60.000 N 1000 60 60.000 W -12345678.00m 90000000.00m 90000000.00m 90000000.00m"];
-#endif /* SUNW_MT_RESOLVER */
const u_char *cp = binary;
int latdeg, latmin, latsec, latsecfrac;
@@ -1029,7 +1066,7 @@ loc_ntoa(binary, ascii)
int32_t latval, longval, altval;
u_int32_t templ;
u_int8_t sizeval, hpval, vpval, versionval;
-
+
char *sizestr, *hpstr, *vpstr;
versionval = *cp++;
@@ -1054,7 +1091,7 @@ loc_ntoa(binary, ascii)
longval = (templ - ((unsigned)1<<31));
GETLONG(templ, cp);
- if (templ < referencealt) { /* below WGS 84 spheroid */
+ if (templ < referencealt) { /*%< below WGS 84 spheroid */
altval = referencealt - templ;
altsign = "-";
} else {
@@ -1117,7 +1154,7 @@ loc_ntoa(binary, ascii)
}
-/* Return the number of DNS hierarchy levels in the name. */
+/*% Return the number of DNS hierarchy levels in the name. */
int
dn_count_labels(const char *name) {
int i, len, count;
@@ -1142,28 +1179,19 @@ dn_count_labels(const char *name) {
return (count);
}
-
-/*
- * Make dates expressed in seconds-since-Jan-1-1970 easy to read.
+/*%
+ * 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 *
-#ifdef ORIGINAL_ISC_CODE
p_secstodate (u_long secs) {
-#else
-p_secstodate (u_int secs) {
-#endif
-#ifdef SUNW_MT_RESOLVER
- char *output = p_secstodate_output;
-#else
- /* XXX nonreentrant */
- static char output[15]; /* YYYYMMDDHHMMSS and null */
-#endif /* SUNW_MT_RESOLVER */
+ char *output = p_secstodate_output;
time_t clock = secs;
struct tm *time;
-
#ifdef HAVE_TIME_R
- gmtime_r(&clock, &time);
+ struct tm res;
+
+ time = gmtime_r(&clock, &res);
#else
time = gmtime(&clock);
#endif
@@ -1190,7 +1218,7 @@ res_nametoclass(const char *buf, int *successp) {
goto done;
errno = 0;
result = strtoul(buf + 5, &endptr, 10);
- if (errno == 0 && *endptr == '\0' && result <= 0xffff)
+ if (errno == 0 && *endptr == '\0' && result <= 0xffffU)
success = 1;
done:
if (successp)
@@ -1213,10 +1241,12 @@ res_nametotype(const char *buf, int *successp) {
goto done;
errno = 0;
result = strtoul(buf + 4, &endptr, 10);
- if (errno == 0 && *endptr == '\0' && result <= 0xffff)
+ if (errno == 0 && *endptr == '\0' && result <= 0xffffU)
success = 1;
done:
if (successp)
*successp = success;
return (result);
}
+
+/*! \file */
diff --git a/usr/src/lib/libresolv2/common/resolv/res_debug.h b/usr/src/lib/libresolv2/common/resolv/res_debug.h
index 1395d7a207..c28171d7c8 100644
--- a/usr/src/lib/libresolv2/common/resolv/res_debug.h
+++ b/usr/src/lib/libresolv2/common/resolv/res_debug.h
@@ -1,30 +1,23 @@
/*
- * Copyright (c) 2001 by Sun Microsystems, Inc.
- * All rights reserved.
- */
-
-/*
+ * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1999 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.
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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 _RES_DEBUG_H_
#define _RES_DEBUG_H_
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#ifndef DEBUG
# define Dprint(cond, args) /*empty*/
# define DprintQ(cond, args, query, size) /*empty*/
@@ -39,3 +32,4 @@
#endif
#endif /* _RES_DEBUG_H_ */
+/*! \file */
diff --git a/usr/src/lib/libresolv2/common/resolv/res_findzonecut.c b/usr/src/lib/libresolv2/common/resolv/res_findzonecut.c
index 65be96235b..933169e3ab 100644
--- a/usr/src/lib/libresolv2/common/resolv/res_findzonecut.c
+++ b/usr/src/lib/libresolv2/common/resolv/res_findzonecut.c
@@ -1,29 +1,22 @@
-/*
- * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#if !defined(lint) && !defined(SABER)
-static const char rcsid[] = "$Id: res_findzonecut.c,v 8.20 2003/05/27 23:36:53 marka Exp $";
+static const char rcsid[] = "$Id: res_findzonecut.c,v 1.10 2005/10/11 00:10:16 marka Exp $";
#endif /* not lint */
/*
+ * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1999 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.
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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.
*/
/* Import. */
@@ -97,61 +90,62 @@ static void res_dprintf(const char *, ...) ISC_FORMAT_PRINTF(1, 2);
#define DPRINTF(x) do {\
int save_errno = errno; \
- if ((statp->options & RES_DEBUG) != 0) res_dprintf x; \
+ if ((statp->options & RES_DEBUG) != 0U) res_dprintf x; \
errno = save_errno; \
} while (0)
/* Public. */
-/*
- * int
- * res_findzonecut(res, dname, class, zname, zsize, addrs, naddrs)
+/*%
* find enclosing zone for a <dname,class>, and some server addresses
+ *
* parameters:
- * res - resolver context to work within (is modified)
- * dname - domain name whose enclosing zone is desired
- * class - class of dname (and its enclosing zone)
- * zname - found zone name
- * zsize - allocated size of zname
- * addrs - found server addresses
- * naddrs - max number of addrs
+ *\li res - resolver context to work within (is modified)
+ *\li dname - domain name whose enclosing zone is desired
+ *\li class - class of dname (and its enclosing zone)
+ *\li zname - found zone name
+ *\li zsize - allocated size of zname
+ *\li addrs - found server addresses
+ *\li naddrs - max number of addrs
+ *
* return values:
- * < 0 - an error occurred (check errno)
- * = 0 - zname is now valid, but addrs[] wasn't changed
- * > 0 - zname is now valid, and return value is number of addrs[] found
+ *\li < 0 - an error occurred (check errno)
+ *\li = 0 - zname is now valid, but addrs[] wasn't changed
+ *\li > 0 - zname is now valid, and return value is number of addrs[] found
+ *
* notes:
- * this function calls res_nsend() which means it depends on correctly
+ *\li this function calls res_nsend() which means it depends on correctly
* functioning recursive nameservers (usually defined in /etc/resolv.conf
* or its local equivilent).
*
- * we start by asking for an SOA<dname,class>. if we get one as an
+ *\li we start by asking for an SOA<dname,class>. if we get one as an
* answer, that just means <dname,class> is a zone top, which is fine.
* more than likely we'll be told to go pound sand, in the form of a
* negative answer.
*
- * note that we are not prepared to deal with referrals since that would
+ *\li note that we are not prepared to deal with referrals since that would
* only come from authority servers and our correctly functioning local
* recursive server would have followed the referral and got us something
* more definite.
*
- * if the authority section contains an SOA, this SOA should also be the
+ *\li if the authority section contains an SOA, this SOA should also be the
* closest enclosing zone, since any intermediary zone cuts would've been
* returned as referrals and dealt with by our correctly functioning local
* recursive name server. but an SOA in the authority section should NOT
* match our dname (since that would have been returned in the answer
* section). an authority section SOA has to be "above" our dname.
*
- * however, since authority section SOA's were once optional, it's
+ *\li however, since authority section SOA's were once optional, it's
* possible that we'll have to go hunting for the enclosing SOA by
* ripping labels off the front of our dname -- this is known as "doing
* it the hard way."
*
- * ultimately we want some server addresses, which are ideally the ones
+ *\li ultimately we want some server addresses, which are ideally the ones
* pertaining to the SOA.MNAME, but only if there is a matching NS RR.
* so the second phase (after we find an SOA) is to go looking for the
* NS RRset for that SOA's zone.
*
- * no answer section processed by this code is allowed to contain CNAME
+ *\li no answer section processed by this code is allowed to contain CNAME
* or DNAME RR's. for the SOA query this means we strip a label and
* keep going. for the NS and A queries this means we just give up.
*/
@@ -326,7 +320,6 @@ get_soa(res_state statp, const char *dname, ns_class class, int opts,
for (i = 0; i < n; i++) {
const char *t;
const u_char *rdata;
- int rdlen;
ns_rr rr;
if (ns_parserr(&msg, sect, i, &rr) < 0) {
@@ -367,14 +360,14 @@ get_soa(res_state statp, const char *dname, ns_class class, int opts,
abort();
}
if (strlen(t) + 1 > zsize) {
- DPRINTF(("get_soa: zname(%d) too small (%d)",
- zsize, strlen(t) + 1));
+ DPRINTF(("get_soa: zname(%lu) too small (%lu)",
+ (unsigned long)zsize,
+ (unsigned long)strlen(t) + 1));
errno = EMSGSIZE;
goto cleanup;
}
strcpy(zname, t);
rdata = ns_rr_rdata(rr);
- rdlen = ns_rr_rdlen(rr);
if (ns_name_uncompress(resp, ns_msg_end(msg), rdata,
mname, msize) < 0) {
DPRINTF(("get_soa: ns_name_uncompress failed")
@@ -532,7 +525,6 @@ save_ns(res_state statp, ns_msg *msg, ns_sect sect,
const u_char *rdata;
rr_ns *nsrr;
ns_rr rr;
- int rdlen;
if (ns_parserr(msg, sect, i, &rr) < 0) {
DPRINTF(("save_ns: ns_parserr(%s, %d) failed",
@@ -551,7 +543,6 @@ save_ns(res_state statp, ns_msg *msg, ns_sect sect,
return (-1);
}
rdata = ns_rr_rdata(rr);
- rdlen = ns_rr_rdlen(rr);
if (ns_name_uncompress(ns_msg_base(*msg),
ns_msg_end(*msg), rdata,
tname, sizeof tname) < 0) {
@@ -727,3 +718,5 @@ res_dprintf(const char *fmt, ...) {
fputc('\n', stderr);
va_end(ap);
}
+
+/*! \file */
diff --git a/usr/src/lib/libresolv2/common/resolv/res_init.c b/usr/src/lib/libresolv2/common/resolv/res_init.c
index 33ccc9ece7..e839323a79 100644
--- a/usr/src/lib/libresolv2/common/resolv/res_init.c
+++ b/usr/src/lib/libresolv2/common/resolv/res_init.c
@@ -1,8 +1,9 @@
/*
- * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
+
/*
* Copyright (c) 1985, 1989, 1993
* The Regents of the University of California. All rights reserved.
@@ -57,27 +58,25 @@
*/
/*
+ * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Portions Copyright (c) 1996-1999 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.
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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.
*/
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#if defined(LIBC_SCCS) && !defined(lint)
static const char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93";
-static const char rcsid[] = "$Id: res_init.c,v 8.32 2003/04/03 06:31:10 marka Exp $";
+static const char rcsid[] = "$Id: res_init.c,v 1.26 2008/12/11 09:59:00 marka Exp $";
#endif /* LIBC_SCCS and not lint */
#include "port_before.h"
@@ -98,14 +97,30 @@ static const char rcsid[] = "$Id: res_init.c,v 8.32 2003/04/03 06:31:10 marka Ex
#include <unistd.h>
#include <netdb.h>
+#ifndef HAVE_MD5
+# include "../dst/md5.h"
+#else
+# ifdef SOLARIS2
+# include <sys/md5.h>
+# endif
+#endif
+#ifndef _MD5_H_
+# define _MD5_H_ 1 /*%< make sure we do not include rsaref md5.h file */
+#endif
+
+
#include "port_after.h"
/* ensure that sockaddr_in6 and IN6ADDR_ANY_INIT are declared / defined */
#include <resolv.h>
+/* ISC purposely put port_after.h before <resolv.h> to force in6 stuff
+ * (above) so we explicitly include port_resolv.h here */
+#include "port_resolv.h"
+
#include "res_private.h"
-/* Options. Should all be left alone. */
+/*% Options. Should all be left alone. */
#define RESOLVSORT
#define DEBUG
@@ -116,15 +131,9 @@ static const char rcsid[] = "$Id: res_init.c,v 8.32 2003/04/03 06:31:10 marka Ex
#define MAXIFS 8192
#endif /* SUNW_INITCHKIF */
-#ifdef SUNW_DOMAINFROMNIS
+#ifdef SOLARIS2
#include <sys/systeminfo.h>
-#include <string.h>
-#endif /* SUNW_DOMAINFROMNIS */
-
-#ifdef ORIGINAL_ISC_CODE
-#else
-#pragma weak __res_randomid = res_randomid
-#endif /* ORIGINAL_ISC_CODE */
+#endif
static void res_setoptions __P((res_state, const char *, const char *));
@@ -134,7 +143,7 @@ static const char sort_mask[] = "/&";
static u_int32_t net_mask __P((struct in_addr));
#endif
-#if !defined(isascii) /* XXX - could be a function */
+#if !defined(isascii) /*%< XXX - could be a function */
# define isascii(c) (!(c & 0200))
#endif
@@ -142,7 +151,7 @@ static u_int32_t net_mask __P((struct in_addr));
* Resolver state default settings.
*/
-/*
+/*%
* 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().
@@ -166,18 +175,17 @@ static u_int32_t net_mask __P((struct in_addr));
int
res_ninit(res_state statp) {
extern int __res_vinit(res_state, int);
-
return (__res_vinit(statp, 0));
}
-/* This function has to be reachable by res_data.c but not publically. */
+/*% This function has to be reachable by res_data.c but not publically. */
int
__res_vinit(res_state statp, int preinit) {
register FILE *fp;
register char *cp, **pp;
register int n;
char buf[BUFSIZ];
- int nserv = 0; /* number of nameserver records read from file */
+ int nserv = 0; /*%< number of nameserver records read from file */
int haveenv = 0;
int havesearch = 0;
#ifdef RESOLVSORT
@@ -186,7 +194,9 @@ __res_vinit(res_state statp, int preinit) {
#endif
int dots;
union res_sockaddr_union u[2];
+ int maxns = MAXNS;
+ RES_SET_H_ERRNO(statp, 0);
if (statp->_u._ext.ext != NULL)
res_ndestroy(statp);
@@ -194,7 +204,8 @@ __res_vinit(res_state statp, int preinit) {
statp->retrans = RES_TIMEOUT;
statp->retry = RES_DFLRETRY;
statp->options = RES_DEFAULT;
- statp->id = res_randomid();
+ res_rndinit(statp);
+ statp->id = res_nrandomid(statp);
}
memset(u, 0, sizeof(u));
@@ -236,8 +247,22 @@ __res_vinit(res_state statp, int preinit) {
statp->_u._ext.ext->nsaddrs[0].sin = statp->nsaddr;
strcpy(statp->_u._ext.ext->nsuffix, "ip6.arpa");
strcpy(statp->_u._ext.ext->nsuffix2, "ip6.int");
- } else
- return (-1);
+ } else {
+ /*
+ * Historically res_init() rarely, if at all, failed.
+ * Examples and applications exist which do not check
+ * our return code. Furthermore several applications
+ * simply call us to get the systems domainname. So
+ * rather then immediately fail here we store the
+ * failure, which is returned later, in h_errno. And
+ * prevent the collection of 'nameserver' information
+ * by setting maxns to 0. Thus applications that fail
+ * to check our return code wont be able to make
+ * queries anyhow.
+ */
+ RES_SET_H_ERRNO(statp, NETDB_INTERNAL);
+ maxns = 0;
+ }
#ifdef RESOLVSORT
statp->nsort = 0;
#endif
@@ -328,25 +353,27 @@ __res_vinit(res_state statp, int preinit) {
}
#endif /* SUNW_INITCHKIF */
-#ifdef SUNW_DOMAINFROMNIS
-/*
- * The old (4.8.3) libresolv derived the default domainname from NIS/NIS+.
- */
- {
- char buf[sizeof(statp->defdname)], *cp;
- int ret;
- if ((ret = sysinfo(SI_SRPC_DOMAIN, buf, sizeof(buf))) > 0 &&
- ret <= sizeof(buf)) {
- if (buf[0] == '+')
- buf[0] = '.';
- cp = strchr(buf, '.');
- if (cp == 0)
- strcpy(statp->defdname, buf);
- else
- strcpy(statp->defdname, cp+1);
- }
- }
-#endif /* SUNW_DOMAINFROMNIS */
+#ifdef SOLARIS2
+ /*
+ * The old libresolv derived the defaultdomain from NIS/NIS+.
+ * We want to keep this behaviour
+ */
+ {
+ char buf[sizeof(statp->defdname)], *cp;
+ int ret;
+
+ if ((ret = sysinfo(SI_SRPC_DOMAIN, buf, sizeof(buf))) > 0 &&
+ (unsigned int)ret <= sizeof(buf)) {
+ if (buf[0] == '+')
+ buf[0] = '.';
+ cp = strchr(buf, '.');
+ cp = (cp == NULL) ? buf : (cp + 1);
+ strncpy(statp->defdname, cp,
+ sizeof(statp->defdname) - 1);
+ statp->defdname[sizeof(statp->defdname) - 1] = '\0';
+ }
+ }
+#endif /* SOLARIS2 */
/* Allow user to override the local domain definition */
if ((cp = getenv("LOCALDOMAIN")) != NULL) {
@@ -365,7 +392,7 @@ __res_vinit(res_state statp, int preinit) {
pp = statp->dnsrch;
*pp++ = cp;
for (n = 0; *cp && pp < statp->dnsrch + MAXDNSRCH; cp++) {
- if (*cp == '\n') /* silly backwards compat */
+ if (*cp == '\n') /*%< silly backwards compat */
break;
else if (*cp == ' ' || *cp == '\t') {
*cp = 0;
@@ -389,12 +416,7 @@ __res_vinit(res_state statp, int preinit) {
line[sizeof(name) - 1] == '\t'))
nserv = 0;
-
-#ifdef SUNW_AVOIDSTDIO_FDLIMIT
- if ((fp = fopen(_PATH_RESCONF, "rF")) != NULL) {
-#else
if ((fp = fopen(_PATH_RESCONF, "r")) != NULL) {
-#endif
/* read the config file */
while (fgets(buf, sizeof(buf), fp) != NULL) {
/* skip comments */
@@ -402,7 +424,7 @@ __res_vinit(res_state statp, int preinit) {
continue;
/* read default domain name */
if (MATCH(buf, "domain")) {
- if (haveenv) /* skip if have from environ */
+ if (haveenv) /*%< skip if have from environ */
continue;
cp = buf + sizeof("domain") - 1;
while (*cp == ' ' || *cp == '\t')
@@ -418,7 +440,7 @@ __res_vinit(res_state statp, int preinit) {
}
/* set search list */
if (MATCH(buf, "search")) {
- if (haveenv) /* skip if have from environ */
+ if (haveenv) /*%< skip if have from environ */
continue;
cp = buf + sizeof("search") - 1;
while (*cp == ' ' || *cp == '\t')
@@ -454,7 +476,7 @@ __res_vinit(res_state statp, int preinit) {
continue;
}
/* read nameservers to query */
- if (MATCH(buf, "nameserver") && nserv < MAXNS) {
+ if (MATCH(buf, "nameserver") && nserv < maxns) {
struct addrinfo hints, *ai;
char sbuf[NI_MAXSERV];
const size_t minsiz =
@@ -542,7 +564,7 @@ __res_vinit(res_state statp, int preinit) {
#ifdef RESOLVSORT
statp->nsort = nsort;
#endif
- (void) fclose(fp);
+ (void) fclose(fp);
}
/*
* Last chance to get a nameserver. This should not normally
@@ -572,7 +594,7 @@ __res_vinit(res_state statp, int preinit) {
while (pp < statp->dnsrch + MAXDFLSRCH) {
if (dots < LOCALDOMAINPARTS)
break;
- cp = strchr(cp, '.') + 1; /* we know there is one */
+ cp = strchr(cp, '.') + 1; /*%< we know there is one */
*pp++ = cp;
dots--;
}
@@ -590,7 +612,7 @@ __res_vinit(res_state statp, int preinit) {
if ((cp = getenv("RES_OPTIONS")) != NULL)
res_setoptions(statp, cp, "env");
statp->options |= RES_INIT;
- return (0);
+ return (statp->res_h_errno);
#ifdef SUNW_INITCHKIF
freedata:
if (statp->_u._ext.ext != NULL) {
@@ -599,6 +621,7 @@ freedata:
}
return (-1);
#endif /* SUNW_INITCHKIF */
+
}
static void
@@ -634,20 +657,17 @@ res_setoptions(res_state statp, const char *options, const char *source)
statp->retrans = i;
else
statp->retrans = RES_MAXRETRANS;
- } else if (!strncmp(cp, "attempts:", sizeof("attempts:") - 1)){
- i = atoi(cp + sizeof("attempts:") - 1);
- if (i <= RES_MAXRETRY)
- statp->retry = i;
- else
- statp->retry = RES_MAXRETRY;
-#ifdef ORIGINAL_ISC_CODE
-#else
+#ifdef DEBUG
+ if (statp->options & RES_DEBUG)
+ printf(";;\ttimeout=%d\n", statp->retrans);
+#endif
+#ifdef SOLARIS2
} else if (!strncmp(cp, "retrans:", sizeof("retrans:") - 1)) {
/*
- * For backward compatibility, 'retrans' is
- * supported as an alias for 'timeout', though
- * without an imposed maximum.
- */
+ * For backward compatibility, 'retrans' is
+ * supported as an alias for 'timeout', though
+ * without an imposed maximum.
+ */
statp->retrans = atoi(cp + sizeof("retrans:") - 1);
} else if (!strncmp(cp, "retry:", sizeof("retry:") - 1)){
/*
@@ -656,7 +676,17 @@ res_setoptions(res_state statp, const char *options, const char *source)
* without an imposed maximum.
*/
statp->retry = atoi(cp + sizeof("retry:") - 1);
-#endif /* ORIGINAL_ISC_CODE */
+#endif /* SOLARIS2 */
+ } else if (!strncmp(cp, "attempts:", sizeof("attempts:") - 1)){
+ i = atoi(cp + sizeof("attempts:") - 1);
+ if (i <= RES_MAXRETRY)
+ statp->retry = i;
+ else
+ statp->retry = RES_MAXRETRY;
+#ifdef DEBUG
+ if (statp->options & RES_DEBUG)
+ printf(";;\tattempts=%d\n", statp->retry);
+#endif
} else if (!strncmp(cp, "debug", sizeof("debug") - 1)) {
#ifdef DEBUG
if (!(statp->options & RES_DEBUG)) {
@@ -726,7 +756,7 @@ res_setoptions(res_state statp, const char *options, const char *source)
#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 */
+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);
@@ -739,15 +769,49 @@ net_mask(in) /* XXX - should really use system's version of this */
}
#endif
+void
+res_rndinit(res_state statp)
+{
+ struct timeval now;
+ u_int32_t u32;
+ u_int16_t u16;
+
+ gettimeofday(&now, NULL);
+ u32 = now.tv_sec;
+ memcpy(statp->_u._ext._rnd, &u32, 4);
+ u32 = now.tv_usec;
+ memcpy(statp->_u._ext._rnd + 4, &u32, 4);
+ u32 += now.tv_sec;
+ memcpy(statp->_u._ext._rnd + 8, &u32, 4);
+ u16 = getpid();
+ memcpy(statp->_u._ext._rnd + 12, &u16, 2);
+
+}
+
u_int
-res_randomid(void) {
+res_nrandomid(res_state statp) {
struct timeval now;
+ u_int16_t u16;
+ MD5_CTX ctx;
gettimeofday(&now, NULL);
- return (0xffff & (now.tv_sec ^ now.tv_usec ^ getpid()));
+ u16 = (u_int16_t) (now.tv_sec ^ now.tv_usec);
+
+ memcpy(statp->_u._ext._rnd + 14, &u16, 2);
+#ifndef HAVE_MD5
+ MD5_Init(&ctx);
+ MD5_Update(&ctx, statp->_u._ext._rnd, 16);
+ MD5_Final(statp->_u._ext._rnd, &ctx);
+#else
+ MD5Init(&ctx);
+ MD5Update(&ctx, statp->_u._ext._rnd, 16);
+ MD5Final(statp->_u._ext._rnd, &ctx);
+#endif
+ memcpy(&u16, statp->_u._ext._rnd + 14, 2);
+ return ((u_int) u16);
}
-/*
+/*%
* 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.
@@ -890,3 +954,5 @@ res_getservers(res_state statp, union res_sockaddr_union *set, int cnt) {
}
return (statp->nscount);
}
+
+/*! \file */
diff --git a/usr/src/lib/libresolv2/common/resolv/res_mkquery.c b/usr/src/lib/libresolv2/common/resolv/res_mkquery.c
index c81e9eba32..acc538a055 100644
--- a/usr/src/lib/libresolv2/common/resolv/res_mkquery.c
+++ b/usr/src/lib/libresolv2/common/resolv/res_mkquery.c
@@ -1,12 +1,30 @@
/*
- * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
+
+/*
+ * Portions Copyright (C) 2004, 2005, 2008 Internet Systems Consortium, Inc. ("ISC")
+ * Portions Copyright (C) 1996, 1997, 1988, 1999, 2001, 2003 Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and/or 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 ISC DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS. IN NO EVENT SHALL ISC 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 (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:
@@ -22,7 +40,7 @@
* 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
@@ -38,14 +56,14 @@
/*
* 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
@@ -56,28 +74,9 @@
* SOFTWARE.
*/
-/*
- * Portions Copyright (c) 1996-1999 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.
- */
-
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#if defined(LIBC_SCCS) && !defined(lint)
static const char sccsid[] = "@(#)res_mkquery.c 8.1 (Berkeley) 6/4/93";
-static const char rcsid[] = "$Id: res_mkquery.c,v 8.16 2003/04/29 02:13:08 marka Exp $";
+static const char rcsid[] = "$Id: res_mkquery.c,v 1.10 2008/12/11 09:59:00 marka Exp $";
#endif /* LIBC_SCCS and not lint */
#include "port_before.h"
@@ -90,7 +89,8 @@ static const char rcsid[] = "$Id: res_mkquery.c,v 8.16 2003/04/29 02:13:08 marka
#include <sys/socket.h>
#include <errno.h>
#include <sys/stat.h>
-#endif
+#endif /* SUNW_CONFCHECK */
+
#include <netdb.h>
#include <resolv.h>
@@ -105,22 +105,23 @@ extern const char *_res_opcodes[];
#ifdef SUNW_CONFCHECK
static int _confcheck(res_state statp);
-#endif
+#endif /* SUNW_CONFCHECK */
-/*
+
+/*%
* Form all types of queries.
* Returns the size of the result or -1.
*/
int
res_nmkquery(res_state statp,
- int op, /* opcode of query */
- const char *dname, /* domain name */
- int class, int 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 */
+ int op, /*!< opcode of query */
+ const char *dname, /*!< domain name */
+ int class, int 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, *ep;
@@ -144,8 +145,8 @@ res_nmkquery(res_state statp,
RES_SET_H_ERRNO(statp, NO_RECOVERY);
return(-1);
}
-#endif
-
+#endif /* SUNW_CONFCHECK */
+
/*
* Initialize header fields.
*/
@@ -153,9 +154,10 @@ res_nmkquery(res_state statp,
return (-1);
memset(buf, 0, HFIXEDSZ);
hp = (HEADER *) buf;
- hp->id = htons(++statp->id);
+ statp->id = res_nrandomid(statp);
+ hp->id = htons(statp->id);
hp->opcode = op;
- hp->rd = (statp->options & RES_RECURSE) != 0;
+ hp->rd = (statp->options & RES_RECURSE) != 0U;
hp->rcode = NOERROR;
cp = buf + HFIXEDSZ;
ep = buf + buflen;
@@ -209,7 +211,7 @@ res_nmkquery(res_state statp,
*/
if (ep - cp < 1 + RRFIXEDSZ + datalen)
return (-1);
- *cp++ = '\0'; /* no domain name */
+ *cp++ = '\0'; /*%< no domain name */
ns_put16(type, cp);
cp += INT16SZ;
ns_put16(class, cp);
@@ -233,27 +235,20 @@ res_nmkquery(res_state statp,
#ifdef RES_USE_EDNS0
/* attach OPT pseudo-RR, as documented in RFC2671 (EDNS0). */
-#ifndef T_OPT
-#define T_OPT 41
-#endif
int
res_nopt(res_state statp,
- int n0, /* current offset in buffer */
-#ifdef ORIGINAL_ISC_CODE
- u_char *buf, /* buffer to put query */
-#else
- uchar_t *buf, /* buffer to put query */
-#endif
- int buflen, /* size of buffer */
- int anslen) /* UDP answer buffer size */
+ int n0, /*%< current offset in buffer */
+ u_char *buf, /*%< buffer to put query */
+ int buflen, /*%< size of buffer */
+ int anslen) /*%< UDP answer buffer size */
{
register HEADER *hp;
register u_char *cp, *ep;
u_int16_t flags = 0;
#ifdef DEBUG
- if ((statp->options & RES_DEBUG) != 0)
+ if ((statp->options & RES_DEBUG) != 0U)
printf(";; res_nopt()\n");
#endif
@@ -264,14 +259,14 @@ res_nopt(res_state statp,
if ((ep - cp) < 1 + RRFIXEDSZ)
return (-1);
- *cp++ = 0; /* "." */
-
- ns_put16(T_OPT, cp); /* TYPE */
+ *cp++ = 0; /*%< "." */
+ ns_put16(ns_t_opt, cp); /*%< TYPE */
cp += INT16SZ;
- ns_put16(anslen & 0xffff, cp); /* CLASS = UDP payload size */
+ ns_put16(anslen & 0xffff, cp); /*%< CLASS = UDP payload size */
cp += INT16SZ;
- *cp++ = NOERROR; /* extended RCODE */
- *cp++ = 0; /* EDNS version */
+ *cp++ = NOERROR; /*%< extended RCODE */
+ *cp++ = 0; /*%< EDNS version */
+
if (statp->options & RES_USE_DNSSEC) {
#ifdef DEBUG
if (statp->options & RES_DEBUG)
@@ -281,44 +276,74 @@ res_nopt(res_state statp,
}
ns_put16(flags, cp);
cp += INT16SZ;
- ns_put16(0, cp); /* RDLEN */
+
+ ns_put16(0U, cp); /*%< RDLEN */
cp += INT16SZ;
+
hp->arcount = htons(ntohs(hp->arcount) + 1);
return (cp - buf);
}
-#endif
-#ifdef SUNW_CONFCHECK
/*
- * Kludge to time out quickly if there is no /etc/resolv.conf
- * and a TCP connection to the local DNS server fails.
- *
- * Moved function from res_send.c to res_mkquery.c. This
- * solves a long timeout problem with nslookup.
- *
- * __areweinnamed is needed because there is a possibility that the
- * user might do bad things to resolv.conf and cause in.named to call
- * _confcheck and deadlock the server.
+ * Construct variable data (RDATA) block for OPT psuedo-RR, append it
+ * to the buffer, then update the RDLEN field (previously set to zero by
+ * res_nopt()) with the new RDATA length.
*/
-
-#ifdef SUNW_AREWEINNAMED
-int __areweinnamed()
+int
+res_nopt_rdata(res_state statp,
+ int n0, /*%< current offset in buffer */
+ u_char *buf, /*%< buffer to put query */
+ int buflen, /*%< size of buffer */
+ u_char *rdata, /*%< ptr to start of opt rdata */
+ u_short code, /*%< OPTION-CODE */
+ u_short len, /*%< OPTION-LENGTH */
+ u_char *data) /*%< OPTION_DATA */
{
- return (0);
+ register u_char *cp, *ep;
+
+#ifdef DEBUG
+ if ((statp->options & RES_DEBUG) != 0U)
+ printf(";; res_nopt_rdata()\n");
+#endif
+
+ cp = buf + n0;
+ ep = buf + buflen;
+
+ if ((ep - cp) < (4 + len))
+ return (-1);
+
+ if (rdata < (buf + 2) || rdata >= ep)
+ return (-1);
+
+ ns_put16(code, cp);
+ cp += INT16SZ;
+
+ ns_put16(len, cp);
+ cp += INT16SZ;
+
+ memcpy(cp, data, len);
+ cp += len;
+
+ len = cp - rdata;
+ ns_put16(len, rdata - 2); /* Update RDLEN field */
+
+ return (cp - buf);
}
-#endif /* SUNW_AREWEINNAMED */
+#endif
+#ifdef SUNW_CONFCHECK
+
+/*
+ * Time out quickly if there is no /etc/resolv.conf and a TCP connection
+ * to the local DNS server fails.
+ */
static int _confcheck(res_state statp)
{
int ns;
struct stat rc_stat;
struct sockaddr_in ns_sin;
-
- if (__areweinnamed())
- return (0);
-
/* First, we check to see if /etc/resolv.conf exists.
* If it doesn't, then it is likely that the localhost is
* the nameserver.
@@ -356,4 +381,6 @@ static int _confcheck(res_state statp)
return (0);
}
-#endif
+#endif /* SUNW_CONFCHECK */
+
+/*! \file */
diff --git a/usr/src/lib/libresolv2/common/resolv/res_mkupdate.c b/usr/src/lib/libresolv2/common/resolv/res_mkupdate.c
index d66f0b91ed..2eb6757a0e 100644
--- a/usr/src/lib/libresolv2/common/resolv/res_mkupdate.c
+++ b/usr/src/lib/libresolv2/common/resolv/res_mkupdate.c
@@ -1,34 +1,28 @@
/*
- * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
-/*
+ * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1996-1999 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.
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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.
*/
-#pragma ident "%Z%%M% %I% %E% SMI"
-
-/*
+/*! \file
+ * \brief
* Based on the Dynamic DNS reference implementation by Viraj Bais
- * <viraj_bais@ccm.fm.intel.com>
+ * &lt;viraj_bais@ccm.fm.intel.com>
*/
#if !defined(lint) && !defined(SABER)
-static const char rcsid[] = "$Id: res_mkupdate.c,v 1.30 2003/08/14 07:54:50 marka Exp $";
+static const char rcsid[] = "$Id: res_mkupdate.c,v 1.10 2008/12/11 09:59:00 marka Exp $";
#endif /* not lint */
#include "port_before.h"
@@ -69,23 +63,25 @@ static int getstr_str(char *, int, u_char **, u_char *);
int res_protocolnumber(const char *);
int res_servicenumber(const char *);
-/*
+/*%
* Form update packets.
* Returns the size of the resulting packet if no error
+ *
* On error,
- * returns -1 if error in reading a word/number in rdata
+ * returns
+ *\li -1 if error in reading a word/number in rdata
* portion for update packets
- * -2 if length of buffer passed is insufficient
- * -3 if zone section is not the first section in
+ *\li -2 if length of buffer passed is insufficient
+ *\li -3 if zone section is not the first section in
* the linked list, or section order has a problem
- * -4 on a number overflow
- * -5 unknown operation or no records
+ *\li -4 on a number overflow
+ *\li -5 unknown operation or no records
*/
int
res_nmkupdate(res_state statp, ns_updrec *rrecp_in, u_char *buf, int buflen) {
ns_updrec *rrecp_start = rrecp_in;
HEADER *hp;
- u_char *cp, *sp1, *sp2, *startp, *endp;
+ u_char *cp, *sp2, *startp, *endp;
int n, i, soanum, multiline;
ns_updrec *rrecp;
struct in_addr ina;
@@ -105,10 +101,10 @@ res_nmkupdate(res_state statp, ns_updrec *rrecp_in, u_char *buf, int buflen) {
return (-1);
memset(buf, 0, HFIXEDSZ);
hp = (HEADER *) buf;
- hp->id = htons(++statp->id);
+ statp->id = res_nrandomid(statp);
+ hp->id = htons(statp->id);
hp->opcode = ns_o_update;
hp->rcode = NOERROR;
- sp1 = buf + 2*INT16SZ; /* save pointer to zocount */
cp = buf + HFIXEDSZ;
buflen -= HFIXEDSZ;
dpp = dnptrs;
@@ -197,7 +193,7 @@ res_nmkupdate(res_state statp, ns_updrec *rrecp_in, u_char *buf, int buflen) {
}
ShrinkBuffer(INT32SZ + INT16SZ);
PUTLONG(rttl, cp);
- sp2 = cp; /* save pointer to length byte */
+ sp2 = cp; /*%< save pointer to length byte */
cp += INT16SZ;
if (rrecp->r_size == 0) {
if (section == S_UPDATE && rclass != C_ANY)
@@ -226,6 +222,7 @@ res_nmkupdate(res_state statp, ns_updrec *rrecp_in, u_char *buf, int buflen) {
case T_MR:
case T_NS:
case T_PTR:
+ case ns_t_dname:
if (!getword_str(buf2, sizeof buf2, &startp, endp))
return (-1);
n = dn_comp(buf2, cp, buflen, dnptrs, lastdnptr);
@@ -356,13 +353,13 @@ res_nmkupdate(res_state statp, ns_updrec *rrecp_in, u_char *buf, int buflen) {
bm[i] = 0;
while (getword_str(buf2, sizeof buf2, &startp, endp)) {
- if ((n1 = res_servicenumber(buf2)) <= 0)
+ if ((n = res_servicenumber(buf2)) <= 0)
return (-1);
- if (n1 < MAXPORT) {
- bm[n1/8] |= (0x80>>(n1%8));
- if (n1 > maxbm)
- maxbm = n1;
+ if (n < MAXPORT) {
+ bm[n/8] |= (0x80>>(n%8));
+ if ((unsigned)n > maxbm)
+ maxbm = n;
} else
return (-1);
}
@@ -386,7 +383,7 @@ res_nmkupdate(res_state statp, ns_updrec *rrecp_in, u_char *buf, int buflen) {
}
break;
case T_TXT:
- while (1) {
+ for (;;) {
if ((n = getstr_str(buf2, sizeof buf2,
&startp, endp)) < 0) {
if (cp != (sp2 + INT16SZ))
@@ -402,7 +399,7 @@ res_nmkupdate(res_state statp, ns_updrec *rrecp_in, u_char *buf, int buflen) {
}
break;
case T_X25:
- /* RFC 1183 */
+ /* RFC1183 */
if ((n = getstr_str(buf2, sizeof buf2, &startp,
endp)) < 0)
return (-1);
@@ -414,7 +411,7 @@ res_nmkupdate(res_state statp, ns_updrec *rrecp_in, u_char *buf, int buflen) {
cp += n;
break;
case T_ISDN:
- /* RFC 1183 */
+ /* RFC1183 */
if ((n = getstr_str(buf2, sizeof buf2, &startp,
endp)) < 0)
return (-1);
@@ -588,7 +585,7 @@ res_nmkupdate(res_state statp, ns_updrec *rrecp_in, u_char *buf, int buflen) {
ShrinkBuffer(n);
maxtype = 0;
memset(data, 0, sizeof data);
- while (1) {
+ for (;;) {
if (!getword_str(buf2, sizeof buf2, &startp,
endp))
break;
@@ -715,7 +712,7 @@ res_nmkupdate(res_state statp, ns_updrec *rrecp_in, u_char *buf, int buflen) {
return (cp - buf);
}
-/*
+/*%
* Get a whitespace delimited word from a string (not file)
* into buf. modify the start pointer to point after the
* word in the string.
@@ -728,9 +725,9 @@ getword_str(char *buf, int size, u_char **startpp, u_char *endp) {
for (cp = buf; *startpp <= endp; ) {
c = **startpp;
if (isspace(c) || c == '\0') {
- if (cp != buf) /* trailing whitespace */
+ if (cp != buf) /*%< trailing whitespace */
break;
- else { /* leading whitespace */
+ else { /*%< leading whitespace */
(*startpp)++;
continue;
}
@@ -744,9 +741,9 @@ getword_str(char *buf, int size, u_char **startpp, u_char *endp) {
return (cp != buf);
}
-/*
+/*%
* get a white spae delimited string from memory. Process quoted strings
- * and \DDD escapes. Return length or -1 on error. Returned string may
+ * and \\DDD escapes. Return length or -1 on error. Returned string may
* contain nulls.
*/
static char digits[] = "0123456789";
@@ -823,7 +820,8 @@ getstr_str(char *buf, int size, u_char **startpp, u_char *endp) {
*cp = '\0';
return ((cp == buf)? (seen_quote? 0: -1): (cp - buf));
}
-/*
+
+/*%
* Get a whitespace delimited base 16 number from a string (not file) into buf
* update the start pointer to point after the number in the string.
*/
@@ -839,9 +837,9 @@ gethexnum_str(u_char **startpp, u_char *endp) {
for (n = 0; *startpp <= endp; ) {
c = **startpp;
if (isspace(c) || c == '\0') {
- if (seendigit) /* trailing whitespace */
+ if (seendigit) /*%< trailing whitespace */
break;
- else { /* leading whitespace */
+ else { /*%< leading whitespace */
(*startpp)++;
continue;
}
@@ -871,7 +869,7 @@ gethexnum_str(u_char **startpp, u_char *endp) {
return (n + m);
}
-/*
+/*%
* Get a whitespace delimited base 10 number from a string (not file) into buf
* update the start pointer to point after the number in the string.
*/
@@ -884,9 +882,9 @@ getnum_str(u_char **startpp, u_char *endp) {
for (n = 0; *startpp <= endp; ) {
c = **startpp;
if (isspace(c) || c == '\0') {
- if (seendigit) /* trailing whitespace */
+ if (seendigit) /*%< trailing whitespace */
break;
- else { /* leading whitespace */
+ else { /*%< leading whitespace */
(*startpp)++;
continue;
}
@@ -913,7 +911,7 @@ getnum_str(u_char **startpp, u_char *endp) {
return (n + m);
}
-/*
+/*%
* Allocate a resource record buffer & save rr info.
*/
ns_updrec *
@@ -928,14 +926,14 @@ res_mkupdrec(int section, const char *dname,
}
INIT_LINK(rrecp, r_link);
INIT_LINK(rrecp, r_glink);
- rrecp->r_class = class;
- rrecp->r_type = type;
+ rrecp->r_class = (ns_class)class;
+ rrecp->r_type = (ns_type)type;
rrecp->r_ttl = ttl;
- rrecp->r_section = section;
+ rrecp->r_section = (ns_sect)section;
return (rrecp);
}
-/*
+/*%
* Free a resource record buffer created by res_mkupdrec.
*/
void
@@ -977,7 +975,7 @@ res_buildservicelist() {
free(slp);
break;
}
- slp->port = ntohs((u_int16_t)sp->s_port); /* host byt order */
+ slp->port = ntohs((u_int16_t)sp->s_port); /*%< host byt order */
slp->next = servicelist;
slp->prev = NULL;
if (servicelist)
@@ -1019,7 +1017,7 @@ res_buildprotolist(void) {
free(slp);
break;
}
- slp->port = pp->p_proto; /* host byte order */
+ slp->port = pp->p_proto; /*%< host byte order */
slp->next = protolist;
slp->prev = NULL;
if (protolist)
@@ -1056,14 +1054,14 @@ findservice(const char *s, struct valuelist **list) {
lp->next = *list;
*list = lp;
}
- return (lp->port); /* host byte order */
+ return (lp->port); /*%< host byte order */
}
if (sscanf(s, "%d", &n) != 1 || n <= 0)
n = -1;
return (n);
}
-/*
+/*%
* Convert service name or (ascii) number to int.
*/
int
@@ -1073,7 +1071,7 @@ res_servicenumber(const char *p) {
return (findservice(p, &servicelist));
}
-/*
+/*%
* Convert protocol name or (ascii) number to int.
*/
int
@@ -1084,14 +1082,14 @@ res_protocolnumber(const char *p) {
}
static struct servent *
-cgetservbyport(u_int16_t port, const char *proto) { /* Host byte order. */
+cgetservbyport(u_int16_t port, const char *proto) { /*%< Host byte order. */
struct valuelist **list = &servicelist;
struct valuelist *lp = *list;
static struct servent serv;
port = ntohs(port);
for (; lp != NULL; lp = lp->next) {
- if (port != (u_int16_t)lp->port) /* Host byte order. */
+ if (port != (u_int16_t)lp->port) /*%< Host byte order. */
continue;
if (strcasecmp(lp->proto, proto) == 0) {
if (lp != *list) {
@@ -1112,13 +1110,13 @@ cgetservbyport(u_int16_t port, const char *proto) { /* Host byte order. */
}
static struct protoent *
-cgetprotobynumber(int proto) { /* Host byte order. */
+cgetprotobynumber(int proto) { /*%< Host byte order. */
struct valuelist **list = &protolist;
struct valuelist *lp = *list;
static struct protoent prot;
for (; lp != NULL; lp = lp->next)
- if (lp->port == proto) { /* Host byte order. */
+ if (lp->port == proto) { /*%< Host byte order. */
if (lp != *list) {
lp->prev->next = lp->next;
if (lp->next)
@@ -1128,7 +1126,7 @@ cgetprotobynumber(int proto) { /* Host byte order. */
*list = lp;
}
prot.p_name = lp->name;
- prot.p_proto = lp->port; /* Host byte order. */
+ prot.p_proto = lp->port; /*%< Host byte order. */
return (&prot);
}
return (0);
@@ -1150,7 +1148,7 @@ res_protocolname(int num) {
}
const char *
-res_servicename(u_int16_t port, const char *proto) { /* Host byte order. */
+res_servicename(u_int16_t port, const char *proto) { /*%< Host byte order. */
static char number[8];
struct servent *ss;
diff --git a/usr/src/lib/libresolv2/common/resolv/res_mkupdate.h b/usr/src/lib/libresolv2/common/resolv/res_mkupdate.h
index 97a7518ee8..96c452d89e 100644
--- a/usr/src/lib/libresolv2/common/resolv/res_mkupdate.h
+++ b/usr/src/lib/libresolv2/common/resolv/res_mkupdate.h
@@ -1,31 +1,25 @@
/*
- * Copyright (c) 1999 by Sun Microsystems, Inc.
- * All rights reserved.
- */
-
-/*
+ * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1998,1999 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.
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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 _RES_MKUPDATE_H_
#define _RES_MKUPDATE_H_
-#pragma ident "%Z%%M% %I% %E% SMI"
-
__BEGIN_DECLS
__END_DECLS
#endif /* _RES_MKUPDATE_H_ */
+/*! \file */
diff --git a/usr/src/lib/libresolv2/common/resolv/res_private.h b/usr/src/lib/libresolv2/common/resolv/res_private.h
index 0ee5617541..4e98157ced 100644
--- a/usr/src/lib/libresolv2/common/resolv/res_private.h
+++ b/usr/src/lib/libresolv2/common/resolv/res_private.h
@@ -1,10 +1,3 @@
-/*
- * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#ifndef res_private_h
#define res_private_h
@@ -25,3 +18,5 @@ extern int
res_ourserver_p(const res_state statp, const struct sockaddr *sa);
#endif
+
+/*! \file */
diff --git a/usr/src/lib/libresolv2/common/resolv/res_query.c b/usr/src/lib/libresolv2/common/resolv/res_query.c
index b592f4e72f..ab18548c92 100644
--- a/usr/src/lib/libresolv2/common/resolv/res_query.c
+++ b/usr/src/lib/libresolv2/common/resolv/res_query.c
@@ -1,12 +1,24 @@
/*
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
+ * Portions Copyright (C) 2004, 2005, 2008 Internet Systems Consortium, Inc. ("ISC")
+ * Portions Copyright (C) 1996-2001, 2003 Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and/or 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 ISC DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS. IN NO EVENT SHALL ISC 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 (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:
@@ -22,7 +34,7 @@
* 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
@@ -38,14 +50,14 @@
/*
* 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
@@ -56,28 +68,9 @@
* SOFTWARE.
*/
-/*
- * Portions Copyright (c) 1996-1999 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.
- */
-
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#if defined(LIBC_SCCS) && !defined(lint)
static const char sccsid[] = "@(#)res_query.c 8.1 (Berkeley) 6/4/93";
-static const char rcsid[] = "$Id: res_query.c,v 8.24 2003/01/31 15:25:58 vixie Exp $";
+static const char rcsid[] = "$Id: res_query.c,v 1.11 2008/11/14 02:36:51 marka Exp $";
#endif /* LIBC_SCCS and not lint */
#include "port_before.h"
@@ -104,7 +97,7 @@ static const char rcsid[] = "$Id: res_query.c,v 8.24 2003/01/31 15:25:58 vixie E
#define MAXPACKET 1024
#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
@@ -116,21 +109,21 @@ static const char rcsid[] = "$Id: res_query.c,v 8.24 2003/01/31 15:25:58 vixie E
*/
int
res_nquery(res_state statp,
- const char *name, /* domain name */
- int class, int type, /* class and type of query */
- u_char *answer, /* buffer to put answer */
- int anslen) /* size of answer buffer */
+ const char *name, /*%< domain name */
+ int class, int type, /*%< class and type of query */
+ u_char *answer, /*%< buffer to put answer */
+ int anslen) /*%< size of answer buffer */
{
u_char buf[MAXPACKET];
HEADER *hp = (HEADER *) answer;
- int n;
u_int oflags;
+ u_char *rdata;
+ int n;
oflags = statp->_flags;
again:
- hp->rcode = NOERROR; /* default */
-
+ hp->rcode = NOERROR; /*%< default */
#ifdef DEBUG
if (statp->options & RES_DEBUG)
printf(";; res_query(%s, %d, %d)\n", name, class, type);
@@ -140,8 +133,14 @@ again:
buf, sizeof(buf));
#ifdef RES_USE_EDNS0
if (n > 0 && (statp->_flags & RES_F_EDNS0ERR) == 0 &&
- (statp->options & (RES_USE_EDNS0|RES_USE_DNSSEC)) != 0)
+ (statp->options & (RES_USE_EDNS0|RES_USE_DNSSEC|RES_NSID))) {
n = res_nopt(statp, n, buf, sizeof(buf), anslen);
+ rdata = &buf[n];
+ if (n > 0 && (statp->options & RES_NSID) != 0U) {
+ n = res_nopt_rdata(statp, n, buf, sizeof(buf), rdata,
+ NS_OPT_NSID, 0, NULL);
+ }
+ }
#endif
if (n <= 0) {
#ifdef DEBUG
@@ -151,11 +150,12 @@ again:
RES_SET_H_ERRNO(statp, NO_RECOVERY);
return (n);
}
+
n = res_nsend(statp, buf, n, answer, anslen);
if (n < 0) {
#ifdef RES_USE_EDNS0
/* if the query choked with EDNS0, retry without EDNS0 */
- if ((statp->options & (RES_USE_EDNS0|RES_USE_DNSSEC)) != 0 &&
+ if ((statp->options & (RES_USE_EDNS0|RES_USE_DNSSEC)) != 0U &&
((oflags ^ statp->_flags) & RES_F_EDNS0ERR) != 0) {
statp->_flags |= RES_F_EDNS0ERR;
if (statp->options & RES_DEBUG)
@@ -202,7 +202,7 @@ again:
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
@@ -210,10 +210,10 @@ again:
*/
int
res_nsearch(res_state statp,
- const char *name, /* domain name */
- int class, int type, /* class and type of query */
- u_char *answer, /* buffer to put answer */
- int anslen) /* size of answer */
+ const char *name, /*%< domain name */
+ int class, int type, /*%< class and type of query */
+ u_char *answer, /*%< buffer to put answer */
+ int anslen) /*%< size of answer */
{
const char *cp, * const *domain;
HEADER *hp = (HEADER *) answer;
@@ -225,8 +225,7 @@ res_nsearch(res_state statp,
int searched = 0;
errno = 0;
- RES_SET_H_ERRNO(statp, HOST_NOT_FOUND); /* True if we never query. */
-
+ RES_SET_H_ERRNO(statp, HOST_NOT_FOUND); /*%< True if we never query. */
dots = 0;
for (cp = name; *cp != '\0'; cp++)
dots += (*cp == '.');
@@ -259,8 +258,8 @@ res_nsearch(res_state statp,
* - there is at least one dot, there is no trailing dot,
* and RES_DNSRCH is set.
*/
- if ((!dots && (statp->options & RES_DEFNAMES) != 0) ||
- (dots && !trailing_dot && (statp->options & RES_DNSRCH) != 0)) {
+ if ((!dots && (statp->options & RES_DEFNAMES) != 0U) ||
+ (dots && !trailing_dot && (statp->options & RES_DNSRCH) != 0U)) {
int done = 0;
for (domain = (const char * const *)statp->dnsrch;
@@ -318,7 +317,7 @@ res_nsearch(res_state statp,
/* if we got here for some reason other than DNSRCH,
* we only wanted one iteration of the loop, so stop.
*/
- if ((statp->options & RES_DNSRCH) == 0)
+ if ((statp->options & RES_DNSRCH) == 0U)
done++;
}
}
@@ -327,7 +326,7 @@ res_nsearch(res_state statp,
* If the query has not already been tried as is then try it
* unless RES_NOTLDQUERY is set and there were no dots.
*/
- if ((dots || !searched || (statp->options & RES_NOTLDQUERY) == 0) &&
+ if ((dots || !searched || (statp->options & RES_NOTLDQUERY) == 0U) &&
!(tried_as_is || root_on_list)) {
ret = res_nquerydomain(statp, name, NULL, class, type,
answer, anslen);
@@ -351,7 +350,7 @@ res_nsearch(res_state statp,
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.
*/
@@ -359,9 +358,9 @@ int
res_nquerydomain(res_state statp,
const char *name,
const char *domain,
- int class, int type, /* class and type of query */
- u_char *answer, /* buffer to put answer */
- int anslen) /* size of answer */
+ int class, int 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;
@@ -409,11 +408,7 @@ res_hostalias(const res_state statp, const char *name, char *dst, size_t siz) {
if (statp->options & RES_NOALIASES)
return (NULL);
file = getenv("HOSTALIASES");
-#ifdef SUNW_AVOIDSTDIO_FDLIMIT
- if (file == NULL || (fp = fopen(file, "rF")) == NULL)
-#else
- if (file == NULL || (fp = fopen(file, "r")) == NULL)
-#endif
+ if (file == NULL || (fp = fopen(file, "r")) == NULL)
return (NULL);
setbuf(fp, NULL);
buf[sizeof(buf) - 1] = '\0';
@@ -441,3 +436,5 @@ res_hostalias(const res_state statp, const char *name, char *dst, size_t siz) {
fclose(fp);
return (NULL);
}
+
+/*! \file */
diff --git a/usr/src/lib/libresolv2/common/resolv/res_send.c b/usr/src/lib/libresolv2/common/resolv/res_send.c
index 5891e01e62..8e629a3d96 100644
--- a/usr/src/lib/libresolv2/common/resolv/res_send.c
+++ b/usr/src/lib/libresolv2/common/resolv/res_send.c
@@ -1,12 +1,30 @@
/*
- * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
+
+/*
+ * Portions Copyright (C) 2004-2009 Internet Systems Consortium, Inc. ("ISC")
+ * Portions Copyright (C) 1996-2003 Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and/or 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 ISC DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS. IN NO EVENT SHALL ISC 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 (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:
@@ -22,7 +40,7 @@
* 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
@@ -38,14 +56,14 @@
/*
* 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
@@ -56,31 +74,13 @@
* SOFTWARE.
*/
-/*
- * Portions Copyright (c) 1996-1999 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.
- */
-
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#if defined(LIBC_SCCS) && !defined(lint)
static const char sccsid[] = "@(#)res_send.c 8.1 (Berkeley) 6/4/93";
-static const char rcsid[] = "$Id: res_send.c,v 8.52 2003/04/29 02:13:08 marka Exp $";
+static const char rcsid[] = "$Id: res_send.c,v 1.22 2009/01/22 23:49:23 tbox Exp $";
#endif /* LIBC_SCCS and not lint */
-/*
+/*! \file
+ * \brief
* Send query to name server and wait for reply.
*/
@@ -110,14 +110,12 @@ static const char rcsid[] = "$Id: res_send.c,v 8.52 2003/04/29 02:13:08 marka Ex
#include "port_after.h"
-#ifdef SUNW_POLL
+#ifdef USE_POLL
+#ifdef HAVE_STROPTS_H
#include <stropts.h>
-#include <poll.h>
-#if defined(pselect)
-#undef pselect
#endif
-#define pselect Pselect
-#endif /* SUNW_POLL */
+#include <poll.h>
+#endif /* USE_POLL */
/* Options. Leave them on. */
#define DEBUG
@@ -126,7 +124,7 @@ static const char rcsid[] = "$Id: res_send.c,v 8.52 2003/04/29 02:13:08 marka Ex
#define EXT(res) ((res)->_u._ext)
-#ifdef ORIGINAL_ISC_CODE
+#ifndef USE_POLL
static const int highestFD = FD_SETSIZE - 1;
#else
static int highestFD = 0;
@@ -139,21 +137,20 @@ static struct sockaddr * get_nsaddr __P((res_state, size_t));
static int send_vc(res_state, const u_char *, int,
u_char *, int, int *, int);
static int send_dg(res_state, const u_char *, int,
- u_char *, int, int *, int,
+ u_char *, int, int *, int, int,
int *, int *);
static void Aerror(const res_state, FILE *, const char *, int,
const struct sockaddr *, int);
static void Perror(const res_state, FILE *, const char *, int);
static int sock_eq(struct sockaddr *, struct sockaddr *);
-#ifdef NEED_PSELECT
+#if defined(NEED_PSELECT) && !defined(USE_POLL)
static int pselect(int, void *, void *, void *,
struct timespec *,
const sigset_t *);
#endif
void res_pquery(const res_state, const u_char *, int, FILE *);
-#ifdef ORIGINAL_ISC_CODE
-#else
+#ifndef ORIGINAL_ISC_CODE
#pragma weak __res_nameinquery = res_nameinquery
#pragma weak __res_queriesmatch = res_queriesmatch
#pragma weak res_nisourserver = res_ourserver_p
@@ -163,14 +160,15 @@ static const int niflags = NI_NUMERICHOST | NI_NUMERICSERV;
/* Public. */
-/* int
- * res_isourserver(ina)
+/*%
* looks up "ina" in _res.ns_addr_list[]
+ *
* returns:
- * 0 : not found
- * >0 : found
+ *\li 0 : not found
+ *\li >0 : found
+ *
* author:
- * paul vixie, 29may94
+ *\li paul vixie, 29may94
*/
int
res_ourserver_p(const res_state statp, const struct sockaddr *sa) {
@@ -199,8 +197,8 @@ res_ourserver_p(const res_state statp, const struct sockaddr *sa) {
if (srv6->sin6_family == in6p->sin6_family &&
srv6->sin6_port == in6p->sin6_port &&
#ifdef HAVE_SIN6_SCOPE_ID
- (srv6->sin6_scope_id == 0 ||
- srv6->sin6_scope_id == in6p->sin6_scope_id) &&
+ (srv6->sin6_scope_id == 0 ||
+ srv6->sin6_scope_id == in6p->sin6_scope_id) &&
#endif
(IN6_IS_ADDR_UNSPECIFIED(&srv6->sin6_addr) ||
IN6_ARE_ADDR_EQUAL(&srv6->sin6_addr, &in6p->sin6_addr)))
@@ -213,17 +211,19 @@ res_ourserver_p(const res_state statp, const struct sockaddr *sa) {
return (0);
}
-/* int
- * res_nameinquery(name, type, class, buf, eom)
+/*%
* look for (name,type,class) in the query section of packet (buf,eom)
+ *
* requires:
- * buf + HFIXEDSZ <= eom
+ *\li buf + HFIXEDSZ <= eom
+ *
* returns:
- * -1 : format error
- * 0 : not found
- * >0 : found
+ *\li -1 : format error
+ *\li 0 : not found
+ *\li >0 : found
+ *
* author:
- * paul vixie, 29may94
+ *\li paul vixie, 29may94
*/
int
res_nameinquery(const char *name, int type, int class,
@@ -251,16 +251,17 @@ res_nameinquery(const char *name, int type, int class,
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
+ *\li -1 : format error
+ *\li 0 : not a 1:1 mapping
+ *\li >0 : is a 1:1 mapping
+ *
* author:
- * paul vixie, 29may94
+ *\li paul vixie, 29may94
*/
int
res_queriesmatch(const u_char *buf1, const u_char *eom1,
@@ -304,14 +305,14 @@ int
res_nsend(res_state statp,
const u_char *buf, int buflen, u_char *ans, int anssiz)
{
- int gotsomewhere, terrno, try, v_circuit, resplen, ns, n;
+ int gotsomewhere, terrno, tries, v_circuit, resplen, ns, n;
char abuf[NI_MAXHOST];
-#ifdef SUNW_POLL
+#ifdef USE_POLL
highestFD = sysconf(_SC_OPEN_MAX) - 1;
#endif
- /* No name servers or previous res_ninit() failure */
+ /* No name servers or res_init() failure */
if (statp->nscount == 0 || EXT(statp).ext == NULL) {
errno = ESRCH;
return (-1);
@@ -349,7 +350,7 @@ res_nsend(res_state statp,
if (EXT(statp).nssocks[ns] == -1)
continue;
peerlen = sizeof(peer);
- if (getsockname(EXT(statp).nssocks[ns],
+ if (getpeername(EXT(statp).nssocks[ns],
(struct sockaddr *)&peer, &peerlen) < 0) {
needclose++;
break;
@@ -385,8 +386,8 @@ res_nsend(res_state statp,
* Some resolvers want to even out the load on their nameservers.
* Note that RES_BLAST overrides RES_ROTATE.
*/
- if ((statp->options & RES_ROTATE) != 0 &&
- (statp->options & RES_BLAST) == 0) {
+ if ((statp->options & RES_ROTATE) != 0U &&
+ (statp->options & RES_BLAST) == 0U) {
union res_sockaddr_union inu;
struct sockaddr_in ina;
int lastns = statp->nscount - 1;
@@ -400,7 +401,7 @@ res_nsend(res_state statp,
nstime = EXT(statp).nstimes[0];
for (ns = 0; ns < lastns; ns++) {
if (EXT(statp).ext != NULL)
- EXT(statp).ext->nsaddrs[ns] =
+ EXT(statp).ext->nsaddrs[ns] =
EXT(statp).ext->nsaddrs[ns + 1];
statp->nsaddr_list[ns] = statp->nsaddr_list[ns + 1];
EXT(statp).nssocks[ns] = EXT(statp).nssocks[ns + 1];
@@ -416,7 +417,7 @@ res_nsend(res_state statp,
/*
* Send request, RETRY times, or until successful.
*/
- for (try = 0; try < statp->retry; try++) {
+ for (tries = 0; tries < statp->retry; tries++) {
for (ns = 0; ns < statp->nscount; ns++) {
struct sockaddr *nsap;
int nsaplen;
@@ -464,7 +465,7 @@ res_nsend(res_state statp,
if (v_circuit) {
/* Use VC; at most one attempt per server. */
- try = statp->retry;
+ tries = statp->retry;
n = send_vc(statp, buf, buflen, ans, anssiz, &terrno,
ns);
if (n < 0)
@@ -475,7 +476,7 @@ res_nsend(res_state statp,
} else {
/* Use datagrams. */
n = send_dg(statp, buf, buflen, ans, anssiz, &terrno,
- ns, &v_circuit, &gotsomewhere);
+ ns, tries, &v_circuit, &gotsomewhere);
if (n < 0)
goto fail;
if (n == 0)
@@ -500,8 +501,8 @@ res_nsend(res_state statp,
* or if we haven't been asked to keep a socket open,
* close the socket.
*/
- if ((v_circuit && (statp->options & RES_USEVC) == 0) ||
- (statp->options & RES_STAYOPEN) == 0) {
+ if ((v_circuit && (statp->options & RES_USEVC) == 0U) ||
+ (statp->options & RES_STAYOPEN) == 0U) {
res_nclose(statp);
}
if (statp->rhook) {
@@ -540,9 +541,9 @@ res_nsend(res_state statp,
res_nclose(statp);
if (!v_circuit) {
if (!gotsomewhere)
- errno = ECONNREFUSED; /* no nameservers found */
+ errno = ECONNREFUSED; /*%< no nameservers found */
else
- errno = ETIMEDOUT; /* no answer obtained */
+ errno = ETIMEDOUT; /*%< no answer obtained */
} else
errno = terrno;
return (-1);
@@ -569,10 +570,10 @@ get_salen(sa)
else if (sa->sa_family == AF_INET6)
return (sizeof(struct sockaddr_in6));
else
- return (0); /* unknown, die on connect */
+ return (0); /*%< unknown, die on connect */
}
-/*
+/*%
* pick appropriate nsaddr_list for use. see res_init() for initialization.
*/
static struct sockaddr *
@@ -612,6 +613,9 @@ send_vc(res_state statp,
u_short len;
u_char *cp;
void *tmp;
+#ifdef SO_NOSIGPIPE
+ int on = 1;
+#endif
nsap = get_nsaddr(statp, ns);
nsaplen = get_salen(nsap);
@@ -643,10 +647,31 @@ send_vc(res_state statp,
errno = ENOTSOCK;
}
if (statp->_vcsock < 0) {
- *terrno = errno;
- Perror(statp, stderr, "socket(vc)", errno);
- return (-1);
+ switch (errno) {
+ case EPROTONOSUPPORT:
+#ifdef EPFNOSUPPORT
+ case EPFNOSUPPORT:
+#endif
+ case EAFNOSUPPORT:
+ Perror(statp, stderr, "socket(vc)", errno);
+ return (0);
+ default:
+ *terrno = errno;
+ Perror(statp, stderr, "socket(vc)", errno);
+ return (-1);
+ }
}
+#ifdef SO_NOSIGPIPE
+ /*
+ * Disable generation of SIGPIPE when writing to a closed
+ * socket. Write should return -1 and set errno to EPIPE
+ * instead.
+ *
+ * Push on even if setsockopt(SO_NOSIGPIPE) fails.
+ */
+ (void)setsockopt(statp->_vcsock, SOL_SOCKET, SO_NOSIGPIPE, &on,
+ sizeof(on));
+#endif
errno = 0;
if (connect(statp->_vcsock, nsap, nsaplen) < 0) {
*terrno = errno;
@@ -679,7 +704,7 @@ send_vc(res_state statp,
len = INT16SZ;
while ((n = read(statp->_vcsock, (char *)cp, (int)len)) > 0) {
cp += n;
- if ((len -= n) <= 0)
+ if ((len -= n) == 0)
break;
}
if (n <= 0) {
@@ -739,14 +764,6 @@ send_vc(res_state statp,
*/
anhp->tc = 1;
len = resplen - anssiz;
- /*
- * Reset the value of resplen to anssiz,
- * this is done because the caller assumes
- * resplen contains the size of message read
- * into the "ans" buffer passed in.
- */
- resplen = anssiz;
-
while (len != 0) {
char junk[PACKETSZ];
@@ -781,22 +798,23 @@ send_vc(res_state statp,
}
static int
-send_dg(res_state statp,
- const u_char *buf, int buflen, u_char *ans, int anssiz,
- int *terrno, int ns, int *v_circuit, int *gotsomewhere)
+send_dg(res_state statp, const u_char *buf, int buflen, u_char *ans,
+ int anssiz, int *terrno, int ns, int tries, int *v_circuit,
+ int *gotsomewhere)
{
const HEADER *hp = (const HEADER *) buf;
HEADER *anhp = (HEADER *) ans;
const struct sockaddr *nsap;
int nsaplen;
struct timespec now, timeout, finish;
- fd_set dsmask;
struct sockaddr_storage from;
ISC_SOCKLEN_T fromlen;
int resplen, seconds, n, s;
-#ifdef SUNW_POLL
- int polltimeout;
+#ifdef USE_POLL
+ int polltimeout;
struct pollfd pollfd;
+#else
+ fd_set dsmask;
#endif
nsap = get_nsaddr(statp, ns);
@@ -808,9 +826,19 @@ send_dg(res_state statp,
errno = ENOTSOCK;
}
if (EXT(statp).nssocks[ns] < 0) {
- *terrno = errno;
- Perror(statp, stderr, "socket(dg)", errno);
- return (-1);
+ switch (errno) {
+ case EPROTONOSUPPORT:
+#ifdef EPFNOSUPPORT
+ case EPFNOSUPPORT:
+#endif
+ case EAFNOSUPPORT:
+ Perror(statp, stderr, "socket(dg)", errno);
+ return (0);
+ default:
+ *terrno = errno;
+ Perror(statp, stderr, "socket(dg)", errno);
+ return (-1);
+ }
}
#ifndef CANNOT_CONNECT_DGRAM
/*
@@ -853,7 +881,7 @@ send_dg(res_state statp,
/*
* Wait for reply.
*/
- seconds = (statp->retrans << ns);
+ seconds = (statp->retrans << tries);
if (ns > 0)
seconds /= statp->nscount;
if (seconds <= 0)
@@ -865,7 +893,15 @@ send_dg(res_state statp,
wait:
now = evNowTime();
nonow:
-#ifdef SUNW_POLL
+#ifndef USE_POLL
+ FD_ZERO(&dsmask);
+ FD_SET(s, &dsmask);
+ if (evCmpTime(finish, now) > 0)
+ timeout = evSubTime(finish, now);
+ else
+ timeout = evConsTime(0, 0);
+ n = pselect(s + 1, &dsmask, NULL, NULL, &timeout, NULL);
+#else
timeout = evSubTime(finish, now);
if (timeout.tv_sec < 0)
timeout = evConsTime(0, 0);
@@ -874,15 +910,8 @@ send_dg(res_state statp,
pollfd.fd = s;
pollfd.events = POLLRDNORM;
n = poll(&pollfd, 1, polltimeout);
-#else
- FD_ZERO(&dsmask);
- FD_SET(s, &dsmask);
- if (evCmpTime(finish, now) > 0)
- timeout = evSubTime(finish, now);
- else
- timeout = evConsTime(0, 0);
- n = pselect(s + 1, &dsmask, NULL, NULL, &timeout, NULL);
-#endif
+#endif /* USE_POLL */
+
if (n == 0) {
Dprint(statp->options & RES_DEBUG, (stdout, ";; timeout\n"));
*gotsomewhere = 1;
@@ -891,11 +920,11 @@ send_dg(res_state statp,
if (n < 0) {
if (errno == EINTR)
goto wait;
-#ifdef SUNW_POLL
- Perror(statp, stderr, "poll", errno);
-#else
+#ifndef USE_POLL
Perror(statp, stderr, "select", errno);
-#endif
+#else
+ Perror(statp, stderr, "poll", errno);
+#endif /* USE_POLL */
res_nclose(statp);
return (0);
}
@@ -946,7 +975,7 @@ send_dg(res_state statp,
goto wait;
}
#ifdef RES_USE_EDNS0
- if (anhp->rcode == FORMERR && (statp->options & RES_USE_EDNS0) != 0) {
+ if (anhp->rcode == FORMERR && (statp->options & RES_USE_EDNS0) != 0U) {
/*
* Do not retry if the server do not understand EDNS0.
* The case has to be captured here, as FORMERR packet do not
@@ -1014,7 +1043,7 @@ Aerror(const res_state statp, FILE *file, const char *string, int error,
alen = alen;
- if ((statp->options & RES_DEBUG) != 0) {
+ if ((statp->options & RES_DEBUG) != 0U) {
if (getnameinfo(address, alen, hbuf, sizeof(hbuf),
sbuf, sizeof(sbuf), niflags)) {
strncpy(hbuf, "?", sizeof(hbuf) - 1);
@@ -1032,7 +1061,7 @@ static void
Perror(const res_state statp, FILE *file, const char *string, int error) {
int save = errno;
- if ((statp->options & RES_DEBUG) != 0)
+ if ((statp->options & RES_DEBUG) != 0U)
fprintf(file, "res_send: %s: %s\n",
string, strerror(error));
errno = save;
@@ -1064,7 +1093,7 @@ sock_eq(struct sockaddr *a, struct sockaddr *b) {
}
}
-#ifdef NEED_PSELECT
+#if defined(NEED_PSELECT) && !defined(USE_POLL)
/* XXX needs to move to the porting library. */
static int
pselect(int nfds, void *rfds, void *wfds, void *efds,
diff --git a/usr/src/lib/libresolv2/common/resolv/res_sendsigned.c b/usr/src/lib/libresolv2/common/resolv/res_sendsigned.c
index 63fe5cc2d9..63ae07ce3d 100644
--- a/usr/src/lib/libresolv2/common/resolv/res_sendsigned.c
+++ b/usr/src/lib/libresolv2/common/resolv/res_sendsigned.c
@@ -1,12 +1,3 @@
-/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- *
- * No ISC copyright for this file.
- */
-
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#include "port_before.h"
#include "fd_setsize.h"
@@ -33,7 +24,7 @@
#include "res_debug.h"
-/* res_nsendsigned */
+/*% res_nsendsigned */
int
res_nsendsigned(res_state statp, const u_char *msg, int msglen,
ns_tsig_key *key, u_char *answer, int anslen)
@@ -47,6 +38,7 @@ res_nsendsigned(res_state statp, const u_char *msg, int msglen,
HEADER *hp;
time_t tsig_time;
int ret;
+ int len;
dst_init();
@@ -60,6 +52,7 @@ res_nsendsigned(res_state statp, const u_char *msg, int msglen,
bufsize = msglen + 1024;
newmsg = (u_char *) malloc(bufsize);
if (newmsg == NULL) {
+ free(nstatp);
errno = ENOMEM;
return (-1);
}
@@ -95,34 +88,51 @@ res_nsendsigned(res_state statp, const u_char *msg, int msglen,
return (ret);
}
- if (newmsglen > PACKETSZ || (nstatp->options & RES_IGNTC))
+ if (newmsglen > PACKETSZ || nstatp->options & RES_USEVC)
usingTCP = 1;
if (usingTCP == 0)
nstatp->options |= RES_IGNTC;
else
nstatp->options |= RES_USEVC;
+ /*
+ * Stop res_send printing the answer.
+ */
+ nstatp->options &= ~RES_DEBUG;
+ nstatp->pfcode &= ~RES_PRF_REPLY;
retry:
- ret = res_nsend(nstatp, newmsg, newmsglen, answer, anslen);
- if (ret < 0) {
+ len = res_nsend(nstatp, newmsg, newmsglen, answer, anslen);
+ if (len < 0) {
free (nstatp);
free (newmsg);
dst_free_key(dstkey);
- return (ret);
+ return (len);
}
- anslen = ret;
- ret = ns_verify(answer, &anslen, dstkey, sig, siglen,
+ ret = ns_verify(answer, &len, dstkey, sig, siglen,
NULL, NULL, &tsig_time, nstatp->options & RES_KEEPTSIG);
if (ret != 0) {
-#ifdef ORIGINAL_ISC_CODE
- Dprint(nstatp->pfcode & RES_PRF_REPLY,
- (stdout, ";; TSIG invalid (%s)\n", p_rcode(ret)));
-#else
- Dprint(nstatp->pfcode & RES_PRF_REPLY,
- (stdout, ";; TSIG invalid (%s)\n", p_rcode(-ret)));
-#endif
+ Dprint((statp->options & RES_DEBUG) ||
+ ((statp->pfcode & RES_PRF_REPLY) &&
+ (statp->pfcode & RES_PRF_HEAD1)),
+ (stdout, ";; got answer:\n"));
+
+ DprintQ((statp->options & RES_DEBUG) ||
+ (statp->pfcode & RES_PRF_REPLY),
+ (stdout, "%s", ""),
+ answer, (anslen > len) ? len : anslen);
+
+ if (ret > 0) {
+ Dprint(statp->pfcode & RES_PRF_REPLY,
+ (stdout, ";; server rejected TSIG (%s)\n",
+ p_rcode(ret)));
+ } else {
+ Dprint(statp->pfcode & RES_PRF_REPLY,
+ (stdout, ";; TSIG invalid (%s)\n",
+ p_rcode(-ret)));
+ }
+
free (nstatp);
free (newmsg);
dst_free_key(dstkey);
@@ -132,17 +142,29 @@ retry:
errno = ENOTTY;
return (-1);
}
- Dprint(nstatp->pfcode & RES_PRF_REPLY, (stdout, ";; TSIG ok\n"));
hp = (HEADER *) answer;
- if (hp->tc && usingTCP == 0) {
+ if (hp->tc && !usingTCP && (statp->options & RES_IGNTC) == 0U) {
nstatp->options &= ~RES_IGNTC;
usingTCP = 1;
goto retry;
}
+ Dprint((statp->options & RES_DEBUG) ||
+ ((statp->pfcode & RES_PRF_REPLY) &&
+ (statp->pfcode & RES_PRF_HEAD1)),
+ (stdout, ";; got answer:\n"));
+
+ DprintQ((statp->options & RES_DEBUG) ||
+ (statp->pfcode & RES_PRF_REPLY),
+ (stdout, "%s", ""),
+ answer, (anslen > len) ? len : anslen);
+
+ Dprint(statp->pfcode & RES_PRF_REPLY, (stdout, ";; TSIG ok\n"));
free (nstatp);
free (newmsg);
dst_free_key(dstkey);
- return (anslen);
+ return (len);
}
+
+/*! \file */
diff --git a/usr/src/lib/libresolv2/common/resolv/res_update.c b/usr/src/lib/libresolv2/common/resolv/res_update.c
index 8983dee245..5b2ecb1a35 100644
--- a/usr/src/lib/libresolv2/common/resolv/res_update.c
+++ b/usr/src/lib/libresolv2/common/resolv/res_update.c
@@ -1,34 +1,28 @@
-/*
- * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
#if !defined(lint) && !defined(SABER)
-static const char rcsid[] = "$Id: res_update.c,v 1.38 2003/05/27 23:36:53 marka Exp $";
+static const char rcsid[] = "$Id: res_update.c,v 1.13 2005/04/27 04:56:43 sra Exp $";
#endif /* not lint */
/*
+ * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1996-1999 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.
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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.
*/
-#pragma ident "%Z%%M% %I% %E% SMI"
-
-/*
+/*! \file
+ * \brief
* Based on the Dynamic DNS reference implementation by Viraj Bais
- * <viraj_bais@ccm.fm.intel.com>
+ * &lt;viraj_bais@ccm.fm.intel.com>
*/
#include "port_before.h"
@@ -56,7 +50,7 @@ static const char rcsid[] = "$Id: res_update.c,v 1.38 2003/05/27 23:36:53 marka
#include "port_after.h"
#include "res_private.h"
-/*
+/*%
* Separate a linked list of records into groups so that all records
* in a group will belong to a single zone on the nameserver.
* Create a dynamic update packet for each zone and send it to the
@@ -90,7 +84,7 @@ static void res_dprintf(const char *, ...) ISC_FORMAT_PRINTF(1, 2);
#define DPRINTF(x) do {\
int save_errno = errno; \
- if ((statp->options & RES_DEBUG) != 0) res_dprintf x; \
+ if ((statp->options & RES_DEBUG) != 0U) res_dprintf x; \
errno = save_errno; \
} while (0)