Lines Matching defs:statp

194 res_ourserver_p(const res_state statp, const struct sockaddr *sa) {
202 for (ns = 0; ns < statp->nscount; ns++) {
203 srv = (struct sockaddr_in *)(void *)get_nsaddr(statp, (size_t)ns);
212 if (EXT(statp).ext == NULL)
215 for (ns = 0; ns < statp->nscount; ns++) {
216 srv6 = (struct sockaddr_in6 *)(void *)get_nsaddr(statp, (size_t)ns);
325 res_nsend(res_state statp,
337 if (statp->nscount == 0 || EXT(statp).ext == NULL) {
345 DprintQ((statp->options & RES_DEBUG) || (statp->pfcode & RES_PRF_QUERY),
347 v_circuit = (statp->options & RES_USEVC) || buflen > PACKETSZ;
361 if (EXT(statp).nscount != 0) {
366 if (EXT(statp).nscount != statp->nscount)
369 for (ns = 0; ns < statp->nscount; ns++) {
370 if (statp->nsaddr_list[ns].sin_family &&
371 !sock_eq((struct sockaddr *)(void *)&statp->nsaddr_list[ns],
372 (struct sockaddr *)(void *)&EXT(statp).ext->nsaddrs[ns])) {
377 if (EXT(statp).nssocks[ns] == -1)
380 if (getpeername(EXT(statp).nssocks[ns],
386 get_nsaddr(statp, (size_t)ns))) {
392 res_nclose(statp);
393 EXT(statp).nscount = 0;
400 if (EXT(statp).nscount == 0) {
401 for (ns = 0; ns < statp->nscount; ns++) {
402 EXT(statp).nstimes[ns] = RES_MAXTIME;
403 EXT(statp).nssocks[ns] = -1;
404 if (!statp->nsaddr_list[ns].sin_family)
406 EXT(statp).ext->nsaddrs[ns].sin =
407 statp->nsaddr_list[ns];
409 EXT(statp).nscount = statp->nscount;
416 if ((statp->options & RES_ROTATE) != 0U &&
417 (statp->options & RES_BLAST) == 0U) {
420 int lastns = statp->nscount - 1;
424 if (EXT(statp).ext != NULL)
425 inu = EXT(statp).ext->nsaddrs[0];
426 ina = statp->nsaddr_list[0];
427 fd = EXT(statp).nssocks[0];
428 nstime = EXT(statp).nstimes[0];
430 if (EXT(statp).ext != NULL)
431 EXT(statp).ext->nsaddrs[ns] =
432 EXT(statp).ext->nsaddrs[ns + 1];
433 statp->nsaddr_list[ns] = statp->nsaddr_list[ns + 1];
434 EXT(statp).nssocks[ns] = EXT(statp).nssocks[ns + 1];
435 EXT(statp).nstimes[ns] = EXT(statp).nstimes[ns + 1];
437 if (EXT(statp).ext != NULL)
438 EXT(statp).ext->nsaddrs[lastns] = inu;
439 statp->nsaddr_list[lastns] = ina;
440 EXT(statp).nssocks[lastns] = fd;
441 EXT(statp).nstimes[lastns] = nstime;
447 for (tries = 0; tries < statp->retry; tries++) {
448 for (ns = 0; ns < statp->nscount; ns++) {
451 nsap = get_nsaddr(statp, (size_t)ns);
453 statp->_flags &= ~RES_F_LASTMASK;
454 statp->_flags |= (ns << RES_F_LASTSHIFT);
456 if (statp->qhook) {
462 act = (*(res_send_qhook)statp->qhook)(&nsap, &buf, &buflen,
469 res_nclose(statp);
489 Dprint(((statp->options & RES_DEBUG) &&
498 tries = statp->retry;
499 n = send_vc(statp, buf, (size_t)buflen, ans, anssiz, &terrno,
508 n = send_dg(statp,
523 Dprint((statp->options & RES_DEBUG) ||
524 ((statp->pfcode & RES_PRF_REPLY) &&
525 (statp->pfcode & RES_PRF_HEAD1)),
528 DprintQ((statp->options & RES_DEBUG) ||
529 (statp->pfcode & RES_PRF_REPLY),
538 if ((v_circuit && (statp->options & RES_USEVC) == 0U) ||
539 (statp->options & RES_STAYOPEN) == 0U) {
540 res_nclose(statp);
542 if (statp->rhook) {
548 act = (*(res_send_rhook)statp->rhook)(nsap, buf, buflen,
556 res_nclose(statp);
578 res_nclose(statp);
591 res_nclose(statp);
622 get_nsaddr(res_state statp, size_t n)
625 if (!statp->nsaddr_list[n].sin_family && EXT(statp).ext) {
627 * - EXT(statp).ext->nsaddrs[n] holds an address that is larger
629 * - user code did not update statp->nsaddr_list[n].
631 return (struct sockaddr *)(void *)&EXT(statp).ext->nsaddrs[n];
634 * - user code updated statp->nsaddr_list[n], or
635 * - statp->nsaddr_list[n] has the same content as
636 * EXT(statp).ext->nsaddrs[n].
638 return (struct sockaddr *)(void *)&statp->nsaddr_list[n];
643 send_vc(res_state statp,
661 nsap = get_nsaddr(statp, (size_t)ns);
669 if (statp->_vcsock >= 0 && (statp->_flags & RES_F_VC) != 0) {
673 if (getpeername(statp->_vcsock,
676 res_nclose(statp);
677 statp->_flags &= ~RES_F_VC;
681 if (statp->_vcsock < 0 || (statp->_flags & RES_F_VC) == 0) {
682 if (statp->_vcsock >= 0)
683 res_nclose(statp);
689 statp->_vcsock = socket(nsap->sa_family, SOCK_STREAM
692 fcntl(statp->_vcsock, F_SETFD, FD_CLOEXEC);
695 if (statp->_vcsock > highestFD) {
696 res_nclose(statp);
700 if (statp->_vcsock < 0) {
707 Perror(statp, stderr, "socket(vc)", errno);
711 Perror(statp, stderr, "socket(vc)", errno);
723 (void)setsockopt(statp->_vcsock, SOL_SOCKET, SO_NOSIGPIPE, &on,
727 if (connect(statp->_vcsock, nsap, nsaplen) < 0) {
729 Aerror(statp, stderr, "connect/vc", errno, nsap,
731 res_nclose(statp);
734 statp->_flags |= RES_F_VC;
744 if (writev(statp->_vcsock, iov, 2) != (ssize_t)(INT16SZ + buflen)) {
746 Perror(statp, stderr, "write failed", errno);
747 res_nclose(statp);
756 while ((n = read(statp->_vcsock, (char *)cp, (size_t)len)) > 0) {
763 Perror(statp, stderr, "read failed", errno);
764 res_nclose(statp);
776 res_nclose(statp);
779 res_nclose(statp);
784 Dprint(statp->options & RES_DEBUG,
795 Dprint(statp->options & RES_DEBUG,
798 res_nclose(statp);
802 while (len != 0 && (n = read(statp->_vcsock, (char *)cp, (size_t)len)) > 0){
808 Perror(statp, stderr, "read(vc)", errno);
809 res_nclose(statp);
821 n = read(statp->_vcsock, junk,
837 DprintQ((statp->options & RES_DEBUG) ||
838 (statp->pfcode & RES_PRF_REPLY),
852 send_dg(res_state statp,
880 nsap = get_nsaddr(statp, (size_t)ns);
882 if (EXT(statp).nssocks[ns] == -1) {
883 EXT(statp).nssocks[ns] = socket(nsap->sa_family, SOCK_DGRAM
886 fcntl(EXT(statp).nssocks[ns], F_SETFD, FD_CLOEXEC);
889 if (EXT(statp).nssocks[ns] > highestFD) {
890 res_nclose(statp);
894 if (EXT(statp).nssocks[ns] < 0) {
901 Perror(statp, stderr, "socket(dg)", errno);
905 Perror(statp, stderr, "socket(dg)", errno);
928 if (!(statp->options & RES_INSECURE1) &&
929 connect(EXT(statp).nssocks[ns], nsap, nsaplen) < 0) {
930 Aerror(statp, stderr, "connect(dg)", errno, nsap,
932 res_nclose(statp);
936 Dprint(statp->options & RES_DEBUG,
939 s = EXT(statp).nssocks[ns];
941 if (statp->options & RES_INSECURE1) {
944 Aerror(statp, stderr, "sendto", errno, nsap, nsaplen);
945 res_nclose(statp);
949 Perror(statp, stderr, "send", errno);
950 res_nclose(statp);
956 Aerror(statp, stderr, "sendto", errno, nsap, nsaplen);
957 res_nclose(statp);
965 seconds = (statp->retrans << tries);
967 seconds /= statp->nscount;
1002 Dprint(statp->options & RES_DEBUG, (stdout, ";; timeout\n"));
1018 Perror(statp, stderr, fun, errno);
1019 res_nclose(statp);
1031 Perror(statp, stderr, "recvfrom", errno);
1032 res_nclose(statp);
1040 Dprint(statp->options & RES_DEBUG,
1044 res_nclose(statp);
1053 DprintQ((statp->options & RES_DEBUG) ||
1054 (statp->pfcode & RES_PRF_REPLY),
1059 if (!(statp->options & RES_INSECURE1) &&
1060 !res_ourserver_p(statp, (struct sockaddr *)(void *)&from)) {
1066 DprintQ((statp->options & RES_DEBUG) ||
1067 (statp->pfcode & RES_PRF_REPLY),
1073 if (anhp->rcode == FORMERR && (statp->options & RES_USE_EDNS0) != 0U) {
1079 DprintQ(statp->options & RES_DEBUG,
1083 statp->_flags |= RES_F_EDNS0ERR;
1084 res_nclose(statp);
1088 if (!(statp->options & RES_INSECURE2) &&
1096 DprintQ((statp->options & RES_DEBUG) ||
1097 (statp->pfcode & RES_PRF_REPLY),
1105 DprintQ(statp->options & RES_DEBUG,
1108 res_nclose(statp);
1110 if (!statp->pfcode)
1113 if (!(statp->options & RES_IGNTC) && anhp->tc) {
1118 Dprint(statp->options & RES_DEBUG,
1121 res_nclose(statp);
1135 Aerror(const res_state statp, FILE *file, const char *string, int error,
1144 if ((statp->options & RES_DEBUG) != 0U) {
1160 Perror(const res_state statp, FILE *file, const char *string, int error) {
1163 if ((statp->options & RES_DEBUG) != 0U)