Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/lib/libc/resolv/res_send.c,v rcsdiff: /ftp/cvs/cvsroot/src/lib/libc/resolv/res_send.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.9 retrieving revision 1.10 diff -u -p -r1.9 -r1.10 --- src/lib/libc/resolv/res_send.c 2006/01/24 17:41:25 1.9 +++ src/lib/libc/resolv/res_send.c 2007/01/27 22:26:44 1.10 @@ -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( 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_NUMERICHOS /* 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, c 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 ty 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 socka } } -#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,