diff --git a/lib/libc/include/isc/list.h b/lib/libc/include/isc/list.h index 489766a9f0d7..68d4ef06d1fb 100644 --- a/lib/libc/include/isc/list.h +++ b/lib/libc/include/isc/list.h @@ -1,4 +1,4 @@ -/* $NetBSD: list.h,v 1.2 2004/05/20 19:51:55 christos Exp $ */ +/* $NetBSD: list.h,v 1.3 2007/01/27 22:26:43 christos Exp $ */ /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -68,12 +68,16 @@ INSIST(LINKED(elt, link));\ if ((elt)->link.next != NULL) \ (elt)->link.next->link.prev = (elt)->link.prev; \ - else \ + else { \ + INSIST((list).tail == (elt)); \ (list).tail = (elt)->link.prev; \ + } \ if ((elt)->link.prev != NULL) \ (elt)->link.prev->link.next = (elt)->link.next; \ - else \ + else { \ + INSIST((list).head == (elt)); \ (list).head = (elt)->link.next; \ + } \ INIT_LINK_TYPE(elt, link, type); \ } while (/*CONSTCOND*/0) #define UNLINK(list, elt, link) \ @@ -112,3 +116,4 @@ #define DEQUEUE(list, elt, link) UNLINK(list, elt, link) #endif /* LIST_H */ +/*! \file */ diff --git a/lib/libc/inet/inet_cidr_ntop.c b/lib/libc/inet/inet_cidr_ntop.c index e85778b90109..945036968f8c 100644 --- a/lib/libc/inet/inet_cidr_ntop.c +++ b/lib/libc/inet/inet_cidr_ntop.c @@ -1,4 +1,4 @@ -/* $NetBSD: inet_cidr_ntop.c,v 1.3 2006/05/10 21:53:15 mrg Exp $ */ +/* $NetBSD: inet_cidr_ntop.c,v 1.4 2007/01/27 22:26:43 christos Exp $ */ /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -20,9 +20,9 @@ #include #if defined(LIBC_SCCS) && !defined(lint) #if 0 -static const char rcsid[] = "Id: inet_cidr_ntop.c,v 1.1.2.1.8.2 2004/03/17 00:29:46 marka Exp"; +static const char rcsid[] = "Id: inet_cidr_ntop.c,v 1.4.18.3 2006/10/11 02:32:47 marka Exp"; #else -__RCSID("$NetBSD: inet_cidr_ntop.c,v 1.3 2006/05/10 21:53:15 mrg Exp $"); +__RCSID("$NetBSD: inet_cidr_ntop.c,v 1.4 2007/01/27 22:26:43 christos Exp $"); #endif #endif @@ -52,12 +52,12 @@ __weak_alias(inet_cidr_ntop,_inet_cidr_ntop) # define SPRINTF(x) ((size_t)sprintf x) #endif -static char * inet_cidr_ntop_ipv4 __P((const u_char *src, int bits, - char *dst, size_t size)); -static char * inet_cidr_ntop_ipv6 __P((const u_char *src, int bits, - char *dst, size_t size)); +static char * +inet_cidr_ntop_ipv4(const u_char *src, int bits, char *dst, size_t size); +static char * +inet_cidr_ntop_ipv6(const u_char *src, int bits, char *dst, size_t size); -/* +/*% * char * * inet_cidr_ntop(af, src, bits, dst, size) * convert network address from network to presentation format. @@ -104,7 +104,7 @@ decoct(const u_char *src, size_t bytes, char *dst, size_t size) { return (dst - odst); } -/* +/*% * static char * * inet_cidr_ntop_ipv4(src, bits, dst, size) * convert IPv4 network address from network to presentation format. @@ -190,9 +190,9 @@ inet_cidr_ntop_ipv6(const u_char *src, int bits, char *dst, size_t size) { for (i = 0; i < NS_IN6ADDRSZ; i++) words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3)); best.base = -1; + best.len = 0; cur.base = -1; - best.len = -1; /* XXX gcc */ - cur.len = -1; /* XXX gcc */ + cur.len = 0; for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) { if (words[i] == 0) { if (cur.base == -1) @@ -271,3 +271,5 @@ inet_cidr_ntop_ipv6(const u_char *src, int bits, char *dst, size_t size) { strcpy(dst, tmp); return (dst); } + +/*! \file */ diff --git a/lib/libc/inet/inet_cidr_pton.c b/lib/libc/inet/inet_cidr_pton.c index 974f95ee05cb..3899360419c5 100644 --- a/lib/libc/inet/inet_cidr_pton.c +++ b/lib/libc/inet/inet_cidr_pton.c @@ -1,4 +1,4 @@ -/* $NetBSD: inet_cidr_pton.c,v 1.2 2004/05/20 23:12:33 christos Exp $ */ +/* $NetBSD: inet_cidr_pton.c,v 1.3 2007/01/27 22:26:43 christos Exp $ */ /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -20,9 +20,9 @@ #include #if defined(LIBC_SCCS) && !defined(lint) #if 0 -static const char rcsid[] = "Id: inet_cidr_pton.c,v 1.2.2.1.8.2 2004/03/17 00:29:46 marka Exp"; +static const char rcsid[] = "Id: inet_cidr_pton.c,v 1.5.18.1 2005/04/27 05:00:53 sra Exp"; #else -__RCSID("$NetBSD: inet_cidr_pton.c,v 1.2 2004/05/20 23:12:33 christos Exp $"); +__RCSID("$NetBSD: inet_cidr_pton.c,v 1.3 2007/01/27 22:26:43 christos Exp $"); #endif #endif @@ -61,7 +61,7 @@ static int inet_cidr_pton_ipv6 __P((const char *src, u_char *dst, static int getbits(const char *, int ipv6); -/* +/*% * int * inet_cidr_pton(af, src, dst, *bits) * convert network address from presentation to network format. @@ -216,7 +216,7 @@ inet_cidr_pton_ipv6(const char *src, u_char *dst, int *pbits) { inet_cidr_pton_ipv4(curtok, tp, &bits, 1) == 0) { tp += NS_INADDRSZ; saw_xdigit = 0; - break; /* '\0' was seen by inet_pton4(). */ + break; /*%< '\\0' was seen by inet_pton4(). */ } if (ch == '/') { bits = getbits(src, 1); @@ -268,20 +268,22 @@ getbits(const char *src, int ipv6) { int bits = 0; char *cp, ch; - if (*src == '\0') /* syntax */ + if (*src == '\0') /*%< syntax */ return (-2); do { ch = *src++; cp = strchr(digits, ch); - if (cp == NULL) /* syntax */ + if (cp == NULL) /*%< syntax */ return (-2); bits *= 10; bits += cp - digits; - if (bits == 0 && *src != '\0') /* no leading zeros */ + if (bits == 0 && *src != '\0') /*%< no leading zeros */ return (-2); - if (bits > (ipv6 ? 128 : 32)) /* range error */ + if (bits > (ipv6 ? 128 : 32)) /*%< range error */ return (-2); } while (*src != '\0'); return (bits); } + +/*! \file */ diff --git a/lib/libc/inet/inet_ntop.c b/lib/libc/inet/inet_ntop.c index 1efcc81d3f4f..cfc88e39c8a7 100644 --- a/lib/libc/inet/inet_ntop.c +++ b/lib/libc/inet/inet_ntop.c @@ -1,4 +1,4 @@ -/* $NetBSD: inet_ntop.c,v 1.3 2006/05/10 21:53:15 mrg Exp $ */ +/* $NetBSD: inet_ntop.c,v 1.4 2007/01/27 22:26:43 christos Exp $ */ /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -20,9 +20,9 @@ #include #if defined(LIBC_SCCS) && !defined(lint) #if 0 -static const char rcsid[] = "Id: inet_ntop.c,v 1.1.2.1.8.1 2004/03/09 08:33:33 marka Exp"; +static const char rcsid[] = "Id: inet_ntop.c,v 1.3.18.2 2005/11/03 23:02:22 marka Exp"; #else -__RCSID("$NetBSD: inet_ntop.c,v 1.3 2006/05/10 21:53:15 mrg Exp $"); +__RCSID("$NetBSD: inet_ntop.c,v 1.4 2007/01/27 22:26:43 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -49,7 +49,7 @@ __RCSID("$NetBSD: inet_ntop.c,v 1.3 2006/05/10 21:53:15 mrg Exp $"); __weak_alias(inet_ntop,_inet_ntop) #endif -/* +/*% * WARNING: Don't even consider trying to compile this on a system where * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. */ @@ -159,9 +159,9 @@ inet_ntop6(src, dst, size) for (i = 0; i < NS_IN6ADDRSZ; i++) words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3)); best.base = -1; + best.len = 0; cur.base = -1; - best.len = -1; /* XXX gcc */ - cur.len = -1; /* XXX gcc */ + cur.len = 0; for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) { if (words[i] == 0) { if (cur.base == -1) @@ -238,3 +238,5 @@ inet_ntop6(src, dst, size) strlcpy(dst, tmp, size); return (dst); } + +/*! \file */ diff --git a/lib/libc/inet/inet_pton.c b/lib/libc/inet/inet_pton.c index 362df36a1d5d..1af39582cc11 100644 --- a/lib/libc/inet/inet_pton.c +++ b/lib/libc/inet/inet_pton.c @@ -1,4 +1,4 @@ -/* $NetBSD: inet_pton.c,v 1.3 2006/09/26 05:59:18 lukem Exp $ */ +/* $NetBSD: inet_pton.c,v 1.4 2007/01/27 22:26:43 christos Exp $ */ /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -20,9 +20,9 @@ #include #if defined(LIBC_SCCS) && !defined(lint) #if 0 -static const char rcsid[] = "Id: inet_pton.c,v 1.2.206.1 2004/03/09 08:33:33 marka Exp"; +static const char rcsid[] = "Id: inet_pton.c,v 1.3.18.2 2005/07/28 07:38:07 marka Exp"; #else -__RCSID("$NetBSD: inet_pton.c,v 1.3 2006/09/26 05:59:18 lukem Exp $"); +__RCSID("$NetBSD: inet_pton.c,v 1.4 2007/01/27 22:26:43 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -46,7 +46,7 @@ __RCSID("$NetBSD: inet_pton.c,v 1.3 2006/09/26 05:59:18 lukem Exp $"); __weak_alias(inet_pton,_inet_pton) #endif -/* +/*% * WARNING: Don't even consider trying to compile this on a system where * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. */ @@ -225,7 +225,7 @@ inet_pton6(const char *src, u_char *dst) xdigits_u[] = "0123456789ABCDEF"; u_char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp; const char *xdigits, *curtok; - int ch, saw_xdigit; + int ch, seen_xdigits; u_int val; _DIAGASSERT(src != NULL); @@ -239,7 +239,7 @@ inet_pton6(const char *src, u_char *dst) if (*++src != ':') return (0); curtok = src; - saw_xdigit = 0; + seen_xdigits = 0; val = 0; while ((ch = *src++) != '\0') { const char *pch; @@ -249,14 +249,13 @@ inet_pton6(const char *src, u_char *dst) if (pch != NULL) { val <<= 4; val |= (pch - xdigits); - if (val > 0xffff) + if (++seen_xdigits > 4) return (0); - saw_xdigit = 1; continue; } if (ch == ':') { curtok = src; - if (!saw_xdigit) { + if (!seen_xdigits) { if (colonp) return (0); colonp = tp; @@ -267,19 +266,19 @@ inet_pton6(const char *src, u_char *dst) return (0); *tp++ = (u_char) (val >> 8) & 0xff; *tp++ = (u_char) val & 0xff; - saw_xdigit = 0; + seen_xdigits = 0; val = 0; continue; } if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) && inet_pton4(curtok, tp, 1) > 0) { tp += NS_INADDRSZ; - saw_xdigit = 0; - break; /* '\0' was seen by inet_pton4(). */ + seen_xdigits = 0; + break; /*%< '\\0' was seen by inet_pton4(). */ } return (0); } - if (saw_xdigit) { + if (seen_xdigits) { if (tp + NS_INT16SZ > endp) return (0); *tp++ = (u_char) (val >> 8) & 0xff; @@ -306,3 +305,5 @@ inet_pton6(const char *src, u_char *dst) memcpy(dst, tmp, NS_IN6ADDRSZ); return (1); } + +/*! \file */ diff --git a/lib/libc/inet/nsap_addr.c b/lib/libc/inet/nsap_addr.c index 488a9990ca3b..1ea426d999a2 100644 --- a/lib/libc/inet/nsap_addr.c +++ b/lib/libc/inet/nsap_addr.c @@ -1,4 +1,4 @@ -/* $NetBSD: nsap_addr.c,v 1.2 2004/05/20 23:12:33 christos Exp $ */ +/* $NetBSD: nsap_addr.c,v 1.3 2007/01/27 22:26:43 christos Exp $ */ /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -20,9 +20,9 @@ #include #if defined(LIBC_SCCS) && !defined(lint) #if 0 -static const char rcsid[] = "Id: nsap_addr.c,v 1.2.206.1 2004/03/09 08:33:33 marka Exp"; +static const char rcsid[] = "Id: nsap_addr.c,v 1.3.18.2 2005/07/28 07:38:08 marka Exp"; #else -__RCSID("$NetBSD: nsap_addr.c,v 1.2 2004/05/20 23:12:33 christos Exp $"); +__RCSID("$NetBSD: nsap_addr.c,v 1.3 2007/01/27 22:26:43 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -40,6 +40,7 @@ __RCSID("$NetBSD: nsap_addr.c,v 1.2 2004/05/20 23:12:33 christos Exp $"); #include #include #include +#include #include "port_after.h" @@ -96,7 +97,7 @@ char * inet_nsap_ntoa(int binlen, const u_char *binary, char *ascii) { int nib; int i; - static char tmpbuf[2+255*3]; + char *tmpbuf = inet_nsap_ntoa_tmpbuf; char *start; _DIAGASSERT(binary != NULL); @@ -125,3 +126,5 @@ inet_nsap_ntoa(int binlen, const u_char *binary, char *ascii) { *ascii = '\0'; return (start); } + +/*! \file */ diff --git a/lib/libc/isc/assertions.c b/lib/libc/isc/assertions.c index d3b4d7afda08..2dbe7d0881a9 100644 --- a/lib/libc/isc/assertions.c +++ b/lib/libc/isc/assertions.c @@ -1,4 +1,4 @@ -/* $NetBSD: assertions.c,v 1.2 2004/05/20 19:52:31 christos Exp $ */ +/* $NetBSD: assertions.c,v 1.3 2007/01/27 22:26:43 christos Exp $ */ /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -20,9 +20,9 @@ #include #if !defined(LINT) && !defined(CODECENTER) && !defined(lint) #ifdef notdef -static const char rcsid[] = "Id: assertions.c,v 1.1.206.1 2004/03/09 08:33:39 marka Exp"; +static const char rcsid[] = "Id: assertions.c,v 1.2.18.1 2005/04/27 05:01:05 sra Exp"; #else -__RCSID("$NetBSD: assertions.c,v 1.2 2004/05/20 19:52:31 christos Exp $"); +__RCSID("$NetBSD: assertions.c,v 1.3 2007/01/27 22:26:43 christos Exp $"); #endif #endif @@ -85,6 +85,7 @@ assertion_type_to_text(assertion_type type) { * Private. */ +/* coverity[+kill] */ static void default_assertion_failed(const char *file, int line, assertion_type type, const char *cond, int print_errno) @@ -96,3 +97,5 @@ default_assertion_failed(const char *file, int line, assertion_type type, abort(); /* NOTREACHED */ } + +/*! \file */ diff --git a/lib/libc/isc/ev_streams.c b/lib/libc/isc/ev_streams.c index 7f95def17275..551f56ebfefc 100644 --- a/lib/libc/isc/ev_streams.c +++ b/lib/libc/isc/ev_streams.c @@ -1,4 +1,4 @@ -/* $NetBSD: ev_streams.c,v 1.2 2004/05/20 19:52:31 christos Exp $ */ +/* $NetBSD: ev_streams.c,v 1.3 2007/01/27 22:26:43 christos Exp $ */ /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -24,9 +24,9 @@ #include #if !defined(LINT) && !defined(CODECENTER) && !defined(lint) #ifdef notdef -static const char rcsid[] = "Id: ev_streams.c,v 1.2.206.2 2004/03/17 00:29:51 marka Exp"; +static const char rcsid[] = "Id: ev_streams.c,v 1.4.18.1 2005/04/27 05:01:06 sra Exp"; #else -__RCSID("$NetBSD: ev_streams.c,v 1.2 2004/05/20 19:52:31 christos Exp $"); +__RCSID("$NetBSD: ev_streams.c,v 1.3 2007/01/27 22:26:43 christos Exp $"); #endif #endif @@ -315,3 +315,5 @@ readable(evContext opaqueCtx, void *uap, int fd, int evmask) { done(opaqueCtx, str); } #endif + +/*! \file */ diff --git a/lib/libc/isc/ev_timers.c b/lib/libc/isc/ev_timers.c index 38d37536c1be..bbf693b347c6 100644 --- a/lib/libc/isc/ev_timers.c +++ b/lib/libc/isc/ev_timers.c @@ -1,4 +1,4 @@ -/* $NetBSD: ev_timers.c,v 1.2 2004/05/20 19:52:31 christos Exp $ */ +/* $NetBSD: ev_timers.c,v 1.3 2007/01/27 22:26:43 christos Exp $ */ /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -24,9 +24,9 @@ #include #if !defined(LINT) && !defined(CODECENTER) && !defined(lint) #ifdef notdef -static const char rcsid[] = "Id: ev_timers.c,v 1.2.2.1.4.5 2004/03/17 02:39:13 marka Exp"; +static const char rcsid[] = "Id: ev_timers.c,v 1.5.18.1 2005/04/27 05:01:06 sra Exp"; #else -__RCSID("$NetBSD: ev_timers.c,v 1.2 2004/05/20 19:52:31 christos Exp $"); +__RCSID("$NetBSD: ev_timers.c,v 1.3 2007/01/27 22:26:43 christos Exp $"); #endif #endif @@ -508,3 +508,5 @@ idle_timeout(evContext opaqueCtx, } } #endif + +/*! \file */ diff --git a/lib/libc/nameser/ns_name.c b/lib/libc/nameser/ns_name.c index dd705824e8aa..10bf342c3b73 100644 --- a/lib/libc/nameser/ns_name.c +++ b/lib/libc/nameser/ns_name.c @@ -1,4 +1,4 @@ -/* $NetBSD: ns_name.c,v 1.3 2004/11/07 02:19:49 christos Exp $ */ +/* $NetBSD: ns_name.c,v 1.4 2007/01/27 22:26:43 christos Exp $ */ /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -20,9 +20,9 @@ #include #ifndef lint #ifdef notdef -static const char rcsid[] = "Id: ns_name.c,v 1.3.2.4.4.2 2004/05/04 03:27:47 marka Exp"; +static const char rcsid[] = "Id: ns_name.c,v 1.8.18.2 2005/04/27 05:01:08 sra Exp"; #else -__RCSID("$NetBSD: ns_name.c,v 1.3 2004/11/07 02:19:49 christos Exp $"); +__RCSID("$NetBSD: ns_name.c,v 1.4 2007/01/27 22:26:43 christos Exp $"); #endif #endif @@ -48,7 +48,7 @@ __RCSID("$NetBSD: ns_name.c,v 1.3 2004/11/07 02:19:49 christos Exp $"); # define SPRINTF(x) ((size_t)sprintf x) #endif -#define NS_TYPE_ELT 0x40 /* EDNS0 extended label type */ +#define NS_TYPE_ELT 0x40 /*%< EDNS0 extended label type */ #define DNS_LABELTYPE_BITSTRING 0x41 /* Data. */ @@ -90,14 +90,15 @@ static int decode_bitstring(const unsigned char **, /* Public. */ -/* - * ns_name_ntop(src, dst, dstsiz) +/*% * Convert an encoded domain name to printable ascii as per RFC1035. + * return: - * Number of bytes written to buffer, or -1 (with errno set) + *\li Number of bytes written to buffer, or -1 (with errno set) + * * notes: - * The root is returned as "." - * All other domains are returned in non absolute form + *\li The root is returned as "." + *\li All other domains are returned in non absolute form */ int ns_name_ntop(const u_char *src, char *dst, size_t dstsiz) @@ -126,7 +127,7 @@ ns_name_ntop(const u_char *src, char *dst, size_t dstsiz) *dn++ = '.'; } if ((l = labellen(cp - 1)) < 0) { - errno = EMSGSIZE; /* XXX */ + errno = EMSGSIZE; /*%< XXX */ return(-1); } if (dn + l >= eom) { @@ -191,15 +192,17 @@ ns_name_ntop(const u_char *src, char *dst, size_t dstsiz) return (dn - dst); } -/* - * ns_name_pton(src, dst, dstsiz) +/*% * Convert a ascii string into an encoded domain name as per RFC1035. + * * return: - * -1 if it fails - * 1 if string was fully qualified - * 0 is string was not fully qualified + * + *\li -1 if it fails + *\li 1 if string was fully qualified + *\li 0 is string was not fully qualified + * * notes: - * Enforces label and domain length limits. + *\li Enforces label and domain length limits. */ int @@ -216,9 +219,9 @@ ns_name_pton(const char *src, u_char *dst, size_t dstsiz) while ((c = *src++) != 0) { if (escaped) { - if (c == '[') { /* start a bit string label */ + if (c == '[') { /*%< start a bit string label */ if ((cp = strchr(src, ']')) == NULL) { - errno = EINVAL; /* ??? */ + errno = EINVAL; /*%< ??? */ return(-1); } if ((e = encode_bitsring(&src, cp + 2, @@ -263,7 +266,7 @@ ns_name_pton(const char *src, u_char *dst, size_t dstsiz) continue; } else if (c == '.') { c = (bp - label - 1); - if ((c & NS_CMPRSFLGS) != 0) { /* Label too big. */ + if ((c & NS_CMPRSFLGS) != 0) { /*%< Label too big. */ errno = EMSGSIZE; return (-1); } @@ -301,7 +304,7 @@ ns_name_pton(const char *src, u_char *dst, size_t dstsiz) *bp++ = (u_char)c; } c = (bp - label - 1); - if ((c & NS_CMPRSFLGS) != 0) { /* Label too big. */ + if ((c & NS_CMPRSFLGS) != 0) { /*%< Label too big. */ errno = EMSGSIZE; return (-1); } @@ -318,20 +321,21 @@ ns_name_pton(const char *src, u_char *dst, size_t dstsiz) } *bp++ = 0; } - if ((bp - dst) > MAXCDNAME) { /* src too big */ + if ((bp - dst) > MAXCDNAME) { /*%< src too big */ errno = EMSGSIZE; return (-1); } return (0); } -/* - * ns_name_ntol(src, dst, dstsiz) +/*% * Convert a network strings labels into all lowercase. + * * return: - * Number of bytes written to buffer, or -1 (with errno set) + *\li Number of bytes written to buffer, or -1 (with errno set) + * * notes: - * Enforces label and domain length limits. + *\li Enforces label and domain length limits. */ int @@ -378,11 +382,11 @@ ns_name_ntol(const u_char *src, u_char *dst, size_t dstsiz) return (dn - dst); } -/* - * ns_name_unpack(msg, eom, src, dst, dstsiz) +/*% * Unpack a domain name from a message, source may be compressed. + * * return: - * -1 if it fails, or consumed octets if it succeeds. + *\li -1 if it fails, or consumed octets if it succeeds. */ int ns_name_unpack(const u_char *msg, const u_char *eom, const u_char *src, @@ -431,7 +435,7 @@ ns_name_unpack(const u_char *msg, const u_char *eom, const u_char *src, if (len < 0) len = srcp - src + 1; srcp = msg + (((n & 0x3f) << 8) | (*srcp & 0xff)); - if (srcp < msg || srcp >= eom) { /* Out of range. */ + if (srcp < msg || srcp >= eom) { /*%< Out of range. */ errno = EMSGSIZE; return (-1); } @@ -449,7 +453,7 @@ ns_name_unpack(const u_char *msg, const u_char *eom, const u_char *src, default: errno = EMSGSIZE; - return (-1); /* flag error */ + return (-1); /*%< flag error */ } } *dstp = '\0'; @@ -458,19 +462,21 @@ ns_name_unpack(const u_char *msg, const u_char *eom, const u_char *src, return (len); } -/* - * ns_name_pack(src, dst, dstsiz, dnptrs, lastdnptr) +/*% * Pack domain name 'domain' into 'comp_dn'. + * * return: - * Size of the compressed name, or -1. + *\li Size of the compressed name, or -1. + * * notes: - * 'dnptrs' is an array of pointers to previous compressed names. - * dnptrs[0] is a pointer to the beginning of the message. The array + *\li 'dnptrs' is an array of pointers to previous compressed names. + *\li dnptrs[0] is a pointer to the beginning of the message. The array * ends with NULL. - * 'lastdnptr' is a pointer to the end of the array pointed to + *\li 'lastdnptr' is a pointer to the end of the array pointed to * by 'dnptrs'. + * * Side effects: - * The list of pointers in dnptrs is updated for labels inserted into + *\li The list of pointers in dnptrs is updated for labels inserted into * the message as we compress the name. If 'dnptr' is NULL, we don't * try to compress names. If 'lastdnptr' is NULL, we don't update the * list. @@ -491,8 +497,8 @@ ns_name_pack(const u_char *src, u_char *dst, int dstsiz, if (dnptrs != NULL) { if ((msg = *dnptrs++) != NULL) { for (cpp = dnptrs; *cpp != NULL; cpp++) - ; - lpp = cpp; /* end of list to search */ + continue; + lpp = cpp; /*%< end of list to search */ } } else msg = NULL; @@ -567,13 +573,14 @@ cleanup: return (dstp - dst); } -/* - * ns_name_uncompress(msg, eom, src, dst, dstsiz) +/*% * Expand compressed domain name to presentation format. + * * return: - * Number of bytes read out of `src', or -1 (with errno set). + *\li Number of bytes read out of `src', or -1 (with errno set). + * * note: - * Root domain returns as "." not "". + *\li Root domain returns as "." not "". */ int ns_name_uncompress(const u_char *msg, const u_char *eom, const u_char *src, @@ -589,18 +596,19 @@ ns_name_uncompress(const u_char *msg, const u_char *eom, const u_char *src, return (n); } -/* - * ns_name_compress(src, dst, dstsiz, dnptrs, lastdnptr) +/*% * Compress a domain name into wire format, using compression pointers. + * * return: - * Number of bytes consumed in `dst' or -1 (with errno set). + *\li Number of bytes consumed in `dst' or -1 (with errno set). + * * notes: - * 'dnptrs' is an array of pointers to previous compressed names. - * dnptrs[0] is a pointer to the beginning of the message. - * The list ends with NULL. 'lastdnptr' is a pointer to the end of the + *\li 'dnptrs' is an array of pointers to previous compressed names. + *\li dnptrs[0] is a pointer to the beginning of the message. + *\li The list ends with NULL. 'lastdnptr' is a pointer to the end of the * array pointed to by 'dnptrs'. Side effect is to update the list of * pointers for labels inserted into the message as we compress the name. - * If 'dnptr' is NULL, we don't try to compress names. If 'lastdnptr' + *\li If 'dnptr' is NULL, we don't try to compress names. If 'lastdnptr' * is NULL, we don't update the list. */ int @@ -614,7 +622,7 @@ ns_name_compress(const char *src, u_char *dst, size_t dstsiz, return (ns_name_pack(tmp, dst, (int)dstsiz, dnptrs, lastdnptr)); } -/* +/*% * Reset dnptrs so that there are no active references to pointers at or * after src. */ @@ -631,11 +639,11 @@ ns_name_rollback(const u_char *src, const u_char **dnptrs, } } -/* - * ns_name_skip(ptrptr, eom) +/*% * Advance *ptrptr to skip over the compressed name it points at. + * * return: - * 0 on success, -1 (with errno set) on failure. + *\li 0 on success, -1 (with errno set) on failure. */ int ns_name_skip(const u_char **ptrptr, const u_char *eom) @@ -648,20 +656,20 @@ ns_name_skip(const u_char **ptrptr, const u_char *eom) while (cp < eom && (n = *cp++) != 0) { /* Check for indirection. */ switch (n & NS_CMPRSFLGS) { - case 0: /* normal case, n == len */ + case 0: /*%< normal case, n == len */ cp += n; continue; - case NS_TYPE_ELT: /* EDNS0 extended label */ + case NS_TYPE_ELT: /*%< EDNS0 extended label */ if ((l = labellen(cp - 1)) < 0) { - errno = EMSGSIZE; /* XXX */ + errno = EMSGSIZE; /*%< XXX */ return(-1); } cp += l; continue; - case NS_CMPRSFLGS: /* indirection */ + case NS_CMPRSFLGS: /*%< indirection */ cp++; break; - default: /* illegal type */ + default: /*%< illegal type */ errno = EMSGSIZE; return (-1); } @@ -677,44 +685,44 @@ ns_name_skip(const u_char **ptrptr, const u_char *eom) /* Private. */ -/* - * special(ch) +/*% * Thinking in noninternationalized USASCII (per the DNS spec), * is this characted special ("in need of quoting") ? + * * return: - * boolean. + *\li boolean. */ static int special(int ch) { switch (ch) { - case 0x22: /* '"' */ - case 0x2E: /* '.' */ - case 0x3B: /* ';' */ - case 0x5C: /* '\\' */ - case 0x28: /* '(' */ - case 0x29: /* ')' */ + case 0x22: /*%< '"' */ + case 0x2E: /*%< '.' */ + case 0x3B: /*%< ';' */ + case 0x5C: /*%< '\\' */ + case 0x28: /*%< '(' */ + case 0x29: /*%< ')' */ /* Special modifiers in zone files. */ - case 0x40: /* '@' */ - case 0x24: /* '$' */ + case 0x40: /*%< '@' */ + case 0x24: /*%< '$' */ return (1); default: return (0); } } -/* - * printable(ch) +/*% * Thinking in noninternationalized USASCII (per the DNS spec), * is this character visible and not a space when printed ? + * * return: - * boolean. + *\li boolean. */ static int printable(int ch) { return (ch > 0x20 && ch < 0x7f); } -/* +/*% * Thinking in noninternationalized USASCII (per the DNS spec), * convert this character to lower case if it's upper case. */ @@ -725,14 +733,15 @@ mklower(int ch) { return (ch); } -/* - * dn_find(domain, msg, dnptrs, lastdnptr) +/*% * Search for the counted-label name in an array of compressed names. + * * return: - * offset from msg if found, or -1. + *\li offset from msg if found, or -1. + * * notes: - * dnptrs is the pointer to the first name on the list, - * not the pointer to the start of the message. + *\li dnptrs is the pointer to the first name on the list, + *\li not the pointer to the start of the message. */ static int dn_find(const u_char *domain, const u_char *msg, @@ -760,9 +769,8 @@ dn_find(const u_char *domain, const u_char *msg, * check for indirection */ switch (n & NS_CMPRSFLGS) { - case 0: /* normal case, n == len */ - n = labellen(cp - 1); /* XXX */ - + case 0: /*%< normal case, n == len */ + n = labellen(cp - 1); /*%< XXX */ if (n != *dn++) goto next; @@ -776,11 +784,11 @@ dn_find(const u_char *domain, const u_char *msg, if (*dn) continue; goto next; - case NS_CMPRSFLGS: /* indirection */ + case NS_CMPRSFLGS: /*%< indirection */ cp = msg + (((n & 0x3f) << 8) | *cp); break; - default: /* illegal type */ + default: /*%< illegal type */ errno = EMSGSIZE; return (-1); } @@ -862,12 +870,12 @@ encode_bitsring(const char **bp, const char *end, unsigned char **labelp, /* XXX: currently, only hex strings are supported */ if (*cp++ != 'x') return(EINVAL); - if (!isxdigit((*cp) & 0xff)) /* reject '\[x/BLEN]' */ + if (!isxdigit((*cp) & 0xff)) /*%< reject '\[x/BLEN]' */ return(EINVAL); for (tp = *dst + 1; cp < end && tp < eom; cp++) { switch((c = *cp)) { - case ']': /* end of the bitstring */ + case ']': /*%< end of the bitstring */ if (afterslash) { if (beg_blen == NULL) return(EINVAL); @@ -877,7 +885,7 @@ encode_bitsring(const char **bp, const char *end, unsigned char **labelp, } if (count) *tp++ = ((value << 4) & 0xff); - cp++; /* skip ']' */ + cp++; /*%< skip ']' */ goto done; case '/': afterslash = 1; @@ -921,14 +929,14 @@ encode_bitsring(const char **bp, const char *end, unsigned char **labelp, * MUST be just sufficient to contain the number of bits specified * by the . If there are insignificant bits in a final * hexadecimal or octal digit, they MUST be zero. - * RFC 2673, Section 3.2. + * RFC2673, Section 3.2. */ if (blen > 0) { int traillen; if (((blen + 3) & ~3) != tbcount) return(EINVAL); - traillen = tbcount - blen; /* between 0 and 3 */ + traillen = tbcount - blen; /*%< between 0 and 3 */ if (((value << (8 - traillen)) & 0xff) != 0) return(EINVAL); } @@ -964,7 +972,9 @@ labellen(const u_char *lp) bitlen = 256; return((bitlen + 7 ) / 8 + 1); } - return(-1); /* unknwon ELT */ + return(-1); /*%< unknwon ELT */ } return(l); } + +/*! \file */ diff --git a/lib/libc/nameser/ns_netint.c b/lib/libc/nameser/ns_netint.c index f20e84ab8cee..a99f4564c080 100644 --- a/lib/libc/nameser/ns_netint.c +++ b/lib/libc/nameser/ns_netint.c @@ -1,4 +1,4 @@ -/* $NetBSD: ns_netint.c,v 1.2 2004/05/20 20:19:00 christos Exp $ */ +/* $NetBSD: ns_netint.c,v 1.3 2007/01/27 22:26:43 christos Exp $ */ /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -20,9 +20,9 @@ #include #ifndef lint #ifdef notdef -static const char rcsid[] = "Id: ns_netint.c,v 1.1.206.1 2004/03/09 08:33:44 marka Exp"; +static const char rcsid[] = "Id: ns_netint.c,v 1.2.18.1 2005/04/27 05:01:08 sra Exp"; #else -__RCSID("$NetBSD: ns_netint.c,v 1.2 2004/05/20 20:19:00 christos Exp $"); +__RCSID("$NetBSD: ns_netint.c,v 1.3 2007/01/27 22:26:43 christos Exp $"); #endif #endif @@ -61,3 +61,5 @@ void ns_put32(u_int32_t src, u_char *dst) { NS_PUT32(src, dst); } + +/*! \file */ diff --git a/lib/libc/nameser/ns_parse.c b/lib/libc/nameser/ns_parse.c index 039b03399a81..d5ea6cec6609 100644 --- a/lib/libc/nameser/ns_parse.c +++ b/lib/libc/nameser/ns_parse.c @@ -1,4 +1,4 @@ -/* $NetBSD: ns_parse.c,v 1.3 2006/10/15 16:13:12 christos Exp $ */ +/* $NetBSD: ns_parse.c,v 1.4 2007/01/27 22:26:43 christos Exp $ */ /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -20,9 +20,9 @@ #include #ifndef lint #ifdef notdef -static const char rcsid[] = "Id: ns_parse.c,v 1.3.2.1.4.1 2004/03/09 08:33:44 marka Exp"; +static const char rcsid[] = "Id: ns_parse.c,v 1.5.18.3 2005/10/11 00:25:10 marka Exp"; #else -__RCSID("$NetBSD: ns_parse.c,v 1.3 2006/10/15 16:13:12 christos Exp $"); +__RCSID("$NetBSD: ns_parse.c,v 1.4 2007/01/27 22:26:43 christos Exp $"); #endif #endif @@ -47,28 +47,33 @@ static void setsection(ns_msg *msg, ns_sect sect); /* Macros. */ +#ifndef SOLARIS2 #define RETERR(err) do { errno = (err); return (-1); } while (/*NOTREACHED*//*CONSTCOND*/0) +#else +#define RETERR(err) \ + do { errno = (err); if (errno == errno) return (-1); } while (0) +#endif /* Public. */ /* These need to be in the same order as the nres.h:ns_flag enum. */ struct _ns_flagdata _ns_flagdata[16] = { - { 0x8000, 15 }, /* qr. */ - { 0x7800, 11 }, /* opcode. */ - { 0x0400, 10 }, /* aa. */ - { 0x0200, 9 }, /* tc. */ - { 0x0100, 8 }, /* rd. */ - { 0x0080, 7 }, /* ra. */ - { 0x0040, 6 }, /* z. */ - { 0x0020, 5 }, /* ad. */ - { 0x0010, 4 }, /* cd. */ - { 0x000f, 0 }, /* rcode. */ - { 0x0000, 0 }, /* expansion (1/6). */ - { 0x0000, 0 }, /* expansion (2/6). */ - { 0x0000, 0 }, /* expansion (3/6). */ - { 0x0000, 0 }, /* expansion (4/6). */ - { 0x0000, 0 }, /* expansion (5/6). */ - { 0x0000, 0 }, /* expansion (6/6). */ + { 0x8000, 15 }, /*%< qr. */ + { 0x7800, 11 }, /*%< opcode. */ + { 0x0400, 10 }, /*%< aa. */ + { 0x0200, 9 }, /*%< tc. */ + { 0x0100, 8 }, /*%< rd. */ + { 0x0080, 7 }, /*%< ra. */ + { 0x0040, 6 }, /*%< z. */ + { 0x0020, 5 }, /*%< ad. */ + { 0x0010, 4 }, /*%< cd. */ + { 0x000f, 0 }, /*%< rcode. */ + { 0x0000, 0 }, /*%< expansion (1/6). */ + { 0x0000, 0 }, /*%< expansion (2/6). */ + { 0x0000, 0 }, /*%< expansion (3/6). */ + { 0x0000, 0 }, /*%< expansion (4/6). */ + { 0x0000, 0 }, /*%< expansion (5/6). */ + { 0x0000, 0 }, /*%< expansion (6/6). */ }; int ns_msg_getflag(ns_msg handle, int flag) { @@ -139,9 +144,11 @@ ns_initparse(const u_char *msg, int msglen, ns_msg *handle) { int ns_parserr(ns_msg *handle, ns_sect section, int rrnum, ns_rr *rr) { int b; + int tmp; /* Make section right. */ - if (/* section < 0 || */ section >= ns_s_max) + tmp = section; + if (tmp < 0 || section >= ns_s_max) RETERR(ENODEV); if (section != handle->_sect) setsection(handle, section); @@ -207,3 +214,5 @@ setsection(ns_msg *msg, ns_sect sect) { msg->_msg_ptr = msg->_sections[(int)sect]; } } + +/*! \file */ diff --git a/lib/libc/nameser/ns_print.c b/lib/libc/nameser/ns_print.c index 2181127be1fe..9b0b8818b812 100644 --- a/lib/libc/nameser/ns_print.c +++ b/lib/libc/nameser/ns_print.c @@ -1,4 +1,4 @@ -/* $NetBSD: ns_print.c,v 1.5 2004/11/07 02:19:49 christos Exp $ */ +/* $NetBSD: ns_print.c,v 1.6 2007/01/27 22:26:43 christos Exp $ */ /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -20,9 +20,9 @@ #include #ifndef lint #ifdef notdef -static const char rcsid[] = "Id: ns_print.c,v 1.3.2.1.4.5 2004/07/28 20:16:45 marka Exp"; +static const char rcsid[] = "Id: ns_print.c,v 1.6.18.4 2005/04/27 05:01:09 sra Exp"; #else -__RCSID("$NetBSD: ns_print.c,v 1.5 2004/11/07 02:19:49 christos Exp $"); +__RCSID("$NetBSD: ns_print.c,v 1.6 2007/01/27 22:26:43 christos Exp $"); #endif #endif @@ -76,12 +76,11 @@ static int addtab(size_t len, size_t target, int spaced, /* Public. */ -/* - * int - * ns_sprintrr(handle, rr, name_ctx, origin, buf, buflen) +/*% * Convert an RR to presentation format. + * * return: - * Number of characters written to buf, or -1 (check errno). + *\li Number of characters written to buf, or -1 (check errno). */ int ns_sprintrr(const ns_msg *handle, const ns_rr *rr, @@ -97,13 +96,11 @@ ns_sprintrr(const ns_msg *handle, const ns_rr *rr, return (n); } -/* - * int - * ns_sprintrrf(msg, msglen, name, class, type, ttl, rdata, rdlen, - * name_ctx, origin, buf, buflen) +/*% * Convert the fields of an RR into presentation format. + * * return: - * Number of characters written to buf, or -1 (check errno). + *\li Number of characters written to buf, or -1 (check errno). */ int ns_sprintrrf(const u_char *msg, size_t msglen, @@ -657,10 +654,10 @@ ns_sprintrrf(const u_char *msg, size_t msglen, T(len = addname(msg, msglen, &rdata, origin, &buf, &buflen)); T(addstr(" ", (size_t)1, &buf, &buflen)); - rdata += 8; /* time */ + rdata += 8; /*%< time */ n = ns_get16(rdata); rdata += INT16SZ; - rdata += n; /* sig */ - n = ns_get16(rdata); rdata += INT16SZ; /* original id */ + rdata += n; /*%< sig */ + n = ns_get16(rdata); rdata += INT16SZ; /*%< original id */ sprintf(buf, "%d", ns_get16(rdata)); rdata += INT16SZ; addlen(strlen(buf), &buf, &buflen); @@ -717,8 +714,8 @@ ns_sprintrrf(const u_char *msg, size_t msglen, int n, m; char *p; - len = SPRINTF((tmp, "\\# %tu%s\t; %s", edata - rdata, - rdlen != 0 ? " (" : "", comment)); + len = SPRINTF((tmp, "\\# %u%s\t; %s", (unsigned)(edata - rdata), + rdlen != 0U ? " (" : "", comment)); T(addstr(tmp, (size_t)len, &buf, &buflen)); while (rdata < edata) { p = tmp; @@ -747,7 +744,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen, /* Private. */ -/* +/*% * size_t * prune_origin(name, origin) * Find out if the name is at or under the current origin. @@ -780,7 +777,7 @@ prune_origin(const char *name, const char *origin) { return (name - oname); } -/* +/*% * int * charstr(rdata, edata, buf, buflen) * Format a into the presentation buffer. @@ -836,7 +833,7 @@ addname(const u_char *msg, size_t msglen, n = dn_expand(msg, msg + msglen, *pp, *buf, (int)*buflen); if (n < 0) - goto enospc; /* Guess. */ + goto enospc; /*%< Guess. */ newlen = prune_origin(*buf, origin); if (**buf == '\0') { goto root; @@ -908,3 +905,5 @@ addtab(size_t len, size_t target, int spaced, char **buf, size_t *buflen) { } return (spaced); } + +/*! \file */ diff --git a/lib/libc/nameser/ns_samedomain.c b/lib/libc/nameser/ns_samedomain.c index 4222420b2f34..7bccebe03712 100644 --- a/lib/libc/nameser/ns_samedomain.c +++ b/lib/libc/nameser/ns_samedomain.c @@ -1,4 +1,4 @@ -/* $NetBSD: ns_samedomain.c,v 1.2 2004/05/20 20:35:05 christos Exp $ */ +/* $NetBSD: ns_samedomain.c,v 1.3 2007/01/27 22:26:43 christos Exp $ */ /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -20,9 +20,9 @@ #include #ifndef lint #ifdef notdef -static const char rcsid[] = "Id: ns_samedomain.c,v 1.1.2.2.4.2 2004/03/16 12:34:17 marka Exp"; +static const char rcsid[] = "Id: ns_samedomain.c,v 1.5.18.1 2005/04/27 05:01:09 sra Exp"; #else -__RCSID("$NetBSD: ns_samedomain.c,v 1.2 2004/05/20 20:35:05 christos Exp $"); +__RCSID("$NetBSD: ns_samedomain.c,v 1.3 2007/01/27 22:26:43 christos Exp $"); #endif #endif @@ -36,21 +36,22 @@ __RCSID("$NetBSD: ns_samedomain.c,v 1.2 2004/05/20 20:35:05 christos Exp $"); #include "port_after.h" #ifndef _LIBC -/* - * int - * ns_samedomain(a, b) +/*% * Check whether a name belongs to a domain. + * * Inputs: - * a - the domain whose ancestory is being verified - * b - the potential ancestor we're checking against + *\li a - the domain whose ancestory is being verified + *\li b - the potential ancestor we're checking against + * * Return: - * boolean - is a at or below b? + *\li boolean - is a at or below b? + * * Notes: - * Trailing dots are first removed from name and domain. + *\li Trailing dots are first removed from name and domain. * Always compare complete subdomains, not only whether the * domain name is the trailing string of the given name. * - * "host.foobar.top" lies in "foobar.top" and in "top" and in "" + *\li "host.foobar.top" lies in "foobar.top" and in "top" and in "" * but NOT in "bar.top" */ @@ -148,9 +149,7 @@ ns_samedomain(const char *a, const char *b) { return (strncasecmp(cp, b, lb) == 0); } -/* - * int - * ns_subdomain(a, b) +/*% * is "a" a subdomain of "b"? */ int @@ -159,30 +158,31 @@ ns_subdomain(const char *a, const char *b) { } #endif -/* - * int - * ns_makecanon(src, dst, dstsize) +/*% * make a canonical copy of domain name "src" + * * notes: + * \code * foo -> foo. * foo. -> foo. * foo.. -> foo. * foo\. -> foo\.. * foo\\. -> foo\\. + * \endcode */ int ns_makecanon(const char *src, char *dst, size_t dstsize) { size_t n = strlen(src); - if (n + sizeof "." > dstsize) { /* Note: sizeof == 2 */ + if (n + sizeof "." > dstsize) { /*%< Note: sizeof == 2 */ errno = EMSGSIZE; return (-1); } strcpy(dst, src); - while (n >= 1U && dst[n - 1] == '.') /* Ends in "." */ - if (n >= 2U && dst[n - 2] == '\\' && /* Ends in "\." */ - (n < 3U || dst[n - 3] != '\\')) /* But not "\\." */ + while (n >= 1U && dst[n - 1] == '.') /*%< Ends in "." */ + if (n >= 2U && dst[n - 2] == '\\' && /*%< Ends in "\." */ + (n < 3U || dst[n - 3] != '\\')) /*%< But not "\\." */ break; else dst[--n] = '\0'; @@ -191,14 +191,13 @@ ns_makecanon(const char *src, char *dst, size_t dstsize) { return (0); } -/* - * int - * ns_samename(a, b) +/*% * determine whether domain name "a" is the same as domain name "b" + * * return: - * -1 on error - * 0 if names differ - * 1 if names are the same + *\li -1 on error + *\li 0 if names differ + *\li 1 if names are the same */ int @@ -213,3 +212,5 @@ ns_samename(const char *a, const char *b) { else return (0); } + +/*! \file */ diff --git a/lib/libc/nameser/ns_ttl.c b/lib/libc/nameser/ns_ttl.c index 3919e33a2315..b2fc78e29036 100644 --- a/lib/libc/nameser/ns_ttl.c +++ b/lib/libc/nameser/ns_ttl.c @@ -1,4 +1,4 @@ -/* $NetBSD: ns_ttl.c,v 1.3 2006/10/15 16:14:08 christos Exp $ */ +/* $NetBSD: ns_ttl.c,v 1.4 2007/01/27 22:26:43 christos Exp $ */ /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -20,9 +20,9 @@ #include #ifndef lint #ifdef notdef -static const char rcsid[] = "Id: ns_ttl.c,v 1.1.206.1 2004/03/09 08:33:45 marka Exp"; +static const char rcsid[] = "Id: ns_ttl.c,v 1.2.18.2 2005/07/28 07:38:10 marka Exp"; #else -__RCSID("$NetBSD: ns_ttl.c,v 1.3 2006/10/15 16:14:08 christos Exp $"); +__RCSID("$NetBSD: ns_ttl.c,v 1.4 2007/01/27 22:26:43 christos Exp $"); #endif #endif @@ -141,7 +141,8 @@ ns_parse_ttl(const char *src, u_long *dst) { goto einval; else ttl += tmp; - } + } else if (!dirty) + goto einval; *dst = ttl; return (0); @@ -166,3 +167,5 @@ fmt1(int t, char s, char **buf, size_t *buflen) { *buflen -= len; return (0); } + +/*! \file */ diff --git a/lib/libc/net/base64.c b/lib/libc/net/base64.c index e6d1ecb11304..3c92ca4123bd 100644 --- a/lib/libc/net/base64.c +++ b/lib/libc/net/base64.c @@ -1,20 +1,20 @@ -/* $NetBSD: base64.c,v 1.8 2002/11/11 01:15:17 thorpej Exp $ */ +/* $NetBSD: base64.c,v 1.9 2007/01/27 22:26:44 christos Exp $ */ /* - * Copyright (c) 1996 by Internet Software Consortium. + * 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. */ /* @@ -44,12 +44,19 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: base64.c,v 1.8 2002/11/11 01:15:17 thorpej Exp $"); +#if 0 +static const char rcsid[] = "Id: base64.c,v 1.3.18.1 2005/04/27 05:01:05 sra Exp"; +#else +__RCSID("$NetBSD: base64.c,v 1.9 2007/01/27 22:26:44 christos Exp $"); +#endif #endif /* LIBC_SCCS and not lint */ +#include "port_before.h" + #include #include #include + #include #include #include @@ -58,13 +65,10 @@ __RCSID("$NetBSD: base64.c,v 1.8 2002/11/11 01:15:17 thorpej Exp $"); #include #include #include +#include +#include -#if defined(BSD) && (BSD >= 199103) && defined(AF_INET6) -# include -# include -#else -# include "../conf/portability.h" -#endif +#include "port_after.h" #define Assert(Cond) if (!(Cond)) abort() @@ -73,7 +77,7 @@ static const char Base64[] = static const char Pad64 = '='; /* (From RFC1521 and draft-ietf-dnssec-secext-03.txt) - The following encoding technique is taken from RFC 1521 by Borenstein + The following encoding technique is taken from RFC1521 by Borenstein and Freed. It is reproduced here in a slightly edited form for convenience. @@ -136,12 +140,7 @@ static const char Pad64 = '='; */ int -b64_ntop(src, srclength, target, targsize) - u_char const *src; - size_t srclength; - char *target; - size_t targsize; -{ +b64_ntop(u_char const *src, size_t srclength, char *target, size_t targsize) { size_t datalength = 0; u_char input[3]; u_char output[4]; @@ -150,7 +149,7 @@ b64_ntop(src, srclength, target, targsize) _DIAGASSERT(src != NULL); _DIAGASSERT(target != NULL); - while (2 < srclength) { + while (2U < srclength) { input[0] = *src++; input[1] = *src++; input[2] = *src++; @@ -176,7 +175,7 @@ b64_ntop(src, srclength, target, targsize) } /* Now we worry about padding. */ - if (0 != srclength) { + if (0U != srclength) { /* Get what's left. */ input[0] = input[1] = input[2] = '\0'; for (i = 0; i < srclength; i++) @@ -195,7 +194,7 @@ b64_ntop(src, srclength, target, targsize) return (-1); target[datalength++] = Base64[output[0]]; target[datalength++] = Base64[output[1]]; - if (srclength == 1) + if (srclength == 1U) target[datalength++] = Pad64; else target[datalength++] = Base64[output[2]]; @@ -203,7 +202,7 @@ b64_ntop(src, srclength, target, targsize) } if (datalength >= targsize) return (-1); - target[datalength] = '\0'; /* Returned value doesn't count \0. */ + target[datalength] = '\0'; /*%< Returned value doesn't count \\0. */ return (datalength); } @@ -230,20 +229,20 @@ b64_pton(src, target, targsize) tarindex = 0; while ((ch = (u_char) *src++) != '\0') { - if (isspace(ch)) /* Skip whitespace anywhere. */ + if (isspace(ch)) /*%< Skip whitespace anywhere. */ continue; if (ch == Pad64) break; pos = strchr(Base64, ch); - if (pos == 0) /* A non-base64 character. */ + if (pos == 0) /*%< A non-base64 character. */ return (-1); switch (state) { case 0: if (target) { - if (tarindex >= targsize) + if ((size_t)tarindex >= targsize) return (-1); target[tarindex] = (pos - Base64) << 2; } @@ -251,7 +250,7 @@ b64_pton(src, target, targsize) break; case 1: if (target) { - if (tarindex + 1 >= targsize) + if ((size_t)tarindex + 1 >= targsize) return (-1); target[tarindex] |= (u_int32_t)(pos - Base64) >> 4; @@ -263,7 +262,7 @@ b64_pton(src, target, targsize) break; case 2: if (target) { - if (tarindex + 1 >= targsize) + if ((size_t)tarindex + 1 >= targsize) return (-1); target[tarindex] |= (u_int32_t)(pos - Base64) >> 2; @@ -275,7 +274,7 @@ b64_pton(src, target, targsize) break; case 3: if (target) { - if (tarindex >= targsize) + if ((size_t)tarindex >= targsize) return (-1); target[tarindex] |= (pos - Base64); } @@ -292,14 +291,14 @@ b64_pton(src, target, targsize) * on a byte boundary, and/or with erroneous trailing characters. */ - if (ch == Pad64) { /* We got a pad char. */ - ch = *src++; /* Skip it, get next. */ + if (ch == Pad64) { /*%< We got a pad char. */ + ch = *src++; /*%< Skip it, get next. */ switch (state) { - case 0: /* Invalid = in first position */ - case 1: /* Invalid = in second position */ + case 0: /*%< Invalid = in first position */ + case 1: /*%< Invalid = in second position */ return (-1); - case 2: /* Valid, means one byte of info */ + case 2: /*%< Valid, means one byte of info */ /* Skip any number of spaces. */ for (; ch != '\0'; ch = (u_char) *src++) if (!isspace(ch)) @@ -307,11 +306,11 @@ b64_pton(src, target, targsize) /* Make sure there is another trailing = sign. */ if (ch != Pad64) return (-1); - ch = *src++; /* Skip the = */ + ch = *src++; /*%< Skip the = */ /* Fall through to "single trailing =" case. */ /* FALLTHROUGH */ - case 3: /* Valid, means two bytes of info */ + case 3: /*%< Valid, means two bytes of info */ /* * We know this char is an =. Is there anything but * whitespace after it? @@ -340,3 +339,5 @@ b64_pton(src, target, targsize) return (tarindex); } + +/*! \file */ diff --git a/lib/libc/net/gethnamaddr.c b/lib/libc/net/gethnamaddr.c deleted file mode 100644 index f7df159dc606..000000000000 --- a/lib/libc/net/gethnamaddr.c +++ /dev/null @@ -1,1441 +0,0 @@ -/* $NetBSD: gethnamaddr.c,v 1.71 2006/10/15 16:14:46 christos Exp $ */ - -/* - * ++Copyright++ 1985, 1988, 1993 - * - - * Copyright (c) 1985, 1988, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - - * Portions Copyright (c) 1993 by Digital Equipment Corporation. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies, and that - * the name of Digital Equipment Corporation not be used in advertising or - * publicity pertaining to distribution of the document or software without - * specific, written prior permission. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL - * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT - * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - * - - * --Copyright-- - */ - -#include -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93"; -static char rcsid[] = "Id: gethnamaddr.c,v 8.21 1997/06/01 20:34:37 vixie Exp "; -#else -__RCSID("$NetBSD: gethnamaddr.c,v 1.71 2006/10/15 16:14:46 christos Exp $"); -#endif -#endif /* LIBC_SCCS and not lint */ - -#if defined(_LIBC) -#include "namespace.h" -#endif -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#ifndef LOG_AUTH -# define LOG_AUTH 0 -#endif - -#define MULTI_PTRS_ARE_ALIASES 1 /* XXX - experimental */ - -#include -#include -#include - -#ifdef YP -#include -#include -#include -#endif - -#if defined(_LIBC) && defined(__weak_alias) -__weak_alias(gethostbyaddr,_gethostbyaddr) -__weak_alias(gethostbyname,_gethostbyname) -__weak_alias(gethostent,_gethostent) -#endif - -#define MAXALIASES 35 -#define MAXADDRS 35 - -static const char AskedForGot[] = - "gethostby*.getanswer: asked for \"%s\", got \"%s\""; - -static char *h_addr_ptrs[MAXADDRS + 1]; - -#ifdef YP -static char *__ypdomain; -#endif - -static struct hostent host; -static char *host_aliases[MAXALIASES]; -static char hostbuf[8*1024]; -static u_int32_t host_addr[16 / sizeof(u_int32_t)]; /* IPv4 or IPv6 */ -static FILE *hostf = NULL; -static int stayopen = 0; - -#define MAXPACKET (64*1024) - -typedef union { - HEADER hdr; - u_char buf[MAXPACKET]; -} querybuf; - -typedef union { - int32_t al; - char ac; -} align; - -#ifdef DEBUG -static void dprintf(const char *, res_state, ...) - __attribute__((__format__(__printf__, 1, 3))); -#endif -static struct hostent *getanswer(const querybuf *, int, const char *, int, - res_state); -static void map_v4v6_address(const char *, char *); -static void map_v4v6_hostent(struct hostent *, char **, char *); -static void addrsort(char **, int, res_state); - -void _sethtent(int); -void _endhtent(void); -struct hostent *_gethtent(void); -void ht_sethostent(int); -void ht_endhostent(void); -struct hostent *ht_gethostbyname(char *); -struct hostent *ht_gethostbyaddr(const char *, int, int); -void dns_service(void); -#undef dn_skipname -int dn_skipname(const u_char *, const u_char *); -int _gethtbyaddr(void *, void *, va_list); -int _gethtbyname(void *, void *, va_list); -struct hostent *_gethtbyname2(const char *, int); -int _dns_gethtbyaddr(void *, void *, va_list); -int _dns_gethtbyname(void *, void *, va_list); -#ifdef YP -struct hostent *_yphostent(char *, int); -int _yp_gethtbyaddr(void *, void *, va_list); -int _yp_gethtbyname(void *, void *, va_list); -#endif - -static struct hostent *gethostbyname_internal(const char *, int, res_state); - -static const ns_src default_dns_files[] = { - { NSSRC_FILES, NS_SUCCESS }, - { NSSRC_DNS, NS_SUCCESS }, - { 0, 0 } -}; - - -#ifdef DEBUG -static void -dprintf(const char *msg, res_state res, ...) -{ - _DIAGASSERT(msg != NULL); - - if (res->options & RES_DEBUG) { - int save = errno; - va_list ap; - - va_start (ap, res); - vprintf(msg, ap); - va_end (ap); - - errno = save; - } -} -#else -# define dprintf(msg, res, num) /*nada*/ -#endif - -#define BOUNDED_INCR(x) \ - do { \ - cp += (x); \ - if (cp > eom) { \ - h_errno = NO_RECOVERY; \ - return NULL; \ - } \ - } while (/*CONSTCOND*/0) - -#define BOUNDS_CHECK(ptr, count) \ - do { \ - if ((ptr) + (count) > eom) { \ - h_errno = NO_RECOVERY; \ - return NULL; \ - } \ - } while (/*CONSTCOND*/0) - -static struct hostent * -getanswer(const querybuf *answer, int anslen, const char *qname, int qtype, - res_state res) -{ - const HEADER *hp; - const u_char *cp; - int n; - const u_char *eom, *erdata; - char *bp, **ap, **hap, *ep; - int type, class, ancount, qdcount; - int haveanswer, had_error; - int toobig = 0; - char tbuf[MAXDNAME]; - const char *tname; - int (*name_ok)(const char *); - - _DIAGASSERT(answer != NULL); - _DIAGASSERT(qname != NULL); - - tname = qname; - host.h_name = NULL; - eom = answer->buf + anslen; - switch (qtype) { - case T_A: - case T_AAAA: - name_ok = res_hnok; - break; - case T_PTR: - name_ok = res_dnok; - break; - default: - return NULL; /* XXX should be abort(); */ - } - /* - * find first satisfactory answer - */ - hp = &answer->hdr; - ancount = ntohs(hp->ancount); - qdcount = ntohs(hp->qdcount); - bp = hostbuf; - ep = hostbuf + sizeof hostbuf; - cp = answer->buf; - BOUNDED_INCR(HFIXEDSZ); - if (qdcount != 1) { - h_errno = NO_RECOVERY; - return NULL; - } - n = dn_expand(answer->buf, eom, cp, bp, ep - bp); - if ((n < 0) || !(*name_ok)(bp)) { - h_errno = NO_RECOVERY; - return NULL; - } - BOUNDED_INCR(n + QFIXEDSZ); - if (qtype == T_A || qtype == T_AAAA) { - /* res_send() has already verified that the query name is the - * same as the one we sent; this just gets the expanded name - * (i.e., with the succeeding search-domain tacked on). - */ - n = strlen(bp) + 1; /* for the \0 */ - if (n >= MAXHOSTNAMELEN) { - h_errno = NO_RECOVERY; - return NULL; - } - host.h_name = bp; - bp += n; - /* The qname can be abbreviated, but h_name is now absolute. */ - qname = host.h_name; - } - ap = host_aliases; - *ap = NULL; - host.h_aliases = host_aliases; - hap = h_addr_ptrs; - *hap = NULL; - host.h_addr_list = h_addr_ptrs; - haveanswer = 0; - had_error = 0; - while (ancount-- > 0 && cp < eom && !had_error) { - n = dn_expand(answer->buf, eom, cp, bp, ep - bp); - if ((n < 0) || !(*name_ok)(bp)) { - had_error++; - continue; - } - cp += n; /* name */ - BOUNDS_CHECK(cp, 3 * INT16SZ + INT32SZ); - type = _getshort(cp); - cp += INT16SZ; /* type */ - class = _getshort(cp); - cp += INT16SZ + INT32SZ; /* class, TTL */ - n = _getshort(cp); - cp += INT16SZ; /* len */ - BOUNDS_CHECK(cp, n); - erdata = cp + n; - if (class != C_IN) { - /* XXX - debug? syslog? */ - cp += n; - continue; /* XXX - had_error++ ? */ - } - if ((qtype == T_A || qtype == T_AAAA) && type == T_CNAME) { - if (ap >= &host_aliases[MAXALIASES-1]) - continue; - n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf); - if ((n < 0) || !(*name_ok)(tbuf)) { - had_error++; - continue; - } - cp += n; - if (cp != erdata) { - h_errno = NO_RECOVERY; - return NULL; - } - /* Store alias. */ - *ap++ = bp; - n = strlen(bp) + 1; /* for the \0 */ - if (n >= MAXHOSTNAMELEN) { - had_error++; - continue; - } - bp += n; - /* Get canonical name. */ - n = strlen(tbuf) + 1; /* for the \0 */ - if (n > ep - bp || n >= MAXHOSTNAMELEN) { - had_error++; - continue; - } - strlcpy(bp, tbuf, (size_t)(ep - bp)); - host.h_name = bp; - bp += n; - continue; - } - if (qtype == T_PTR && type == T_CNAME) { - n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf); - if (n < 0 || !res_dnok(tbuf)) { - had_error++; - continue; - } - cp += n; - if (cp != erdata) { - h_errno = NO_RECOVERY; - return NULL; - } - /* Get canonical name. */ - n = strlen(tbuf) + 1; /* for the \0 */ - if (n > ep - bp || n >= MAXHOSTNAMELEN) { - had_error++; - continue; - } - strlcpy(bp, tbuf, (size_t)(ep - bp)); - tname = bp; - bp += n; - continue; - } - if (type != qtype) { - if (type != T_KEY && type != T_SIG) - syslog(LOG_NOTICE|LOG_AUTH, - "gethostby*.getanswer: asked for \"%s %s %s\", got type \"%s\"", - qname, p_class(C_IN), p_type(qtype), - p_type(type)); - cp += n; - continue; /* XXX - had_error++ ? */ - } - switch (type) { - case T_PTR: - if (strcasecmp(tname, bp) != 0) { - syslog(LOG_NOTICE|LOG_AUTH, - AskedForGot, qname, bp); - cp += n; - continue; /* XXX - had_error++ ? */ - } - n = dn_expand(answer->buf, eom, cp, bp, ep - bp); - if ((n < 0) || !res_hnok(bp)) { - had_error++; - break; - } -#if MULTI_PTRS_ARE_ALIASES - cp += n; - if (cp != erdata) { - h_errno = NO_RECOVERY; - return NULL; - } - if (!haveanswer) - host.h_name = bp; - else if (ap < &host_aliases[MAXALIASES-1]) - *ap++ = bp; - else - n = -1; - if (n != -1) { - n = strlen(bp) + 1; /* for the \0 */ - if (n >= MAXHOSTNAMELEN) { - had_error++; - break; - } - bp += n; - } - break; -#else - host.h_name = bp; - if (res->options & RES_USE_INET6) { - n = strlen(bp) + 1; /* for the \0 */ - if (n >= MAXHOSTNAMELEN) { - had_error++; - break; - } - bp += n; - map_v4v6_hostent(&host, &bp, ep); - } - h_errno = NETDB_SUCCESS; - return &host; -#endif - case T_A: - case T_AAAA: - if (strcasecmp(host.h_name, bp) != 0) { - syslog(LOG_NOTICE|LOG_AUTH, - AskedForGot, host.h_name, bp); - cp += n; - continue; /* XXX - had_error++ ? */ - } - if (n != host.h_length) { - cp += n; - continue; - } - if (type == T_AAAA) { - struct in6_addr in6; - memcpy(&in6, cp, IN6ADDRSZ); - if (IN6_IS_ADDR_V4MAPPED(&in6)) { - cp += n; - continue; - } - } - if (!haveanswer) { - int nn; - - host.h_name = bp; - nn = strlen(bp) + 1; /* for the \0 */ - bp += nn; - } - - bp += sizeof(align) - - (size_t)((u_long)bp % sizeof(align)); - - if (bp + n >= &hostbuf[sizeof hostbuf]) { - dprintf("size (%d) too big\n", res, n); - had_error++; - continue; - } - if (hap >= &h_addr_ptrs[MAXADDRS-1]) { - if (!toobig++) { - dprintf("Too many addresses (%d)\n", - res, MAXADDRS); - } - cp += n; - continue; - } - (void)memcpy(*hap++ = bp, cp, (size_t)n); - bp += n; - cp += n; - if (cp != erdata) { - h_errno = NO_RECOVERY; - return NULL; - } - break; - default: - abort(); - } - if (!had_error) - haveanswer++; - } - if (haveanswer) { - *ap = NULL; - *hap = NULL; - /* - * Note: we sort even if host can take only one address - * in its return structures - should give it the "best" - * address in that case, not some random one - */ - if (res->nsort && haveanswer > 1 && qtype == T_A) - addrsort(h_addr_ptrs, haveanswer, res); - if (!host.h_name) { - n = strlen(qname) + 1; /* for the \0 */ - if (n > ep - bp || n >= MAXHOSTNAMELEN) - goto no_recovery; - strlcpy(bp, qname, (size_t)(ep - bp)); - host.h_name = bp; - bp += n; - } - if (res->options & RES_USE_INET6) - map_v4v6_hostent(&host, &bp, ep); - h_errno = NETDB_SUCCESS; - return &host; - } - no_recovery: - h_errno = NO_RECOVERY; - return NULL; -} - -struct hostent * -gethostbyname(const char *name) -{ - struct hostent *hp; - res_state res = __res_get_state(); - - if (res == NULL) - return NULL; - - _DIAGASSERT(name != NULL); - - if (res->options & RES_USE_INET6) { - hp = gethostbyname_internal(name, AF_INET6, res); - if (hp) { - __res_put_state(res); - return hp; - } - } - hp = gethostbyname_internal(name, AF_INET, res); - __res_put_state(res); - return hp; -} - -struct hostent * -gethostbyname2(const char *name, int af) -{ - struct hostent *hp; - res_state res = __res_get_state(); - - if (res == NULL) - return NULL; - hp = gethostbyname_internal(name, af, res); - __res_put_state(res); - return hp; -} - -static struct hostent * -gethostbyname_internal(const char *name, int af, res_state res) -{ - const char *cp; - char *bp, *ep; - int size; - struct hostent *hp; - static const ns_dtab dtab[] = { - NS_FILES_CB(_gethtbyname, NULL) - { NSSRC_DNS, _dns_gethtbyname, NULL }, /* force -DHESIOD */ - NS_NIS_CB(_yp_gethtbyname, NULL) - NS_NULL_CB - }; - - _DIAGASSERT(name != NULL); - - switch (af) { - case AF_INET: - size = INADDRSZ; - break; - case AF_INET6: - size = IN6ADDRSZ; - break; - default: - h_errno = NETDB_INTERNAL; - errno = EAFNOSUPPORT; - return NULL; - } - - host.h_addrtype = af; - host.h_length = size; - - /* - * if there aren't any dots, it could be a user-level alias. - * this is also done in res_nquery() since we are not the only - * function that looks up host names. - */ - if (!strchr(name, '.') && (cp = __hostalias(name))) - name = cp; - - /* - * disallow names consisting only of digits/dots, unless - * they end in a dot. - */ - if (isdigit((u_char) name[0])) - for (cp = name;; ++cp) { - if (!*cp) { - if (*--cp == '.') - break; - /* - * All-numeric, no dot at the end. - * Fake up a hostent as if we'd actually - * done a lookup. - */ - if (inet_pton(af, name, - (char *)(void *)host_addr) <= 0) { - h_errno = HOST_NOT_FOUND; - return NULL; - } - strncpy(hostbuf, name, MAXDNAME); - hostbuf[MAXDNAME] = '\0'; - bp = hostbuf + MAXDNAME; - ep = hostbuf + sizeof hostbuf; - host.h_name = hostbuf; - host.h_aliases = host_aliases; - host_aliases[0] = NULL; - h_addr_ptrs[0] = (char *)(void *)host_addr; - h_addr_ptrs[1] = NULL; - host.h_addr_list = h_addr_ptrs; - if (res->options & RES_USE_INET6) - map_v4v6_hostent(&host, &bp, ep); - h_errno = NETDB_SUCCESS; - return &host; - } - if (!isdigit((u_char) *cp) && *cp != '.') - break; - } - if ((isxdigit((u_char) name[0]) && strchr(name, ':') != NULL) || - name[0] == ':') - for (cp = name;; ++cp) { - if (!*cp) { - if (*--cp == '.') - break; - /* - * All-IPv6-legal, no dot at the end. - * Fake up a hostent as if we'd actually - * done a lookup. - */ - if (inet_pton(af, name, - (char *)(void *)host_addr) <= 0) { - h_errno = HOST_NOT_FOUND; - return NULL; - } - strncpy(hostbuf, name, MAXDNAME); - hostbuf[MAXDNAME] = '\0'; - bp = hostbuf + MAXDNAME; - ep = hostbuf + sizeof hostbuf; - host.h_name = hostbuf; - host.h_aliases = host_aliases; - host_aliases[0] = NULL; - h_addr_ptrs[0] = (char *)(void *)host_addr; - h_addr_ptrs[1] = NULL; - host.h_addr_list = h_addr_ptrs; - h_errno = NETDB_SUCCESS; - return &host; - } - if (!isxdigit((u_char) *cp) && *cp != ':' && *cp != '.') - break; - } - - hp = NULL; - h_errno = NETDB_INTERNAL; - if (nsdispatch(&hp, dtab, NSDB_HOSTS, "gethostbyname", - default_dns_files, name, strlen(name), af) != NS_SUCCESS) - return NULL; - h_errno = NETDB_SUCCESS; - return hp; -} - -struct hostent * -gethostbyaddr(const char *addr, /* XXX should have been def'd as u_char! */ - socklen_t len, int af) -{ - const u_char *uaddr = (const u_char *)addr; - socklen_t size; - struct hostent *hp; - static const ns_dtab dtab[] = { - NS_FILES_CB(_gethtbyaddr, NULL) - { NSSRC_DNS, _dns_gethtbyaddr, NULL }, /* force -DHESIOD */ - NS_NIS_CB(_yp_gethtbyaddr, NULL) - NS_NULL_CB - }; - - _DIAGASSERT(addr != NULL); - - if (af == AF_INET6 && len == IN6ADDRSZ && - (IN6_IS_ADDR_LINKLOCAL((const struct in6_addr *)(const void *)uaddr) || - IN6_IS_ADDR_SITELOCAL((const struct in6_addr *)(const void *)uaddr))) { - h_errno = HOST_NOT_FOUND; - return NULL; - } - if (af == AF_INET6 && len == IN6ADDRSZ && - (IN6_IS_ADDR_V4MAPPED((const struct in6_addr *)(const void *)uaddr) || - IN6_IS_ADDR_V4COMPAT((const struct in6_addr *)(const void *)uaddr))) { - /* Unmap. */ - addr += IN6ADDRSZ - INADDRSZ; - uaddr += IN6ADDRSZ - INADDRSZ; - af = AF_INET; - len = INADDRSZ; - } - switch (af) { - case AF_INET: - size = INADDRSZ; - break; - case AF_INET6: - size = IN6ADDRSZ; - break; - default: - errno = EAFNOSUPPORT; - h_errno = NETDB_INTERNAL; - return NULL; - } - if (size != len) { - errno = EINVAL; - h_errno = NETDB_INTERNAL; - return NULL; - } - hp = NULL; - h_errno = NETDB_INTERNAL; - if (nsdispatch(&hp, dtab, NSDB_HOSTS, "gethostbyaddr", - default_dns_files, uaddr, len, af) != NS_SUCCESS) - return NULL; - h_errno = NETDB_SUCCESS; - return hp; -} - -void -_sethtent(int f) -{ - if (!hostf) - hostf = fopen(_PATH_HOSTS, "r" ); - else - rewind(hostf); - stayopen = f; -} - -void -_endhtent(void) -{ - if (hostf && !stayopen) { - (void) fclose(hostf); - hostf = NULL; - } -} - -struct hostent * -_gethtent(void) -{ - char *p; - char *cp, **q; - int af, len; - - if (!hostf && !(hostf = fopen(_PATH_HOSTS, "r" ))) { - h_errno = NETDB_INTERNAL; - return NULL; - } - again: - if (!(p = fgets(hostbuf, sizeof hostbuf, hostf))) { - h_errno = HOST_NOT_FOUND; - return NULL; - } - if (*p == '#') - goto again; - if (!(cp = strpbrk(p, "#\n"))) - goto again; - *cp = '\0'; - if (!(cp = strpbrk(p, " \t"))) - goto again; - *cp++ = '\0'; - if (inet_pton(AF_INET6, p, (char *)(void *)host_addr) > 0) { - af = AF_INET6; - len = IN6ADDRSZ; - } else if (inet_pton(AF_INET, p, (char *)(void *)host_addr) > 0) { - res_state res = __res_get_state(); - if (res == NULL) - return NULL; - if (res->options & RES_USE_INET6) { - map_v4v6_address((char *)(void *)host_addr, - (char *)(void *)host_addr); - af = AF_INET6; - len = IN6ADDRSZ; - } else { - af = AF_INET; - len = INADDRSZ; - } - __res_put_state(res); - } else { - goto again; - } - /* if this is not something we're looking for, skip it. */ - if (host.h_addrtype != 0 && host.h_addrtype != af) - goto again; - if (host.h_length != 0 && host.h_length != len) - goto again; - h_addr_ptrs[0] = (char *)(void *)host_addr; - h_addr_ptrs[1] = NULL; - host.h_addr_list = h_addr_ptrs; - host.h_length = len; - host.h_addrtype = af; - while (*cp == ' ' || *cp == '\t') - cp++; - host.h_name = cp; - q = host.h_aliases = host_aliases; - if ((cp = strpbrk(cp, " \t")) != NULL) - *cp++ = '\0'; - while (cp && *cp) { - if (*cp == ' ' || *cp == '\t') { - cp++; - continue; - } - if (q < &host_aliases[MAXALIASES - 1]) - *q++ = cp; - if ((cp = strpbrk(cp, " \t")) != NULL) - *cp++ = '\0'; - } - *q = NULL; - h_errno = NETDB_SUCCESS; - return &host; -} - -/*ARGSUSED*/ -int -_gethtbyname(void *rv, void *cb_data, va_list ap) -{ - struct hostent *hp; - const char *name; - int af; - - _DIAGASSERT(rv != NULL); - - name = va_arg(ap, char *); - /* NOSTRICT skip len */(void)va_arg(ap, int); - af = va_arg(ap, int); - - hp = NULL; -#if 0 - { - res_state res = __res_get_state(); - if (res == NULL) - return NS_NOTFOUND; - if (res->options & RES_USE_INET6) - hp = _gethtbyname2(name, AF_INET6); - if (hp==NULL) - hp = _gethtbyname2(name, AF_INET); - __res_put_state(res); - } -#else - hp = _gethtbyname2(name, af); -#endif - *((struct hostent **)rv) = hp; - if (hp == NULL) { - h_errno = HOST_NOT_FOUND; - return NS_NOTFOUND; - } - return NS_SUCCESS; -} - -struct hostent * -_gethtbyname2(const char *name, int af) -{ - struct hostent *p; - char *tmpbuf, *ptr, **cp; - int num; - size_t len; - - _DIAGASSERT(name != NULL); - - _sethtent(stayopen); - ptr = tmpbuf = NULL; - num = 0; - while ((p = _gethtent()) != NULL && num < MAXADDRS) { - if (p->h_addrtype != af) - continue; - if (strcasecmp(p->h_name, name) != 0) { - for (cp = p->h_aliases; *cp != NULL; cp++) - if (strcasecmp(*cp, name) == 0) - break; - if (*cp == NULL) continue; - } - - if (num == 0) { - size_t bufsize; - char *src; - - bufsize = strlen(p->h_name) + 2 + - MAXADDRS * p->h_length + - ALIGNBYTES; - for (cp = p->h_aliases; *cp != NULL; cp++) - bufsize += strlen(*cp) + 1; - - if ((tmpbuf = malloc(bufsize)) == NULL) { - h_errno = NETDB_INTERNAL; - return NULL; - } - - ptr = tmpbuf; - src = p->h_name; - while ((*ptr++ = *src++) != '\0'); - for (cp = p->h_aliases; *cp != NULL; cp++) { - src = *cp; - while ((*ptr++ = *src++) != '\0'); - } - *ptr++ = '\0'; - - ptr = (char *)(void *)ALIGN(ptr); - } - - (void)memcpy(ptr, p->h_addr_list[0], (size_t)p->h_length); - ptr += p->h_length; - num++; - } - _endhtent(); - if (num == 0) return NULL; - - len = ptr - tmpbuf; - if (len > (sizeof(hostbuf) - ALIGNBYTES)) { - free(tmpbuf); - errno = ENOSPC; - h_errno = NETDB_INTERNAL; - return NULL; - } - ptr = memcpy((void *)ALIGN(hostbuf), tmpbuf, len); - free(tmpbuf); - - host.h_name = ptr; - while (*ptr++); - - cp = host_aliases; - while (*ptr) { - *cp++ = ptr; - while (*ptr++); - } - ptr++; - *cp = NULL; - - ptr = (char *)(void *)ALIGN(ptr); - cp = h_addr_ptrs; - while (num--) { - *cp++ = ptr; - ptr += host.h_length; - } - *cp = NULL; - - return &host; -} - -/*ARGSUSED*/ -int -_gethtbyaddr(void *rv, void *cb_data, va_list ap) -{ - struct hostent *p; - const unsigned char *addr; - int len, af; - - _DIAGASSERT(rv != NULL); - - addr = va_arg(ap, unsigned char *); - len = va_arg(ap, int); - af = va_arg(ap, int); - - host.h_length = len; - host.h_addrtype = af; - - _sethtent(stayopen); - while ((p = _gethtent()) != NULL) - if (p->h_addrtype == af && !memcmp(p->h_addr, addr, - (size_t)len)) - break; - _endhtent(); - *((struct hostent **)rv) = p; - if (p==NULL) { - h_errno = HOST_NOT_FOUND; - return NS_NOTFOUND; - } - return NS_SUCCESS; -} - -static void -map_v4v6_address(const char *src, char *dst) -{ - u_char *p = (u_char *)dst; - char tmp[INADDRSZ]; - int i; - - _DIAGASSERT(src != NULL); - _DIAGASSERT(dst != NULL); - - /* Stash a temporary copy so our caller can update in place. */ - (void)memcpy(tmp, src, INADDRSZ); - /* Mark this ipv6 addr as a mapped ipv4. */ - for (i = 0; i < 10; i++) - *p++ = 0x00; - *p++ = 0xff; - *p++ = 0xff; - /* Retrieve the saved copy and we're done. */ - (void)memcpy((void *)p, tmp, INADDRSZ); -} - -static void -map_v4v6_hostent(struct hostent *hp, char **bpp, char *ep) -{ - char **ap; - - _DIAGASSERT(hp != NULL); - _DIAGASSERT(bpp != NULL); - _DIAGASSERT(ep != NULL); - - if (hp->h_addrtype != AF_INET || hp->h_length != INADDRSZ) - return; - hp->h_addrtype = AF_INET6; - hp->h_length = IN6ADDRSZ; - for (ap = hp->h_addr_list; *ap; ap++) { - int i = sizeof(align) - (size_t)((u_long)*bpp % sizeof(align)); - - if (ep - *bpp < (i + IN6ADDRSZ)) { - /* Out of memory. Truncate address list here. XXX */ - *ap = NULL; - return; - } - *bpp += i; - map_v4v6_address(*ap, *bpp); - *ap = *bpp; - *bpp += IN6ADDRSZ; - } -} - -static void -addrsort(char **ap, int num, res_state res) -{ - int i, j; - char **p; - short aval[MAXADDRS]; - int needsort = 0; - - _DIAGASSERT(ap != NULL); - - p = ap; - for (i = 0; i < num; i++, p++) { - for (j = 0 ; (unsigned)j < res->nsort; j++) - if (res->sort_list[j].addr.s_addr == - (((struct in_addr *)(void *)(*p))->s_addr & - res->sort_list[j].mask)) - break; - aval[i] = j; - if (needsort == 0 && i > 0 && j < aval[i-1]) - needsort = i; - } - if (!needsort) - return; - - while (needsort < num) { - for (j = needsort - 1; j >= 0; j--) { - if (aval[j] > aval[j+1]) { - char *hp; - - i = aval[j]; - aval[j] = aval[j+1]; - aval[j+1] = i; - - hp = ap[j]; - ap[j] = ap[j+1]; - ap[j+1] = hp; - } else - break; - } - needsort++; - } -} - -struct hostent * -gethostent(void) -{ - host.h_addrtype = 0; - host.h_length = 0; - return _gethtent(); -} - -/*ARGSUSED*/ -int -_dns_gethtbyname(void *rv, void *cb_data, va_list ap) -{ - querybuf *buf; - int n, type; - struct hostent *hp; - const char *name; - int af; - res_state res; - - _DIAGASSERT(rv != NULL); - - name = va_arg(ap, char *); - /* NOSTRICT skip len */(void)va_arg(ap, int); - af = va_arg(ap, int); - - switch (af) { - case AF_INET: - type = T_A; - break; - case AF_INET6: - type = T_AAAA; - break; - default: - return NS_UNAVAIL; - } - buf = malloc(sizeof(*buf)); - if (buf == NULL) { - h_errno = NETDB_INTERNAL; - return NS_NOTFOUND; - } - res = __res_get_state(); - if (res == NULL) { - free(buf); - return NS_NOTFOUND; - } - n = res_nsearch(res, name, C_IN, type, buf->buf, sizeof(buf->buf)); - if (n < 0) { - free(buf); - dprintf("res_nsearch failed (%d)\n", res, n); - __res_put_state(res); - return NS_NOTFOUND; - } - hp = getanswer(buf, n, name, type, res); - free(buf); - __res_put_state(res); - if (hp == NULL) - switch (h_errno) { - case HOST_NOT_FOUND: - return NS_NOTFOUND; - case TRY_AGAIN: - return NS_TRYAGAIN; - default: - return NS_UNAVAIL; - } - *((struct hostent **)rv) = hp; - return NS_SUCCESS; -} - -/*ARGSUSED*/ -int -_dns_gethtbyaddr(void *rv, void *cb_data, va_list ap) -{ - char qbuf[MAXDNAME + 1], *qp, *ep; - int n; - querybuf *buf; - struct hostent *hp; - const unsigned char *uaddr; - int len, af, advance; - res_state res; - - _DIAGASSERT(rv != NULL); - - uaddr = va_arg(ap, unsigned char *); - len = va_arg(ap, int); - af = va_arg(ap, int); - - switch (af) { - case AF_INET: - (void)snprintf(qbuf, sizeof(qbuf), "%u.%u.%u.%u.in-addr.arpa", - (uaddr[3] & 0xff), (uaddr[2] & 0xff), - (uaddr[1] & 0xff), (uaddr[0] & 0xff)); - break; - - case AF_INET6: - qp = qbuf; - ep = qbuf + sizeof(qbuf) - 1; - for (n = IN6ADDRSZ - 1; n >= 0; n--) { - advance = snprintf(qp, (size_t)(ep - qp), "%x.%x.", - uaddr[n] & 0xf, - ((unsigned int)uaddr[n] >> 4) & 0xf); - if (advance > 0 && qp + advance < ep) - qp += advance; - else { - h_errno = NETDB_INTERNAL; - return NS_NOTFOUND; - } - } - if (strlcat(qbuf, "ip6.arpa", sizeof(qbuf)) >= sizeof(qbuf)) { - h_errno = NETDB_INTERNAL; - return NS_NOTFOUND; - } - break; - default: - abort(); - } - - buf = malloc(sizeof(*buf)); - if (buf == NULL) { - h_errno = NETDB_INTERNAL; - return NS_NOTFOUND; - } - res = __res_get_state(); - if (res == NULL) { - free(buf); - return NS_NOTFOUND; - } - n = res_nquery(res, qbuf, C_IN, T_PTR, buf->buf, sizeof(buf->buf)); - if (n < 0) { - free(buf); - dprintf("res_nquery failed (%d)\n", res, n); - __res_put_state(res); - return NS_NOTFOUND; - } - hp = getanswer(buf, n, qbuf, T_PTR, res); - free(buf); - if (hp == NULL) { - __res_put_state(res); - switch (h_errno) { - case HOST_NOT_FOUND: - return NS_NOTFOUND; - case TRY_AGAIN: - return NS_TRYAGAIN; - default: - return NS_UNAVAIL; - } - } - hp->h_addrtype = af; - hp->h_length = len; - (void)memcpy(host_addr, uaddr, (size_t)len); - h_addr_ptrs[0] = (char *)(void *)host_addr; - h_addr_ptrs[1] = NULL; - if (af == AF_INET && (res->options & RES_USE_INET6)) { - map_v4v6_address((char *)(void *)host_addr, - (char *)(void *)host_addr); - hp->h_addrtype = AF_INET6; - hp->h_length = IN6ADDRSZ; - } - - __res_put_state(res); - *((struct hostent **)rv) = hp; - h_errno = NETDB_SUCCESS; - return NS_SUCCESS; -} - -#ifdef YP -/*ARGSUSED*/ -struct hostent * -_yphostent(char *line, int af) -{ - static struct in_addr host_addrs[MAXADDRS]; - static struct in6_addr host6_addrs[MAXADDRS]; - char *p = line; - char *cp, **q; - char **hap; - int addrok; - int more; - size_t naddrs; - - _DIAGASSERT(line != NULL); - - host.h_name = NULL; - host.h_addr_list = h_addr_ptrs; - host.h_addrtype = af; - switch (af) { - case AF_INET: - host.h_length = INADDRSZ; - break; - case AF_INET6: - host.h_length = IN6ADDRSZ; - break; - default: - return NULL; - } - hap = h_addr_ptrs; - q = host.h_aliases = host_aliases; - naddrs = 0; - -nextline: - /* check for host_addrs overflow */ - if (naddrs >= sizeof(host_addrs) / sizeof(host_addrs[0])) - goto done; - if (naddrs >= sizeof(host6_addrs) / sizeof(host6_addrs[0])) - goto done; - - more = 0; - cp = strpbrk(p, " \t"); - if (cp == NULL) - goto done; - *cp++ = '\0'; - - /* p has should have an address */ - addrok = 0; - switch (af) { - case AF_INET: - addrok = inet_aton(p, &host_addrs[naddrs]); - break; - case AF_INET6: - addrok = inet_pton(af, p, &host6_addrs[naddrs]); - break; - } - if (addrok != 1) { - /* skip to the next line */ - while (cp && *cp) { - if (*cp == '\n') { - cp++; - goto nextline; - } - cp++; - } - - goto done; - } - - switch (af) { - case AF_INET: - *hap++ = (char *)(void *)&host_addrs[naddrs++]; - break; - case AF_INET6: - *hap++ = (char *)(void *)&host6_addrs[naddrs++]; - break; - } - - while (*cp == ' ' || *cp == '\t') - cp++; - p = cp; - cp = strpbrk(p, " \t\n"); - if (cp != NULL) { - if (*cp == '\n') - more = 1; - *cp++ = '\0'; - } - if (!host.h_name) - host.h_name = p; - else if (strcmp(host.h_name, p)==0) - ; - else if (q < &host_aliases[MAXALIASES - 1]) - *q++ = p; - p = cp; - if (more) - goto nextline; - - while (cp && *cp) { - if (*cp == ' ' || *cp == '\t') { - cp++; - continue; - } - if (*cp == '\n') { - cp++; - goto nextline; - } - if (q < &host_aliases[MAXALIASES - 1]) - *q++ = cp; - cp = strpbrk(cp, " \t"); - if (cp != NULL) - *cp++ = '\0'; - } - -done: - if (host.h_name == NULL) - return NULL; - *q = NULL; - *hap = NULL; - return &host; -} - -/*ARGSUSED*/ -int -_yp_gethtbyaddr(void *rv, void *cb_data, va_list ap) -{ - struct hostent *hp = NULL; - static char *__ypcurrent; - int __ypcurrentlen, r; - char name[INET6_ADDRSTRLEN]; /* XXX enough? */ - const unsigned char *uaddr; - int af; - const char *map; - - _DIAGASSERT(rv != NULL); - - uaddr = va_arg(ap, unsigned char *); - /* NOSTRICT skip len */(void)va_arg(ap, int); - af = va_arg(ap, int); - - if (!__ypdomain) { - if (_yp_check(&__ypdomain) == 0) - return NS_UNAVAIL; - } - /* - * XXX unfortunately, we cannot support IPv6 extended scoped address - * notation here. gethostbyaddr() is not scope-aware. too bad. - */ - if (inet_ntop(af, uaddr, name, sizeof(name)) == NULL) - return NS_UNAVAIL; - if (__ypcurrent) - free(__ypcurrent); - __ypcurrent = NULL; - switch (af) { - case AF_INET: - map = "hosts.byaddr"; - break; - default: - map = "ipnodes.byaddr"; - break; - } - r = yp_match(__ypdomain, map, name, - (int)strlen(name), &__ypcurrent, &__ypcurrentlen); - if (r == 0) - hp = _yphostent(__ypcurrent, af); - if (hp == NULL) { - h_errno = HOST_NOT_FOUND; - return NS_NOTFOUND; - } - *((struct hostent **)rv) = hp; - return NS_SUCCESS; -} - -/*ARGSUSED*/ -int -_yp_gethtbyname(void *rv, void *cb_data, va_list ap) -{ - struct hostent *hp = NULL; - static char *__ypcurrent; - int __ypcurrentlen, r; - const char *name; - int af; - const char *map; - - _DIAGASSERT(rv != NULL); - - name = va_arg(ap, char *); - /* NOSTRICT skip len */(void)va_arg(ap, int); - af = va_arg(ap, int); - - if (!__ypdomain) { - if (_yp_check(&__ypdomain) == 0) - return NS_UNAVAIL; - } - if (__ypcurrent) - free(__ypcurrent); - __ypcurrent = NULL; - switch (af) { - case AF_INET: - map = "hosts.byname"; - break; - default: - map = "ipnodes.byname"; - break; - } - r = yp_match(__ypdomain, map, name, - (int)strlen(name), &__ypcurrent, &__ypcurrentlen); - if (r == 0) - hp = _yphostent(__ypcurrent, af); - if (hp == NULL) { - h_errno = HOST_NOT_FOUND; - return NS_NOTFOUND; - } - *((struct hostent **)rv) = hp; - return NS_SUCCESS; -} -#endif diff --git a/lib/libc/net/getnetent.c b/lib/libc/net/getnetent.c deleted file mode 100644 index e6f492f6059e..000000000000 --- a/lib/libc/net/getnetent.c +++ /dev/null @@ -1,170 +0,0 @@ -/* $NetBSD: getnetent.c,v 1.16 2004/05/08 18:52:15 kleink Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * Portions Copyright (c) 1993 Carlos Leandro and Rui Salgueiro - * Dep. Matematica Universidade de Coimbra, Portugal, Europe - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * from getnetent.c 1.1 (Coimbra) 93/06/02 - */ - -#include -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)getnetent.c 8.1 (Berkeley) 6/4/93"; -static char rcsid[] = "Id: getnetent.c,v 8.4 1997/06/01 20:34:37 vixie Exp "; -#else -__RCSID("$NetBSD: getnetent.c,v 1.16 2004/05/08 18:52:15 kleink Exp $"); -#endif -#endif /* LIBC_SCCS and not lint */ - -#include "namespace.h" -#include -#include -#include -#include -#include -#include -#include - -#ifdef __weak_alias -__weak_alias(endnetent,_endnetent) -__weak_alias(getnetent,_getnetent) -__weak_alias(setnetent,_setnetent) -#endif - -#define MAXALIASES 35 - -static FILE *netf; -static char line[BUFSIZ+1]; -static struct netent net; -static char *net_aliases[MAXALIASES]; -int _net_stayopen; - -static void __setnetent __P((int)); -static void __endnetent __P((void)); - -void -setnetent(stayopen) - int stayopen; -{ - - sethostent(stayopen); - __setnetent(stayopen); -} - -void -endnetent() -{ - - endhostent(); - __endnetent(); -} - -static void -__setnetent(f) - int f; -{ - - if (netf == NULL) - netf = fopen(_PATH_NETWORKS, "r" ); - else - rewind(netf); - _net_stayopen |= f; -} - -static void -__endnetent() -{ - - if (netf) { - fclose(netf); - netf = NULL; - } - _net_stayopen = 0; -} - -struct netent * -getnetent() -{ - char *p; - register char *cp, **q; - - if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "r" )) == NULL) - return (NULL); -#if (defined(__sparc__) && defined(_LP64)) || \ - defined(__alpha__) || \ - (defined(__i386__) && defined(_LP64)) || \ - (defined(__sh__) && defined(_LP64)) - net.__n_pad0 = 0; -#endif -again: - p = fgets(line, sizeof line, netf); - if (p == NULL) - return (NULL); - if (*p == '#') - goto again; - cp = strpbrk(p, "#\n"); - if (cp == NULL) - goto again; - *cp = '\0'; - net.n_name = p; - cp = strpbrk(p, " \t"); - if (cp == NULL) - goto again; - *cp++ = '\0'; - while (*cp == ' ' || *cp == '\t') - cp++; - p = strpbrk(cp, " \t"); - if (p != NULL) - *p++ = '\0'; - net.n_net = inet_network(cp); - net.n_addrtype = AF_INET; - q = net.n_aliases = net_aliases; - if (p != NULL) { - cp = p; - while (cp && *cp) { - if (*cp == ' ' || *cp == '\t') { - cp++; - continue; - } - if (q < &net_aliases[MAXALIASES - 1]) - *q++ = cp; - cp = strpbrk(cp, " \t"); - if (cp != NULL) - *cp++ = '\0'; - } - } - *q = NULL; - return (&net); -} diff --git a/lib/libc/net/getnetnamadr.c b/lib/libc/net/getnetnamadr.c deleted file mode 100644 index 1a6c2719e6e7..000000000000 --- a/lib/libc/net/getnetnamadr.c +++ /dev/null @@ -1,615 +0,0 @@ -/* $NetBSD: getnetnamadr.c,v 1.35 2006/10/15 16:14:46 christos Exp $ */ - -/* Copyright (c) 1993 Carlos Leandro and Rui Salgueiro - * Dep. Matematica Universidade de Coimbra, Portugal, Europe - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - */ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)getnetbyaddr.c 8.1 (Berkeley) 6/4/93"; -static char sccsid_[] = "from getnetnamadr.c 1.4 (Coimbra) 93/06/03"; -static char rcsid[] = "Id: getnetnamadr.c,v 8.8 1997/06/01 20:34:37 vixie Exp "; -#else -__RCSID("$NetBSD: getnetnamadr.c,v 1.35 2006/10/15 16:14:46 christos Exp $"); -#endif -#endif /* LIBC_SCCS and not lint */ - -#include "namespace.h" -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef YP -#include -#include -#include -#endif - -#ifdef __weak_alias -__weak_alias(getnetbyaddr,_getnetbyaddr) -__weak_alias(getnetbyname,_getnetbyname) -#endif - -extern int _net_stayopen; - -#define BYADDR 0 -#define BYNAME 1 -#define MAXALIASES 35 - -#define MAXPACKET (64*1024) - -typedef union { - HEADER hdr; - u_char buf[MAXPACKET]; -} querybuf; - -typedef union { - long al; - char ac; -} align; - -#ifdef YP -static char *__ypdomain; -static char *__ypcurrent; -static int __ypcurrentlen; -#endif - -static struct netent net_entry; -static char *net_aliases[MAXALIASES]; - -static struct netent *getnetanswer(querybuf *, int, int); -int _files_getnetbyaddr(void *, void *, va_list); -int _files_getnetbyname(void *, void *, va_list); -int _dns_getnetbyaddr(void *, void *, va_list); -int _dns_getnetbyname(void *, void *, va_list); -#ifdef YP -int _yp_getnetbyaddr(void *, void *, va_list); -int _yp_getnetbyname(void *, void *, va_list); -struct netent *_ypnetent(char *); -#endif - -static struct netent * -getnetanswer(querybuf *answer, int anslen, int net_i) -{ - HEADER *hp; - u_char *cp; - int n; - u_char *eom; - int type, class, ancount, qdcount, haveanswer, i, nchar; - char aux1[MAXDNAME], aux2[MAXDNAME], ans[MAXDNAME]; - char *in, *st, *pauxt, *bp, **ap; - char *paux1 = &aux1[0], *paux2 = &aux2[0], *ep; - static char netbuf[PACKETSZ]; - - _DIAGASSERT(answer != NULL); - - /* - * find first satisfactory answer - * - * answer --> +------------+ ( MESSAGE ) - * | Header | - * +------------+ - * | Question | the question for the name server - * +------------+ - * | Answer | RRs answering the question - * +------------+ - * | Authority | RRs pointing toward an authority - * | Additional | RRs holding additional information - * +------------+ - */ - eom = answer->buf + anslen; - hp = &answer->hdr; - ancount = ntohs(hp->ancount); /* #/records in the answer section */ - qdcount = ntohs(hp->qdcount); /* #/entries in the question section */ - bp = netbuf; - ep = netbuf + sizeof(netbuf); - cp = answer->buf + HFIXEDSZ; - if (!qdcount) { - if (hp->aa) - h_errno = HOST_NOT_FOUND; - else - h_errno = TRY_AGAIN; - return NULL; - } - while (qdcount-- > 0) { - n = __dn_skipname(cp, eom); - if (n < 0 || (cp + n + QFIXEDSZ) > eom) { - h_errno = NO_RECOVERY; - return(NULL); - } - cp += n + QFIXEDSZ; - } - ap = net_aliases; - *ap = NULL; - net_entry.n_aliases = net_aliases; - haveanswer = 0; - while (--ancount >= 0 && cp < eom) { - n = dn_expand(answer->buf, eom, cp, bp, ep - bp); - if ((n < 0) || !res_dnok(bp)) - break; - cp += n; - ans[0] = '\0'; - (void)strlcpy(ans, bp, sizeof(ans)); - GETSHORT(type, cp); - GETSHORT(class, cp); - cp += INT32SZ; /* TTL */ - GETSHORT(n, cp); - if (class == C_IN && type == T_PTR) { - n = dn_expand(answer->buf, eom, cp, bp, ep - bp); - if ((n < 0) || !res_hnok(bp)) { - cp += n; - return NULL; - } - cp += n; - *ap++ = bp; - bp += strlen(bp) + 1; - net_entry.n_addrtype = - (class == C_IN) ? AF_INET : AF_UNSPEC; - haveanswer++; - } - } - if (haveanswer) { - *ap = NULL; - switch (net_i) { - case BYADDR: - net_entry.n_name = *net_entry.n_aliases; - net_entry.n_net = 0L; - break; - case BYNAME: - ap = net_entry.n_aliases; - next_alias: - in = *ap++; - if (in == NULL) { - h_errno = HOST_NOT_FOUND; - return NULL; - } - net_entry.n_name = ans; - aux2[0] = '\0'; - for (i = 0; i < 4; i++) { - for (st = in, nchar = 0; - isdigit((unsigned char)*st); - st++, nchar++) - ; - if (*st != '.' || nchar == 0 || nchar > 3) - goto next_alias; - if (i != 0) - nchar++; - (void)strlcpy(paux1, in, (size_t)nchar); - paux1[nchar] = '\0'; - pauxt = paux2; - paux2 = strcat(paux1, paux2); - paux1 = pauxt; - in = ++st; - } - if (strcasecmp(in, "IN-ADDR.ARPA") != 0) - goto next_alias; - net_entry.n_net = inet_network(paux2); - break; - } - net_entry.n_aliases++; -#if (defined(__sparc__) && defined(_LP64)) || \ - defined(__alpha__) || \ - (defined(__i386__) && defined(_LP64)) || \ - (defined(__sh__) && defined(_LP64)) - net_entry.__n_pad0 = 0; -#endif - return &net_entry; - } - h_errno = TRY_AGAIN; - return NULL; -} - -/*ARGSUSED*/ -int -_files_getnetbyaddr(void *rv, void *cb_data, va_list ap) -{ - struct netent *p; - uint32_t net; - int type; - - _DIAGASSERT(rv != NULL); - - net = va_arg(ap, uint32_t); - type = va_arg(ap, int); - - setnetent(_net_stayopen); - while ((p = getnetent()) != NULL) - if (p->n_addrtype == type && p->n_net == net) - break; - if (!_net_stayopen) - endnetent(); - *((struct netent **)rv) = p; - if (p==NULL) { - h_errno = HOST_NOT_FOUND; - return NS_NOTFOUND; - } - return NS_SUCCESS; -} - -/*ARGSUSED*/ -int -_dns_getnetbyaddr(void *rv, void *cb_data, va_list ap) -{ - unsigned int netbr[4]; - int nn, anslen; - querybuf *buf; - char qbuf[MAXDNAME]; - uint32_t net2; - struct netent *np; - uint32_t net; - int type; - res_state res; - - _DIAGASSERT(rv != NULL); - - net = va_arg(ap, uint32_t); - type = va_arg(ap, int); - - if (type != AF_INET) - return NS_UNAVAIL; - - for (nn = 4, net2 = net; net2; net2 >>= 8) - netbr[--nn] = (unsigned int)(net2 & 0xff); - switch (nn) { - default: - return NS_UNAVAIL; - case 3: /* Class A */ - snprintf(qbuf, sizeof(qbuf), "0.0.0.%u.in-addr.arpa", netbr[3]); - break; - case 2: /* Class B */ - snprintf(qbuf, sizeof(qbuf), "0.0.%u.%u.in-addr.arpa", - netbr[3], netbr[2]); - break; - case 1: /* Class C */ - snprintf(qbuf, sizeof(qbuf), "0.%u.%u.%u.in-addr.arpa", - netbr[3], netbr[2], netbr[1]); - break; - case 0: /* Class D - E */ - snprintf(qbuf, sizeof(qbuf), "%u.%u.%u.%u.in-addr.arpa", - netbr[3], netbr[2], netbr[1], netbr[0]); - break; - } - buf = malloc(sizeof(*buf)); - if (buf == NULL) { - h_errno = NETDB_INTERNAL; - return NS_NOTFOUND; - } - res = __res_get_state(); - if (res == NULL) - return NS_NOTFOUND; - anslen = res_nquery(res, qbuf, C_IN, T_PTR, buf->buf, sizeof(buf->buf)); - if (anslen < 0) { - free(buf); -#ifdef DEBUG - if (res->options & RES_DEBUG) - printf("res_query failed\n"); -#endif - __res_put_state(res); - return NS_NOTFOUND; - } - __res_put_state(res); - np = getnetanswer(buf, anslen, BYADDR); - free(buf); - if (np) { - /* maybe net should be unsigned? */ - uint32_t u_net = net; - - /* Strip trailing zeros */ - while ((u_net & 0xff) == 0 && u_net != 0) - u_net >>= 8; - np->n_net = u_net; - } - *((struct netent **)rv) = np; - if (np == NULL) { - h_errno = HOST_NOT_FOUND; - return NS_NOTFOUND; - } - return NS_SUCCESS; -} - - -struct netent * -getnetbyaddr(uint32_t net, int net_type) -{ - struct netent *np; - static const ns_dtab dtab[] = { - NS_FILES_CB(_files_getnetbyaddr, NULL) - { NSSRC_DNS, _dns_getnetbyaddr, NULL }, /* force -DHESIOD */ - NS_NIS_CB(_yp_getnetbyaddr, NULL) - NS_NULL_CB - }; - - np = NULL; - h_errno = NETDB_INTERNAL; - if (nsdispatch(&np, dtab, NSDB_NETWORKS, "getnetbyaddr", __nsdefaultsrc, - net, net_type) != NS_SUCCESS) - return NULL; - h_errno = NETDB_SUCCESS; - return np; -} - -/*ARGSUSED*/ -int -_files_getnetbyname(void *rv, void *cb_data, va_list ap) -{ - struct netent *p; - char **cp; - const char *name; - - _DIAGASSERT(rv != NULL); - - name = va_arg(ap, const char *); - setnetent(_net_stayopen); - while ((p = getnetent()) != NULL) { - if (strcasecmp(p->n_name, name) == 0) - break; - for (cp = p->n_aliases; *cp != 0; cp++) - if (strcasecmp(*cp, name) == 0) - goto found; - } -found: - if (!_net_stayopen) - endnetent(); - *((struct netent **)rv) = p; - if (p==NULL) { - h_errno = HOST_NOT_FOUND; - return NS_NOTFOUND; - } - return NS_SUCCESS; -} - -/*ARGSUSED*/ -int -_dns_getnetbyname(void *rv, void *cb_data, va_list ap) -{ - int anslen; - querybuf *buf; - char qbuf[MAXDNAME]; - struct netent *np; - const char *net; - res_state res; - - _DIAGASSERT(rv != NULL); - - net = va_arg(ap, const char *); - strlcpy(&qbuf[0], net, sizeof(qbuf)); - buf = malloc(sizeof(*buf)); - if (buf == NULL) { - h_errno = NETDB_INTERNAL; - return NS_NOTFOUND; - } - res = __res_get_state(); - if (res == NULL) { - free(buf); - return NS_NOTFOUND; - } - anslen = res_nsearch(res, qbuf, C_IN, T_PTR, buf->buf, - sizeof(buf->buf)); - if (anslen < 0) { - free(buf); -#ifdef DEBUG - if (res->options & RES_DEBUG) - printf("res_search failed\n"); -#endif - __res_put_state(res); - return NS_NOTFOUND; - } - __res_put_state(res); - np = getnetanswer(buf, anslen, BYNAME); - free(buf); - *((struct netent **)rv) = np; - if (np == NULL) { - h_errno = HOST_NOT_FOUND; - return NS_NOTFOUND; - } - return NS_SUCCESS; -} - -struct netent * -getnetbyname(const char *net) -{ - struct netent *np; - static const ns_dtab dtab[] = { - NS_FILES_CB(_files_getnetbyname, NULL) - { NSSRC_DNS, _dns_getnetbyname, NULL }, /* force -DHESIOD */ - NS_NIS_CB(_yp_getnetbyname, NULL) - NS_NULL_CB - }; - - _DIAGASSERT(net != NULL); - - np = NULL; - h_errno = NETDB_INTERNAL; - if (nsdispatch(&np, dtab, NSDB_NETWORKS, "getnetbyname", __nsdefaultsrc, - net) != NS_SUCCESS) - return NULL; - h_errno = NETDB_SUCCESS; - return np; -} - -#ifdef YP -/*ARGSUSED*/ -int -_yp_getnetbyaddr(void *rv, void *cb_data, va_list ap) -{ - struct netent *np; - char qbuf[MAXDNAME]; - unsigned int netbr[4]; - uint32_t net, net2; - int type, r; - - _DIAGASSERT(rv != NULL); - - net = va_arg(ap, uint32_t); - type = va_arg(ap, int); - - if (type != AF_INET) - return NS_UNAVAIL; - - if (!__ypdomain) { - if (_yp_check(&__ypdomain) == 0) - return NS_UNAVAIL; - } - np = NULL; - if (__ypcurrent) - free(__ypcurrent); - __ypcurrent = NULL; - for (r = 4, net2 = net; net2; net2 >>= 8) - netbr[--r] = (unsigned int)(net2 & 0xff); - switch (r) { - default: - return NS_UNAVAIL; - case 3: /* Class A */ - snprintf(qbuf, sizeof(qbuf), "%u", netbr[3]); - break; - case 2: /* Class B */ - snprintf(qbuf, sizeof(qbuf), "%u.%u", netbr[2], netbr[3]); - break; - case 1: /* Class C */ - snprintf(qbuf, sizeof(qbuf), "%u.%u.%u", netbr[1], netbr[2], - netbr[3]); - break; - case 0: /* Class D - E */ - snprintf(qbuf, sizeof(qbuf), "%u.%u.%u.%u", netbr[0], netbr[1], - netbr[2], netbr[3]); - break; - } - r = yp_match(__ypdomain, "networks.byaddr", qbuf, (int)strlen(qbuf), - &__ypcurrent, &__ypcurrentlen); - if (r == 0) - np = _ypnetent(__ypcurrent); - - *((struct netent **)rv) = np; - if (np == NULL) { - h_errno = HOST_NOT_FOUND; - return NS_NOTFOUND; - } - return NS_SUCCESS; - -} - -int -/*ARGSUSED*/ -_yp_getnetbyname(void *rv, void *cb_data, va_list ap) -{ - struct netent *np; - const char *name; - int r; - - _DIAGASSERT(rv != NULL); - - name = va_arg(ap, const char *); - - if (!__ypdomain) { - if (_yp_check(&__ypdomain) == 0) - return NS_UNAVAIL; - } - np = NULL; - if (__ypcurrent) - free(__ypcurrent); - __ypcurrent = NULL; - r = yp_match(__ypdomain, "networks.byname", name, (int)strlen(name), - &__ypcurrent, &__ypcurrentlen); - if (r == 0) - np = _ypnetent(__ypcurrent); - - *((struct netent **)rv) = np; - if (np == NULL) { - h_errno = HOST_NOT_FOUND; - return NS_NOTFOUND; - } - return NS_SUCCESS; -} - -struct netent * -_ypnetent(char *line) -{ - char *cp, *p, **q; - - _DIAGASSERT(line != NULL); - - net_entry.n_name = line; - cp = strpbrk(line, " \t"); - if (cp == NULL) - return NULL; - *cp++ = '\0'; - while (*cp == ' ' || *cp == '\t') - cp++; - p = strpbrk(cp, " \t"); - if (p != NULL) - *p++ = '\0'; - net_entry.n_net = inet_network(cp); -#if (defined(__sparc__) && defined(_LP64)) || \ - defined(__alpha__) || \ - (defined(__i386__) && defined(_LP64)) || \ - (defined(__sh__) && defined(_LP64)) - net_entry.__n_pad0 = 0; -#endif - net_entry.n_addrtype = AF_INET; - q = net_entry.n_aliases = net_aliases; - if (p != NULL) { - cp = p; - while (cp && *cp) { - if (*cp == ' ' || *cp == '\t') { - cp++; - continue; - } - if (q < &net_aliases[MAXALIASES - 1]) - *q++ = cp; - cp = strpbrk(cp, " \t"); - if (cp != NULL) - *cp++ = '\0'; - } - } - *q = NULL; - - return &net_entry; -} -#endif diff --git a/lib/libc/net/sethostent.c b/lib/libc/net/sethostent.c deleted file mode 100644 index f848f1537f0c..000000000000 --- a/lib/libc/net/sethostent.c +++ /dev/null @@ -1,82 +0,0 @@ -/* $NetBSD: sethostent.c,v 1.14 2004/08/17 02:40:05 ginsbach Exp $ */ - -/* - * Copyright (c) 1985, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)sethostent.c 8.1 (Berkeley) 6/4/93"; -static char rcsid[] = "Id: sethostent.c,v 8.5 1996/09/28 06:51:07 vixie Exp "; -#else -__RCSID("$NetBSD: sethostent.c,v 1.14 2004/08/17 02:40:05 ginsbach Exp $"); -#endif -#endif /* LIBC_SCCS and not lint */ - -#include "namespace.h" -#include -#include -#include -#include -#include - -#ifdef __weak_alias -__weak_alias(sethostent,_sethostent) -__weak_alias(endhostent,_endhostent) -#endif - -void _endhtent __P((void)); -#ifndef _REENTRANT -void res_close __P((void)); -#endif -void _sethtent __P((int)); - -void -/*ARGSUSED*/ -sethostent(stayopen) - int stayopen; -{ -#ifndef _REENTRANT - if ((_res.options & RES_INIT) == 0 && res_init() == -1) - return; - if (stayopen) - _res.options |= RES_STAYOPEN | RES_USEVC; -#endif - _sethtent(stayopen); -} - -void -endhostent() -{ -#ifndef _REENTRANT - _res.options &= ~(RES_STAYOPEN | RES_USEVC); - res_close(); -#endif - _endhtent(); -} diff --git a/lib/libc/resolv/Makefile.inc b/lib/libc/resolv/Makefile.inc index 7f2971dc56eb..25008a3f743a 100644 --- a/lib/libc/resolv/Makefile.inc +++ b/lib/libc/resolv/Makefile.inc @@ -1,8 +1,8 @@ -# $NetBSD: Makefile.inc,v 1.2 2004/06/09 18:07:03 christos Exp $ +# $NetBSD: Makefile.inc,v 1.3 2007/01/27 22:26:44 christos Exp $ # net sources .PATH: ${.CURDIR}/resolv -CPPFLAGS+=-DCOMPAT__RES +CPPFLAGS+=-DCOMPAT__RES -DUSE_POLL SRCS+= __dn_comp.c __res_close.c __res_send.c h_errno.c \ herror.c res_comp.c res_data.c res_debug.c \ diff --git a/lib/libc/resolv/herror.c b/lib/libc/resolv/herror.c index 44cfba1b3ac3..d7c76a2d0697 100644 --- a/lib/libc/resolv/herror.c +++ b/lib/libc/resolv/herror.c @@ -1,4 +1,4 @@ -/* $NetBSD: herror.c,v 1.4 2004/05/23 05:09:52 christos Exp $ */ +/* $NetBSD: herror.c,v 1.5 2007/01/27 22:26:44 christos Exp $ */ /* * Copyright (c) 1987, 1993 @@ -53,10 +53,9 @@ #include #if defined(LIBC_SCCS) && !defined(lint) #ifdef notdef -static const char sccsid[] = "@(#)herror.c 8.1 (Berkeley) 6/4/93"; -static const char rcsid[] = "Id: herror.c,v 1.2.206.1 2004/03/09 08:33:54 marka Exp"; +static const char rcsid[] = "Id: herror.c,v 1.3.18.1 2005/04/27 05:01:09 sra Exp"; #else -__RCSID("$NetBSD: herror.c,v 1.4 2004/05/23 05:09:52 christos Exp $"); +__RCSID("$NetBSD: herror.c,v 1.5 2007/01/27 22:26:44 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -79,10 +78,10 @@ __RCSID("$NetBSD: herror.c,v 1.4 2004/05/23 05:09:52 christos Exp $"); 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] }; @@ -95,7 +94,7 @@ int h_errno; __weak_alias(herror,_herror) #endif -/* +/*% * herror -- * print the error indicated by the h_errno value. */ @@ -124,7 +123,7 @@ herror(const char *s) { writev(STDERR_FILENO, iov, (v - iov) + 1); } -/* +/*% * hstrerror -- * return the string associated with a given "host" errno value. */ @@ -136,3 +135,5 @@ hstrerror(int err) { return (h_errlist[err]); return ("Unknown resolver error"); } + +/*! \file */ diff --git a/lib/libc/resolv/res_comp.c b/lib/libc/resolv/res_comp.c index fb1286cb2e66..ce144178d0cc 100644 --- a/lib/libc/resolv/res_comp.c +++ b/lib/libc/resolv/res_comp.c @@ -1,4 +1,4 @@ -/* $NetBSD: res_comp.c,v 1.6 2004/05/22 23:47:09 christos Exp $ */ +/* $NetBSD: res_comp.c,v 1.7 2007/01/27 22:26:44 christos Exp $ */ /* * Copyright (c) 1985, 1993 @@ -73,9 +73,9 @@ #if defined(LIBC_SCCS) && !defined(lint) #ifdef notdef static const char sccsid[] = "@(#)res_comp.c 8.1 (Berkeley) 6/4/93"; -static const char rcsid[] = "Id: res_comp.c,v 1.1.2.1.4.1 2004/03/09 08:33:54 marka Exp"; +static const char rcsid[] = "Id: res_comp.c,v 1.3.18.2 2005/07/28 07:38:11 marka Exp"; #else -__RCSID("$NetBSD: res_comp.c,v 1.6 2004/05/22 23:47:09 christos Exp $"); +__RCSID("$NetBSD: res_comp.c,v 1.7 2007/01/27 22:26:44 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -105,12 +105,13 @@ __weak_alias(res_dnok,__res_dnok) #endif #endif -/* +/*% * 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, @@ -123,10 +124,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, @@ -137,7 +139,7 @@ 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 @@ -149,11 +151,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 @@ -196,7 +196,7 @@ res_hnok(const char *dn) { return (1); } -/* +/*% * hostname-like (A, MX, WKS) owners can have "*" as their first label * but must otherwise be as a host name. */ @@ -211,7 +211,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. */ @@ -239,8 +239,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 @@ -254,7 +254,7 @@ res_dnok(const char *dn) { } #ifdef BIND_4_COMPAT -/* +/*% * This module must export the following externally-visible symbols: * ___putlong * ___putshort @@ -262,6 +262,18 @@ res_dnok(const char *dn) { * __getshort * Note that one _ comes from C and the others come from us. */ + +#ifdef SOLARIS2 +#ifdef __putlong +#undef __putlong +#endif +#ifdef __putshort +#undef __putshort +#endif +#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__ @@ -269,3 +281,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/lib/libc/resolv/res_data.c b/lib/libc/resolv/res_data.c index 155a6c939435..ddb42b9764f3 100644 --- a/lib/libc/resolv/res_data.c +++ b/lib/libc/resolv/res_data.c @@ -1,4 +1,4 @@ -/* $NetBSD: res_data.c,v 1.8 2004/06/09 18:07:03 christos Exp $ */ +/* $NetBSD: res_data.c,v 1.9 2007/01/27 22:26:44 christos Exp $ */ /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -20,9 +20,9 @@ #include #if defined(LIBC_SCCS) && !defined(lint) #ifdef notdef -static const char rcsid[] = "Id: res_data.c,v 1.1.206.2 2004/03/16 12:34:18 marka Exp"; +static const char rcsid[] = "Id: res_data.c,v 1.3.18.1 2005/04/27 05:01:10 sra Exp"; #else -__RCSID("$NetBSD: res_data.c,v 1.8 2004/06/09 18:07:03 christos Exp $"); +__RCSID("$NetBSD: res_data.c,v 1.9 2007/01/27 22:26:44 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -74,8 +74,8 @@ const char *_res_opcodes[] = { "QUERY", "IQUERY", "CQUERYM", - "CQUERYU", /* experimental */ - "NOTIFY", /* experimental */ + "CQUERYU", /*%< experimental */ + "NOTIFY", /*%< experimental */ "UPDATE", "6", "7", @@ -187,14 +187,14 @@ fp_nquery(const u_char *msg, int len, FILE *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 ((_nres.options & RES_INIT) == 0U && res_init() == -1) { RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL); @@ -218,10 +218,10 @@ res_mkupdate(ns_updrec *rrecp_in, u_char *buf, int buflen) { #endif 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 ((_nres.options & RES_INIT) == 0U && res_init() == -1) { RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL); @@ -287,10 +287,10 @@ res_update(ns_updrec *rrecp_in) { #endif 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 ((_nres.options & RES_INIT) == 0U && res_init() == -1) { RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL); @@ -303,9 +303,9 @@ 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 ((_nres.options & RES_INIT) == 0U && res_init() == -1) { RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL); @@ -348,3 +348,5 @@ local_hostname_length(const char *hostname) { #endif /*ultrix*/ #endif + +/*! \file */ diff --git a/lib/libc/resolv/res_debug.c b/lib/libc/resolv/res_debug.c index ef498e3f37cb..f15bfa1abf30 100644 --- a/lib/libc/resolv/res_debug.c +++ b/lib/libc/resolv/res_debug.c @@ -1,4 +1,4 @@ -/* $NetBSD: res_debug.c,v 1.7 2004/11/07 02:25:01 christos Exp $ */ +/* $NetBSD: res_debug.c,v 1.8 2007/01/27 22:26:44 christos Exp $ */ /* * Copyright (c) 1985 @@ -99,9 +99,9 @@ #if defined(LIBC_SCCS) && !defined(lint) #ifdef notdef static const char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93"; -static const char rcsid[] = "Id: res_debug.c,v 1.3.2.5.4.5 2004/07/28 20:16:46 marka Exp"; +static const char rcsid[] = "Id: res_debug.c,v 1.10.18.5 2005/07/28 07:38:11 marka Exp"; #else -__RCSID("$NetBSD: res_debug.c,v 1.7 2004/11/07 02:25:01 christos Exp $"); +__RCSID("$NetBSD: res_debug.c,v 1.8 2007/01/27 22:26:44 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -121,6 +121,7 @@ __RCSID("$NetBSD: res_debug.c,v 1.7 2004/11/07 02:25:01 christos Exp $"); #include #include #include +#include #include #include #include @@ -148,7 +149,7 @@ __weak_alias(res_nametotype,__res_nametotype) #endif #ifndef _LIBC -/* +/*% * Print the current options. */ void @@ -242,7 +243,7 @@ do_section(const res_state statp, free(buf); } -/* +/*% * Print the contents of a query. * This is intended to be primarily a debugging routine. */ @@ -337,7 +338,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 * @@ -353,7 +355,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, "."); @@ -375,7 +377,7 @@ 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.) @@ -391,7 +393,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[] = { @@ -428,7 +430,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.) @@ -486,7 +488,7 @@ const struct res_sym __p_type_syms[] = { {0, NULL, NULL} }; -/* +/*% * Names of DNS rcodes. */ const struct res_sym __p_rcode_syms[] = { @@ -519,12 +521,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) { - static char unname[20]; + char *unname = sym_ntos_unname; for (; syms->name != 0; syms++) { if (number == syms->number) { @@ -534,7 +536,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); @@ -542,7 +544,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) { - static char unname[20]; + char *unname = sym_ntop_unname; for (; syms->name != 0; syms++) { if (number == syms->number) { @@ -551,13 +553,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 * @@ -575,7 +577,7 @@ p_type(int type) { return (typebuf); } -/* +/*% * Return a string for the type. */ const char * @@ -593,7 +595,7 @@ p_section(int section, int opcode) { return (sym_ntos(symbols, section, (int *)0)); } -/* +/*% * Return a mnemonic for class. */ const char * @@ -611,12 +613,12 @@ p_class(int class) { return (classbuf); } -/* +/*% * Return a mnemonic for an option */ const char * p_option(u_long option) { - static char nbuf[40]; + char *nbuf = p_option_nbuf; switch (option) { case RES_INIT: return "init"; @@ -633,7 +635,7 @@ p_option(u_long 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"; #endif #ifdef RES_USE_DNAME @@ -654,19 +656,19 @@ p_option(u_long option) { } } -/* +/*% * Return a mnemonic for a time to live. */ const char * p_time(u_int32_t value) { - static char nbuf[40]; /* XXX nonreentrant */ + char *nbuf = p_time_nbuf; if (ns_format_ttl((u_long)value, nbuf, sizeof nbuf) < 0) sprintf(nbuf, "%u", value); return (nbuf); } -/* +/*% * Return a string for the rcode. */ const char * @@ -674,7 +676,7 @@ p_rcode(int rcode) { return (sym_ntos(__p_rcode_syms, rcode, (int *)0)); } -/* +/*% * Return a string for a res_sockaddr_union. */ const char * @@ -701,7 +703,7 @@ p_sockun(union res_sockaddr_union u, char *buf, size_t size) { 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. @@ -710,12 +712,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_int32_t prec; { - static char retbuf[sizeof "90000000.00"]; /* XXX nonreentrant */ + char *retbuf = precsize_ntoa_retbuf; unsigned long val; int mantissa, exponent; @@ -728,7 +730,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; @@ -742,7 +744,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; @@ -768,7 +770,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; @@ -798,7 +800,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; @@ -811,7 +813,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)) @@ -832,30 +834,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; @@ -863,7 +864,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) @@ -876,9 +878,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; @@ -889,18 +891,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); } @@ -916,7 +918,7 @@ loc_aton(ascii, binary) 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; @@ -928,7 +930,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)) @@ -939,7 +941,7 @@ loc_aton(ascii, binary) 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)) @@ -950,7 +952,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)) @@ -964,7 +966,7 @@ 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; @@ -972,10 +974,10 @@ loc_aton(ascii, binary) 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; @@ -1022,7 +1024,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 { @@ -1085,7 +1087,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; @@ -1110,15 +1112,14 @@ dn_count_labels(const char *name) { return (count); } - -/* +/*% * Make dates expressed in seconds-since-Jan-1-1970 easy to read. * SIG records are required to be printed like this, by the Secure DNS RFC. */ char * p_secstodate (u_long secs) { /* XXX nonreentrant */ - static char output[15]; /* YYYYMMDDHHMMSS and null */ + char *output = p_secstodate_output; time_t myclock = secs; struct tm *mytime; #ifdef HAVE_TIME_R @@ -1181,3 +1182,5 @@ res_nametotype(const char *buf, int *successp) { *successp = success; return (u_int16_t)(result); } + +/*! \file */ diff --git a/lib/libc/resolv/res_init.c b/lib/libc/resolv/res_init.c index c60b62e3b762..90e36254ebe4 100644 --- a/lib/libc/resolv/res_init.c +++ b/lib/libc/resolv/res_init.c @@ -1,4 +1,4 @@ -/* $NetBSD: res_init.c,v 1.8 2006/03/19 03:10:08 christos Exp $ */ +/* $NetBSD: res_init.c,v 1.9 2007/01/27 22:26:44 christos Exp $ */ /* * Copyright (c) 1985, 1989, 1993 @@ -74,9 +74,9 @@ #if defined(LIBC_SCCS) && !defined(lint) #ifdef notdef static const char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93"; -static const char rcsid[] = "Id: res_init.c,v 1.9.2.5.4.2 2004/03/16 12:34:18 marka Exp"; +static const char rcsid[] = "Id: res_init.c,v 1.16.18.5 2006/08/30 23:23:13 marka Exp"; #else -__RCSID("$NetBSD: res_init.c,v 1.8 2006/03/19 03:10:08 christos Exp $"); +__RCSID("$NetBSD: res_init.c,v 1.9 2007/01/27 22:26:44 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -120,18 +120,23 @@ __weak_alias(res_setservers,__res_setservers) #include "res_private.h" -/* Options. Should all be left alone. */ +/*% Options. Should all be left alone. */ +#define RESOLVSORT #ifndef DEBUG #define DEBUG #endif +#ifdef SOLARIS2 +#include +#endif + static void res_setoptions __P((res_state, const char *, const char *)); static const char sort_mask[] = "/&"; #define ISSORTMASK(ch) (strchr(sort_mask, ch) != NULL) static u_int32_t net_mask __P((struct in_addr)); -#if !defined(isascii) /* XXX - could be a function */ +#if !defined(isascii) /*%< XXX - could be a function */ # define isascii(c) (!(c & 0200)) #endif @@ -139,7 +144,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(). @@ -167,14 +172,14 @@ res_ninit(res_state statp) { 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; int nsort = 0; @@ -182,6 +187,9 @@ __res_vinit(res_state statp, int preinit) { int dots; union res_sockaddr_union u[2]; + if (statp->_u._ext.ext != NULL) + res_ndestroy(statp); + if (!preinit) { statp->retrans = RES_TIMEOUT; statp->retry = RES_DFLRETRY; @@ -189,9 +197,6 @@ __res_vinit(res_state statp, int preinit) { statp->id = res_randomid(); } - if ((statp->options & RES_INIT) != 0U) - res_ndestroy(statp); - memset(u, 0, sizeof(u)); #ifdef USELOOPBACK u[nserv].sin.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1); @@ -231,10 +236,34 @@ __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); +#ifdef RESOLVSORT statp->nsort = 0; res_setservers(statp, u, nserv); +#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); + if (strlen(cp) >= sizeof(statp->defdname)) + goto freedata; + strcpy(statp->defdname, cp); + } + } +#endif /* SOLARIS2 */ + /* Allow user to override the local domain definition */ if ((cp = getenv("LOCALDOMAIN")) != NULL) { (void)strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1); @@ -252,7 +281,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; @@ -284,7 +313,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') @@ -300,7 +329,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') @@ -450,7 +479,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--; } @@ -469,6 +498,15 @@ __res_vinit(res_state statp, int preinit) { res_setoptions(statp, cp, "env"); statp->options |= RES_INIT; return (0); + +#ifdef SOLARIS2 + freedata: + if (statp->_u._ext.ext != NULL) { + free(statp->_u._ext.ext); + statp->_u._ext.ext = NULL; + } + return (-1); +#endif } static void @@ -508,6 +546,22 @@ res_setoptions(res_state statp, const char *options, const char *source) 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. + */ + statp->retrans = atoi(cp + sizeof("retrans:") - 1); + } else if (!strncmp(cp, "retry:", sizeof("retry:") - 1)){ + /* + * For backward compatibility, 'retry' is + * supported as an alias for 'attempts', though + * without an imposed maximum. + */ + statp->retry = atoi(cp + sizeof("retry:") - 1); +#endif /* SOLARIS2 */ } else if (!strncmp(cp, "attempts:", sizeof("attempts:") - 1)){ i = atoi(cp + sizeof("attempts:") - 1); if (i <= RES_MAXRETRY) @@ -586,7 +640,7 @@ res_setoptions(res_state statp, const char *options, const char *source) /* 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); @@ -606,7 +660,7 @@ res_randomid(void) { return (0xffff & (now.tv_sec ^ now.tv_usec ^ getpid())); } -/* +/*% * 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. @@ -751,3 +805,5 @@ res_getservers(res_state statp, union res_sockaddr_union *set, int cnt) { } return (statp->nscount); } + +/*! \file */ diff --git a/lib/libc/resolv/res_mkquery.c b/lib/libc/resolv/res_mkquery.c index 3efefb2cd6fc..e52b2874b9af 100644 --- a/lib/libc/resolv/res_mkquery.c +++ b/lib/libc/resolv/res_mkquery.c @@ -1,4 +1,4 @@ -/* $NetBSD: res_mkquery.c,v 1.6 2006/01/24 17:40:32 christos Exp $ */ +/* $NetBSD: res_mkquery.c,v 1.7 2007/01/27 22:26:44 christos Exp $ */ /* * Copyright (c) 1985, 1993 @@ -74,9 +74,9 @@ #if defined(LIBC_SCCS) && !defined(lint) #ifdef notdef static const char sccsid[] = "@(#)res_mkquery.c 8.1 (Berkeley) 6/4/93"; -static const char rcsid[] = "Id: res_mkquery.c,v 1.1.2.2.4.2 2004/03/16 12:34:18 marka Exp"; +static const char rcsid[] = "Id: res_mkquery.c,v 1.5.18.1 2005/04/27 05:01:11 sra Exp"; #else -__RCSID("$NetBSD: res_mkquery.c,v 1.6 2006/01/24 17:40:32 christos Exp $"); +__RCSID("$NetBSD: res_mkquery.c,v 1.7 2007/01/27 22:26:44 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -107,20 +107,20 @@ __weak_alias(res_nopt,_res_nopt) extern const char *_res_opcodes[]; -/* +/*% * 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; @@ -197,7 +197,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); @@ -227,10 +227,10 @@ res_nmkquery(res_state statp, int res_nopt(res_state statp, - int n0, /* current offset in buffer */ - u_char *buf, /* buffer to put query */ - 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; @@ -248,14 +248,13 @@ res_nopt(res_state statp, if ((ep - cp) < 1 + RRFIXEDSZ) return (-1); - *cp++ = 0; /* "." */ - - ns_put16(T_OPT, cp); /* TYPE */ + *cp++ = 0; /*%< "." */ + ns_put16(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) @@ -265,10 +264,12 @@ res_nopt(res_state statp, } ns_put16(flags, cp); cp += INT16SZ; - ns_put16(0, cp); /* RDLEN */ + ns_put16(0, cp); /*%< RDLEN */ cp += INT16SZ; hp->arcount = htons(ntohs(hp->arcount) + 1); return (cp - buf); } #endif + +/*! \file */ diff --git a/lib/libc/resolv/res_query.c b/lib/libc/resolv/res_query.c index 6b114a7a361c..05fae123466b 100644 --- a/lib/libc/resolv/res_query.c +++ b/lib/libc/resolv/res_query.c @@ -1,4 +1,4 @@ -/* $NetBSD: res_query.c,v 1.7 2006/01/24 17:41:25 christos Exp $ */ +/* $NetBSD: res_query.c,v 1.8 2007/01/27 22:26:44 christos Exp $ */ /* * Copyright (c) 1988, 1993 @@ -74,9 +74,9 @@ #if defined(LIBC_SCCS) && !defined(lint) #ifdef notdef static const char sccsid[] = "@(#)res_query.c 8.1 (Berkeley) 6/4/93"; -static const char rcsid[] = "Id: res_query.c,v 1.2.2.3.4.2 2004/03/16 12:34:19 marka Exp"; +static const char rcsid[] = "Id: res_query.c,v 1.7.18.1 2005/04/27 05:01:11 sra Exp"; #else -__RCSID("$NetBSD: res_query.c,v 1.7 2006/01/24 17:41:25 christos Exp $"); +__RCSID("$NetBSD: res_query.c,v 1.8 2007/01/27 22:26:44 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -118,7 +118,7 @@ __weak_alias(res_hostalias,__res_hostalias) #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 @@ -130,10 +130,10 @@ __weak_alias(res_hostalias,__res_hostalias) */ 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 *)(void *)answer; @@ -143,8 +143,7 @@ res_nquery(res_state statp, 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); @@ -216,7 +215,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 @@ -224,10 +223,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 *)(void *)answer; @@ -239,8 +238,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 == '.'); @@ -365,7 +363,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. */ @@ -373,9 +371,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; @@ -457,3 +455,5 @@ res_hostalias(const res_state statp, const char *name, char *dst, size_t siz) { fclose(fp); return (NULL); } + +/*! \file */ diff --git a/lib/libc/resolv/res_send.c b/lib/libc/resolv/res_send.c index b5e028356c0b..432c496ad8ed 100644 --- a/lib/libc/resolv/res_send.c +++ b/lib/libc/resolv/res_send.c @@ -1,4 +1,4 @@ -/* $NetBSD: res_send.c,v 1.9 2006/01/24 17:41:25 christos Exp $ */ +/* $NetBSD: res_send.c,v 1.10 2007/01/27 22:26:44 christos Exp $ */ /* * Copyright (c) 1985, 1989, 1993 @@ -54,7 +54,7 @@ */ /* - * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 2005 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 @@ -74,13 +74,14 @@ #if defined(LIBC_SCCS) && !defined(lint) #ifdef notdef static const char sccsid[] = "@(#)res_send.c 8.1 (Berkeley) 6/4/93"; -static const char rcsid[] = "Id: res_send.c,v 1.5.2.2.4.5 2004/08/10 02:19:56 marka Exp"; +static const char rcsid[] = "Id: res_send.c,v 1.9.18.8 2006/10/16 23:00:58 marka Exp"; #else -__RCSID("$NetBSD: res_send.c,v 1.9 2006/01/24 17:41:25 christos Exp $"); +__RCSID("$NetBSD: res_send.c,v 1.10 2007/01/27 22:26:44 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ -/* +/*! \file + * \brief * Send query to name server and wait for reply. */ @@ -120,6 +121,14 @@ __weak_alias(res_nsend,__res_nsend) #endif #endif + +#ifdef USE_POLL +#ifdef HAVE_STROPTS_H +#include +#endif +#include +#endif /* USE_POLL */ + /* Options. Leave them on. */ #ifndef DEBUG #define DEBUG @@ -129,7 +138,11 @@ __weak_alias(res_nsend,__res_nsend) #define EXT(res) ((res)->_u._ext) +#ifndef USE_POLL static const int highestFD = FD_SETSIZE - 1; +#else +static int highestFD = 0; +#endif /* Forward. */ @@ -138,13 +151,13 @@ 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 *); @@ -155,14 +168,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) { @@ -205,17 +219,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, @@ -243,16 +259,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, @@ -299,7 +316,12 @@ res_nsend(res_state statp, int gotsomewhere, terrno, try, v_circuit, resplen, ns, n; char abuf[NI_MAXHOST]; - if (statp->nscount == 0) { +#ifdef USE_POLL + highestFD = sysconf(_SC_OPEN_MAX) - 1; +#endif + + /* No name servers or res_init() failure */ + if (statp->nscount == 0 || EXT(statp).ext == NULL) { errno = ESRCH; return (-1); } @@ -462,7 +484,7 @@ res_nsend(res_state statp, } else { /* Use datagrams. */ n = send_dg(statp, buf, buflen, ans, anssiz, &terrno, - ns, &v_circuit, &gotsomewhere); + ns, try, &v_circuit, &gotsomewhere); if (n < 0) goto fail; if (n == 0) @@ -527,9 +549,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); @@ -556,10 +578,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 * @@ -770,19 +792,24 @@ 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 try, int *v_circuit, + int *gotsomewhere) { const HEADER *hp = (const HEADER *)(const void *)buf; HEADER *anhp = (HEADER *)(void *)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 USE_POLL + int polltimeout; + struct pollfd pollfd; +#else + fd_set dsmask; +#endif nsap = get_nsaddr(statp, (size_t)ns); nsaplen = get_salen(nsap); @@ -848,7 +875,7 @@ send_dg(res_state statp, /* * Wait for reply. */ - seconds = (statp->retrans << ns); + seconds = (statp->retrans << try); if (ns > 0) seconds /= statp->nscount; if (seconds <= 0) @@ -860,6 +887,7 @@ send_dg(res_state statp, wait: now = evNowTime(); nonow: +#ifndef USE_POLL FD_ZERO(&dsmask); FD_SET(s, &dsmask); if (evCmpTime(finish, now) > 0) @@ -867,6 +895,17 @@ send_dg(res_state statp, else timeout = evConsTime(0L, 0L); n = pselect(s + 1, &dsmask, NULL, NULL, &timeout, NULL); +#else + timeout = evSubTime(finish, now); + if (timeout.tv_sec < 0) + timeout = evConsTime(0, 0); + polltimeout = 1000*timeout.tv_sec + + timeout.tv_nsec/1000000; + pollfd.fd = s; + pollfd.events = POLLRDNORM; + n = poll(&pollfd, 1, polltimeout); +#endif /* USE_POLL */ + if (n == 0) { Dprint(statp->options & RES_DEBUG, (stdout, ";; timeout\n")); *gotsomewhere = 1; @@ -875,7 +914,11 @@ send_dg(res_state statp, if (n < 0) { if (errno == EINTR) goto wait; +#ifndef USE_POLL Perror(statp, stderr, "select", errno); +#else + Perror(statp, stderr, "poll", errno); +#endif /* USE_POLL */ res_nclose(statp); return (0); } @@ -1044,7 +1087,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/lib/libc/resolv/res_state.c b/lib/libc/resolv/res_state.c index 932c822dafdd..4b3f27f45208 100644 --- a/lib/libc/resolv/res_state.c +++ b/lib/libc/resolv/res_state.c @@ -1,4 +1,4 @@ -/* $NetBSD: res_state.c,v 1.5 2004/06/09 18:07:03 christos Exp $ */ +/* $NetBSD: res_state.c,v 1.6 2007/01/27 22:26:44 christos Exp $ */ /*- * Copyright (c) 2004 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: res_state.c,v 1.5 2004/06/09 18:07:03 christos Exp $"); +__RCSID("$NetBSD: res_state.c,v 1.6 2007/01/27 22:26:44 christos Exp $"); #endif #include @@ -47,7 +47,11 @@ __RCSID("$NetBSD: res_state.c,v 1.5 2004/06/09 18:07:03 christos Exp $"); #include #include -struct __res_state _nres; +struct __res_state _nres +# if defined(__BIND_RES_TEXT) + = { .retrans = RES_TIMEOUT, } /*%< Motorola, et al. */ +# endif + ; res_state __res_get_state_nothread(void); void __res_put_state_nothread(res_state);