&EXT(statp).nsaddrs[ns])) #endif {
res_nsend(res_state statp,	  const u_char *buf, int buflen, u_char *ans, int anssiz){	int gotsomewhere, terrno, try, v_circuit, resplen, ns, n;	if (statp->nscount == 0) {		__set_errno (ESRCH);		return (-1);	}	if (anssiz < HFIXEDSZ) {		__set_errno (EINVAL);		return (-1);	}	DprintQ((statp->options & RES_DEBUG) || (statp->pfcode & RES_PRF_QUERY),		(stdout, ";; res_send()\n"), buf, buflen);	v_circuit = (statp->options & RES_USEVC) || buflen > PACKETSZ;	gotsomewhere = 0;	terrno = ETIMEDOUT;	/*	 * If the ns_addr_list in the resolver context has changed, then	 * invalidate our cached copy and the associated timing data.	 */	if (EXT(statp).nscount != 0) {		int needclose = 0;		if (EXT(statp).nscount != statp->nscount)			needclose++;		else			for (ns = 0; ns < statp->nscount; ns++)				if (!sock_eq(&statp->nsaddr_list[ns],#ifdef _LIBC					     (struct sockaddr_in *)#endif					     &EXT(statp).nsaddrs[ns])) {					needclose++;					break;				}		if (needclose)			res_nclose(statp);	}	/*	 * Maybe initialize our private copy of the ns_addr_list.	 */	if (EXT(statp).nscount == 0) {		for (ns = 0; ns < statp->nscount; ns++) {#ifdef _LIBC			memcpy(&EXT(statp).nsaddrs[ns],			       &statp->nsaddr_list[ns],			       sizeof (&EXT(statp).nsaddrs[0]));#else			EXT(statp).nsaddrs[ns] = statp->nsaddr_list[ns];#endif			EXT(statp).nstimes[ns] = RES_MAXTIME;			EXT(statp).nssocks[ns] = -1;		}		EXT(statp).nscount = statp->nscount;	}	/*	 * Some resolvers want to even out the load on their nameservers.	 * Note that RES_BLAST overrides RES_ROTATE.	 */	if ((statp->options & RES_ROTATE) != 0 &&	    (statp->options & RES_BLAST) == 0) {		struct sockaddr_in ina;		int lastns = statp->nscount - 1;		ina = statp->nsaddr_list[0];		for (ns = 0; ns < lastns; ns++)			statp->nsaddr_list[ns] = statp->nsaddr_list[ns + 1];		statp->nsaddr_list[lastns] = ina;	}	/*	 * Send request, RETRY times, or until successful.	 */	for (try = 0; try < statp->retry; try++) {	    for (ns = 0; ns < statp->nscount; ns++) {		struct sockaddr_in *nsap = &statp->nsaddr_list[ns]; same_ns:		if (statp->qhook) {			int done = 0, loops = 0;			do {				res_sendhookact act;				act = (*statp->qhook)(&nsap, &buf, &buflen,						      ans, anssiz, &resplen);				switch (act) {				case res_goahead:					done = 1;					break;				case res_nextns:					res_nclose(statp);					goto next_ns;				case res_done:					return (resplen);				case res_modified:					/* give the hook another try */					if (++loops < 42) /*doug adams*/						break;					/*FALLTHROUGH*/				case res_error:					/*FALLTHROUGH*/				default:					return (-1);				}			} while (!done);		}		Dprint(statp->options & RES_DEBUG,		       (stdout, ";; Querying server (# %d) address = %s\n",			ns + 1, inet_ntoa(nsap->sin_addr)));		if (v_circuit) {			/* Use VC; at most one attempt per server. */			try = statp->retry;			n = send_vc(statp, buf, buflen, ans, anssiz, &terrno,				    ns);			if (n < 0)				return (-1);			if (n == 0)				goto next_ns;			resplen = n;		} else {			/* Use datagrams. */			n = send_dg(statp, buf, buflen, ans, anssiz, &terrno,				    ns, &v_circuit, &gotsomewhere);			if (n < 0)				return (-1);			if (n == 0)				goto next_ns;			if (v_circuit)				goto same_ns;			resplen = n;		}		Dprint((statp->options & RES_DEBUG) ||		       ((statp->pfcode & RES_PRF_REPLY) &&			(statp->pfcode & RES_PRF_HEAD1)),		       (stdout, ";; got answer:\n"));		DprintQ((statp->options & RES_DEBUG) ||			(statp->pfcode & RES_PRF_REPLY),			(stdout, ""),			ans, (resplen > anssiz) ? anssiz : resplen);		/*		 * If we have temporarily opened a virtual circuit,		 * or if we haven't been asked to keep a socket open,		 * close the socket.		 */		if ((v_circuit && (statp->options & RES_USEVC) == 0) ||		    (statp->options & RES_STAYOPEN) == 0) {			res_nclose(statp);		}		if (statp->rhook) {			int done = 0, loops = 0;			do {				res_sendhookact act;				act = (*statp->rhook)(nsap, buf, buflen,						      ans, anssiz, &resplen);				switch (act) {				case res_goahead:				case res_done:					done = 1;					break;				case res_nextns:					res_nclose(statp);					goto next_ns;				case res_modified:					/* give the hook another try */					if (++loops < 42) /*doug adams*/						break;					/*FALLTHROUGH*/				case res_error:					/*FALLTHROUGH*/				default:					return (-1);				}			} while (!done);		}		return (resplen); next_ns: ;	   } /*foreach ns*/	} /*foreach retry*/	res_nclose(statp);	if (!v_circuit) {		if (!gotsomewhere)			__set_errno (ECONNREFUSED);	/* no nameservers found */		else			__set_errno (ETIMEDOUT);	/* no answer obtained */	} else		__set_errno (terrno);	return (-1);}