Lines Matching refs:statp

172 res_ourserver_p(const res_state statp, const struct sockaddr *sa) {  in res_ourserver_p()  argument
180 for (ns = 0; ns < statp->nscount; ns++) { in res_ourserver_p()
181 srv = (struct sockaddr_in *)get_nsaddr(statp, ns); in res_ourserver_p()
190 if (EXT(statp).ext == NULL) in res_ourserver_p()
193 for (ns = 0; ns < statp->nscount; ns++) { in res_ourserver_p()
194 srv6 = (struct sockaddr_in6 *)get_nsaddr(statp, ns); in res_ourserver_p()
303 res_nsend(res_state statp, in res_nsend() argument
314 if (statp->nscount == 0 || EXT(statp).ext == NULL) { in res_nsend()
322 DprintQ((statp->options & RES_DEBUG) || (statp->pfcode & RES_PRF_QUERY), in res_nsend()
324 v_circuit = (statp->options & RES_USEVC) || buflen > PACKETSZ; in res_nsend()
332 if (EXT(statp).nscount != 0) { in res_nsend()
337 if (EXT(statp).nscount != statp->nscount) in res_nsend()
340 for (ns = 0; ns < statp->nscount; ns++) { in res_nsend()
341 if (statp->nsaddr_list[ns].sin_family && in res_nsend()
342 !sock_eq((struct sockaddr *)&statp->nsaddr_list[ns], in res_nsend()
343 (struct sockaddr *)&EXT(statp).ext->nsaddrs[ns])) { in res_nsend()
348 if (EXT(statp).nssocks[ns] == -1) in res_nsend()
351 if (getpeername(EXT(statp).nssocks[ns], in res_nsend()
357 get_nsaddr(statp, ns))) { in res_nsend()
363 res_nclose(statp); in res_nsend()
364 EXT(statp).nscount = 0; in res_nsend()
371 if (EXT(statp).nscount == 0) { in res_nsend()
372 for (ns = 0; ns < statp->nscount; ns++) { in res_nsend()
373 EXT(statp).nstimes[ns] = RES_MAXTIME; in res_nsend()
374 EXT(statp).nssocks[ns] = -1; in res_nsend()
375 if (!statp->nsaddr_list[ns].sin_family) in res_nsend()
377 EXT(statp).ext->nsaddrs[ns].sin = in res_nsend()
378 statp->nsaddr_list[ns]; in res_nsend()
380 EXT(statp).nscount = statp->nscount; in res_nsend()
387 if ((statp->options & RES_ROTATE) != 0U && in res_nsend()
388 (statp->options & RES_BLAST) == 0U) { in res_nsend()
391 int lastns = statp->nscount - 1; in res_nsend()
395 if (EXT(statp).ext != NULL) in res_nsend()
396 inu = EXT(statp).ext->nsaddrs[0]; in res_nsend()
397 ina = statp->nsaddr_list[0]; in res_nsend()
398 fd = EXT(statp).nssocks[0]; in res_nsend()
399 nstime = EXT(statp).nstimes[0]; in res_nsend()
401 if (EXT(statp).ext != NULL) in res_nsend()
402 EXT(statp).ext->nsaddrs[ns] = in res_nsend()
403 EXT(statp).ext->nsaddrs[ns + 1]; in res_nsend()
404 statp->nsaddr_list[ns] = statp->nsaddr_list[ns + 1]; in res_nsend()
405 EXT(statp).nssocks[ns] = EXT(statp).nssocks[ns + 1]; in res_nsend()
406 EXT(statp).nstimes[ns] = EXT(statp).nstimes[ns + 1]; in res_nsend()
408 if (EXT(statp).ext != NULL) in res_nsend()
409 EXT(statp).ext->nsaddrs[lastns] = inu; in res_nsend()
410 statp->nsaddr_list[lastns] = ina; in res_nsend()
411 EXT(statp).nssocks[lastns] = fd; in res_nsend()
412 EXT(statp).nstimes[lastns] = nstime; in res_nsend()
418 for (tries = 0; tries < statp->retry; tries++) { in res_nsend()
419 for (ns = 0; ns < statp->nscount; ns++) { in res_nsend()
422 nsap = get_nsaddr(statp, ns); in res_nsend()
424 statp->_flags &= ~RES_F_LASTMASK; in res_nsend()
425 statp->_flags |= (ns << RES_F_LASTSHIFT); in res_nsend()
427 if (statp->qhook) { in res_nsend()
433 act = (*statp->qhook)(&nsap, &buf, &buflen, in res_nsend()
440 res_nclose(statp); in res_nsend()
457 Dprint(((statp->options & RES_DEBUG) && in res_nsend()
466 tries = statp->retry; in res_nsend()
467 n = send_vc(statp, buf, buflen, ans, anssiz, &terrno, in res_nsend()
476 n = send_dg(statp, buf, buflen, ans, anssiz, &terrno, in res_nsend()
487 Dprint((statp->options & RES_DEBUG) || in res_nsend()
488 ((statp->pfcode & RES_PRF_REPLY) && in res_nsend()
489 (statp->pfcode & RES_PRF_HEAD1)), in res_nsend()
492 DprintQ((statp->options & RES_DEBUG) || in res_nsend()
493 (statp->pfcode & RES_PRF_REPLY), in res_nsend()
502 if ((v_circuit && (statp->options & RES_USEVC) == 0U) || in res_nsend()
503 (statp->options & RES_STAYOPEN) == 0U) { in res_nsend()
504 res_nclose(statp); in res_nsend()
506 if (statp->rhook) { in res_nsend()
512 act = (*statp->rhook)(nsap, buf, buflen, in res_nsend()
520 res_nclose(statp); in res_nsend()
539 res_nclose(statp); in res_nsend()
549 res_nclose(statp); in res_nsend()
578 get_nsaddr(statp, n) in get_nsaddr() argument
579 res_state statp; in get_nsaddr()
583 if (!statp->nsaddr_list[n].sin_family && EXT(statp).ext) {
589 return (struct sockaddr *)(void *)&EXT(statp).ext->nsaddrs[n];
596 return (struct sockaddr *)(void *)&statp->nsaddr_list[n];
601 send_vc(res_state statp, in send_vc() argument
618 nsap = get_nsaddr(statp, ns); in send_vc()
626 if (statp->_vcsock >= 0 && (statp->_flags & RES_F_VC) != 0) { in send_vc()
630 if (getpeername(statp->_vcsock, in send_vc()
633 res_nclose(statp); in send_vc()
634 statp->_flags &= ~RES_F_VC; in send_vc()
638 if (statp->_vcsock < 0 || (statp->_flags & RES_F_VC) == 0) { in send_vc()
639 if (statp->_vcsock >= 0) in send_vc()
640 res_nclose(statp); in send_vc()
642 statp->_vcsock = socket(nsap->sa_family, SOCK_STREAM, 0); in send_vc()
643 if (statp->_vcsock > highestFD) { in send_vc()
644 res_nclose(statp); in send_vc()
647 if (statp->_vcsock < 0) { in send_vc()
654 Perror(statp, stderr, "socket(vc)", errno); in send_vc()
658 Perror(statp, stderr, "socket(vc)", errno); in send_vc()
670 (void)setsockopt(statp->_vcsock, SOL_SOCKET, SO_NOSIGPIPE, &on, in send_vc()
690 conn_tmo = statp->retrans * 2000; /* mSec */ in send_vc()
691 (void)setsockopt(statp->_vcsock, IPPROTO_TCP, in send_vc()
697 if (connect(statp->_vcsock, nsap, nsaplen) < 0) { in send_vc()
699 Aerror(statp, stderr, "connect/vc", errno, nsap, in send_vc()
701 res_nclose(statp); in send_vc()
704 statp->_flags |= RES_F_VC; in send_vc()
714 if (writev(statp->_vcsock, iov, 2) != (INT16SZ + buflen)) { in send_vc()
716 Perror(statp, stderr, "write failed", errno); in send_vc()
717 res_nclose(statp); in send_vc()
726 while ((n = read(statp->_vcsock, (char *)cp, (int)len)) > 0) { in send_vc()
733 Perror(statp, stderr, "read failed", errno); in send_vc()
734 res_nclose(statp); in send_vc()
746 res_nclose(statp); in send_vc()
749 res_nclose(statp); in send_vc()
754 Dprint(statp->options & RES_DEBUG, in send_vc()
765 Dprint(statp->options & RES_DEBUG, in send_vc()
768 res_nclose(statp); in send_vc()
772 while (len != 0 && (n = read(statp->_vcsock, (char *)cp, (int)len)) > 0){ in send_vc()
778 Perror(statp, stderr, "read(vc)", errno); in send_vc()
779 res_nclose(statp); in send_vc()
791 n = read(statp->_vcsock, junk, in send_vc()
807 DprintQ((statp->options & RES_DEBUG) || in send_vc()
808 (statp->pfcode & RES_PRF_REPLY), in send_vc()
822 send_dg(res_state statp, const u_char *buf, int buflen, u_char *ans, in send_dg() argument
841 nsap = get_nsaddr(statp, ns); in send_dg()
843 if (EXT(statp).nssocks[ns] == -1) { in send_dg()
844 EXT(statp).nssocks[ns] = socket(nsap->sa_family, SOCK_DGRAM, 0); in send_dg()
845 if (EXT(statp).nssocks[ns] > highestFD) { in send_dg()
846 res_nclose(statp); in send_dg()
849 if (EXT(statp).nssocks[ns] < 0) { in send_dg()
856 Perror(statp, stderr, "socket(dg)", errno); in send_dg()
860 Perror(statp, stderr, "socket(dg)", errno); in send_dg()
876 if (connect(EXT(statp).nssocks[ns], nsap, nsaplen) < 0) { in send_dg()
877 Aerror(statp, stderr, "connect(dg)", errno, nsap, in send_dg()
879 res_nclose(statp); in send_dg()
883 Dprint(statp->options & RES_DEBUG, in send_dg()
886 s = EXT(statp).nssocks[ns]; in send_dg()
889 Perror(statp, stderr, "send", errno); in send_dg()
890 res_nclose(statp); in send_dg()
896 Aerror(statp, stderr, "sendto", errno, nsap, nsaplen); in send_dg()
897 res_nclose(statp); in send_dg()
905 seconds = (statp->retrans << tries); in send_dg()
907 seconds /= statp->nscount; in send_dg()
937 Dprint(statp->options & RES_DEBUG, (stdout, ";; timeout\n")); in send_dg()
945 Perror(statp, stderr, "select", errno); in send_dg()
947 Perror(statp, stderr, "poll", errno); in send_dg()
949 res_nclose(statp); in send_dg()
957 Perror(statp, stderr, "recvfrom", errno); in send_dg()
958 res_nclose(statp); in send_dg()
966 Dprint(statp->options & RES_DEBUG, in send_dg()
970 res_nclose(statp); in send_dg()
979 DprintQ((statp->options & RES_DEBUG) || in send_dg()
980 (statp->pfcode & RES_PRF_REPLY), in send_dg()
985 if (!(statp->options & RES_INSECURE1) && in send_dg()
986 !res_ourserver_p(statp, (struct sockaddr *)&from)) { in send_dg()
992 DprintQ((statp->options & RES_DEBUG) || in send_dg()
993 (statp->pfcode & RES_PRF_REPLY), in send_dg()
999 if (anhp->rcode == FORMERR && (statp->options & RES_USE_EDNS0) != 0U) { in send_dg()
1005 DprintQ(statp->options & RES_DEBUG, in send_dg()
1009 statp->_flags |= RES_F_EDNS0ERR; in send_dg()
1010 res_nclose(statp); in send_dg()
1014 if (!(statp->options & RES_INSECURE2) && in send_dg()
1022 DprintQ((statp->options & RES_DEBUG) || in send_dg()
1023 (statp->pfcode & RES_PRF_REPLY), in send_dg()
1031 DprintQ(statp->options & RES_DEBUG, in send_dg()
1034 res_nclose(statp); in send_dg()
1036 if (!statp->pfcode) in send_dg()
1039 if (!(statp->options & RES_IGNTC) && anhp->tc) { in send_dg()
1044 Dprint(statp->options & RES_DEBUG, in send_dg()
1047 res_nclose(statp); in send_dg()
1058 Aerror(const res_state statp, FILE *file, const char *string, int error, in Aerror() argument
1067 if ((statp->options & RES_DEBUG) != 0U) { in Aerror()
1082 Perror(const res_state statp, FILE *file, const char *string, int error) { in Perror() argument
1085 if ((statp->options & RES_DEBUG) != 0U) in Perror()