2N/A * Copyright (c) 1989, 2011, Oracle and/or its affiliates. All rights reserved. 2N/A * Portions Copyright (C) 2004-2009 Internet Systems Consortium, Inc. ("ISC") 2N/A * Portions Copyright (C) 1996-2003 Internet Software Consortium. 2N/A * Permission to use, copy, modify, and/or distribute this software for any 2N/A * purpose with or without fee is hereby granted, provided that the above 2N/A * copyright notice and this permission notice appear in all copies. 2N/A * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 2N/A * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 2N/A * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 2N/A * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 2N/A * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 2N/A * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 2N/A * PERFORMANCE OF THIS SOFTWARE. 2N/A * Copyright (c) 1985, 1989, 1993 2N/A * The Regents of the University of California. All rights reserved. 2N/A * Redistribution and use in source and binary forms, with or without 2N/A * modification, are permitted provided that the following conditions 2N/A * 1. Redistributions of source code must retain the above copyright 2N/A * notice, this list of conditions and the following disclaimer. 2N/A * 2. Redistributions in binary form must reproduce the above copyright 2N/A * notice, this list of conditions and the following disclaimer in the 2N/A * documentation and/or other materials provided with the distribution. 2N/A * 3. All advertising materials mentioning features or use of this software 2N/A * must display the following acknowledgement: 2N/A * This product includes software developed by the University of 2N/A * California, Berkeley and its contributors. 2N/A * 4. Neither the name of the University nor the names of its contributors 2N/A * may be used to endorse or promote products derived from this software 2N/A * without specific prior written permission. 2N/A * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2N/A * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2N/A * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2N/A * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2N/A * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2N/A * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2N/A * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2N/A * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2N/A * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2N/A * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2N/A * Portions Copyright (c) 1993 by Digital Equipment Corporation. 2N/A * Permission to use, copy, modify, and distribute this software for any 2N/A * purpose with or without fee is hereby granted, provided that the above 2N/A * copyright notice and this permission notice appear in all copies, and that 2N/A * the name of Digital Equipment Corporation not be used in advertising or 2N/A * publicity pertaining to distribution of the document or software without 2N/A * specific, written prior permission. 2N/A * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL 2N/A * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES 2N/A * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT 2N/A * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 2N/A * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 2N/A * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 2N/A * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 2N/A#
endif /* LIBC_SCCS and not lint */ 2N/A * Send query to name server and wait for reply. 2N/A#
endif /* USE_POLL */ 2N/A/* Options. Leave them on. */ 2N/A#
endif /* ORIGINAL_ISC_CODE */ 2N/A#
endif /* SUNW_SUBSECOND_TIME */ 2N/A * looks up "ina" in _res.ns_addr_list[] 2N/A *\li paul vixie, 29may94 2N/A * look for (name,type,class) in the query section of packet (buf,eom) 2N/A *\li buf + HFIXEDSZ <= eom 2N/A *\li -1 : format error 2N/A *\li paul vixie, 29may94 2N/A * is there a 1:1 mapping of (name,type,class) 2N/A * in (buf1,eom1) and (buf2,eom2)? 2N/A *\li -1 : format error 2N/A *\li 0 : not a 1:1 mapping 2N/A *\li >0 : is a 1:1 mapping 2N/A *\li paul vixie, 29may94 2N/A * Only header section present in replies to 2N/A * dynamic update packets. 2N/A#
endif /* SUNW_DEFER_ON_FAIL */ 2N/A /* No name servers or res_init() failure */ 2N/A * If the ns_addr_list in the resolver context has changed, then 2N/A * invalidate our cached copy and the associated timing data. 2N/A * If the retrans time in the public portion of the resolver context 2N/A * (an integer) has changed, update the corresponding retrans time 2N/A * in the private area of the resolver context (a struct timespec). 2N/A#
endif /* SUNW_SUBSECOND_TIME */ 2N/A * Maybe initialize our private copy of the ns_addr_list. 2N/A#
endif /* SUNW_DEFER_ON_FAIL */ 2N/A * Some resolvers want to even out the load on their nameservers. 2N/A * Note that RES_BLAST overrides RES_ROTATE. 2N/A#
endif /* SUNW_DEFER_ON_FAIL */ 2N/A#
endif /* SUNW_DEFER_ON_FAIL */ 2N/A#
endif /* SUNW_DEFER_ON_FAIL */ 2N/A#
endif /* SUNW_DEFER_ON_FAIL */ 2N/A * Send request, RETRY times, or until successful. 2N/A#
endif /* SUNW_DEFER_ON_FAIL */ 2N/A ";; Deferred server (# %d) address = %s\n",
2N/A * Although the query has not yet actually been sent, 2N/A * the following assignment is made here, because: 2N/A * 1) The query will be attempted below, before this boolean 2N/A * is next referenced, unless the qhook returns res_nextns. 2N/A * 2) Even if the qhook returns res_nextns, the server should 2N/A * still be considered to have been queried, so that this 2N/A * condition cannot cause the qhook to run a second time 2N/A * on this server when statp->retry == 1. 2N/A#
endif /* SUNW_DEFER_ON_FAIL */ 2N/A /* give the hook another try */ 2N/A (
stdout,
";; Querying server (# %d) address = %s\n",
2N/A /* Use VC; at most one attempt per server. */ 2N/A#
endif /* SUNW_DEFER_ON_FAIL */ 2N/A /* Use datagrams. */ 2N/A#
endif /* SUNW_DEFER_ON_FAIL */ 2N/A * If we have temporarily opened a virtual circuit, 2N/A * or if we haven't been asked to keep a socket open, 2N/A /* give the hook another try */ 2N/A ";; All servers deferred, forcing retry\n"));
2N/A#
endif /* SUNW_DEFER_ON_FAIL */ 2N/A /* There are people do not set sa_len. Be forgiving to them. */ 2N/A return (0);
/*%< unknown, die on connect */ 2N/A * pick appropriate nsaddr_list for use. see res_init() for initialization. 2N/A * - EXT(statp).ext->nsaddrs[n] holds an address that is larger 2N/A * than struct sockaddr, and 2N/A * - user code did not update statp->nsaddr_list[n]. 2N/A * - user code updated statp->nsaddr_list[n], or 2N/A * - statp->nsaddr_list[n] has the same content as 2N/A * EXT(statp).ext->nsaddrs[n]. 2N/A /* Are we still talking to whom we want to talk to? */ 2N/A * Disable generation of SIGPIPE when writing to a closed 2N/A * socket. Write should return -1 and set errno to EPIPE 2N/A * Push on even if setsockopt(SO_NOSIGPIPE) fails. 2N/A * Send length & message 2N/A * Receive length & response 2N/A * A long running process might get its TCP 2N/A * connection reset if the remote server was 2N/A * restarted. Requery the server instead of 2N/A * trying a new one. When there is only one 2N/A * server, this means that a query might work 2N/A * instead of failing. We only allow one reset 2N/A * per query to prevent looping. 2N/A * Undersized message. 2N/A * Flush rest of answer so connection stays in synch. 2N/A * If the calling applicating has bailed out of 2N/A * a previous call and failed to arrange to have 2N/A * the circuit closed or the server has got 2N/A * itself confused, then drop the packet and 2N/A * wait for the correct one. 2N/A * All is well, or the error is fatal. Signal that the 2N/A * next nameserver ought not be tried. 2N/A#
endif /* SUNW_SUBSECOND_TIME */ 2N/A * On a 4.3BSD+ machine (client and server, 2N/A * actually), sending to a nameserver datagram 2N/A * port with no nameserver will cause an 2N/A * ICMP port unreachable message to be returned. 2N/A * If our datagram socket is "connected" to the 2N/A * server, we get an ECONNREFUSED error on the next 2N/A * socket operation, and select returns if the 2N/A * error message is received. We can thus detect 2N/A * the absence of a nameserver without timing out. 2N/A#
endif /* !CANNOT_CONNECT_DGRAM */ 2N/A#
else /* !CANNOT_CONNECT_DGRAM */ 2N/A#
endif /* !CANNOT_CONNECT_DGRAM */ 2N/A#
else /* SUNW_SUBSECOND_TIME */ 2N/A#
endif /* SUNW_SUBSECOND_TIME */ 2N/A#
else /* SUNW_SUBSECOND_TIME */ 2N/A#
endif /* SUNW_SUBSECOND_TIME */ 2N/A#
endif /* USE_POLL */ 2N/A#
endif /* USE_POLL */ 2N/A * Undersized message. 2N/A * response from old query, ignore it. 2N/A * XXX - potential security hazard could 2N/A * response from wrong server? ignore it. 2N/A * XXX - potential security hazard could 2N/A * Do not retry if the server do not understand EDNS0. 2N/A * The case has to be captured here, as FORMERR packet do not 2N/A * carry query section, hence res_queriesmatch() returns 0. 2N/A (
stdout,
"server rejected query with EDNS0:\n"),
2N/A /* record the error */ 2N/A * response contains wrong query? ignore it. 2N/A * XXX - potential security hazard could 2N/A /* don't retry if called from dig */ 2N/A * To get the rest of answer, 2N/A * use TCP with same server. 2N/A * All is well, or the error is fatal. Signal that the 2N/A * next nameserver ought not be tried. 2N/A/* XXX needs to move to the porting library. */ 2N/A * Set the current defer status for a nameserver. 2N/A /* if statp extension data is unavailable, do nothing */ 2N/A /* always set status to online if defer-on-fail option is disabled */ 2N/A * Caller is reporting a successful query. 2N/A * Mark the server as online. 2N/A * Set it's defer time to 0, as if it has always been online. 2N/A * Caller is reporting an unsuccessful query. 2N/A * Mark the server as offline. 2N/A * Set the retry time to a "defer-on-fail" time in the future. 2N/A * However, do not extend an unexpired retry time. 2N/A * Get status code indicating whether or not the nameserver 2N/A * is expected to be responsive to queries. 2N/A /* if statp extension data is unavailable, always return "online" */ 2N/A /* quick return when defer-on-fail option is disabled */ 2N/A /* quick return for "online" servers */ 2N/A * if "offline" server is now ready for retry, 2N/A * mark it "online" and return new status 2N/A /* server is still considered "offline" */ 2N/A#
endif /* SUNW_DEFER_ON_FAIL */