Lines Matching defs:statp

172 res_ourserver_p(const res_state statp, const struct sockaddr *sa) {
180 for (ns = 0; ns < statp->nscount; ns++) {
181 srv = (struct sockaddr_in *)get_nsaddr(statp, ns);
190 if (EXT(statp).ext == NULL)
193 for (ns = 0; ns < statp->nscount; ns++) {
194 srv6 = (struct sockaddr_in6 *)get_nsaddr(statp, ns);
303 res_nsend(res_state statp,
313 if (statp->nscount == 0 || EXT(statp).ext == NULL) {
321 DprintQ((statp->options & RES_DEBUG) || (statp->pfcode & RES_PRF_QUERY),
323 v_circuit = (statp->options & RES_USEVC) || buflen > PACKETSZ;
329 Perror(statp, stderr, "kqueue", errno);
338 if (EXT(statp).nscount != 0) {
343 if (EXT(statp).nscount != statp->nscount)
346 for (ns = 0; ns < statp->nscount; ns++) {
347 if (statp->nsaddr_list[ns].sin_family &&
348 !sock_eq((struct sockaddr *)&statp->nsaddr_list[ns],
349 (struct sockaddr *)&EXT(statp).ext->nsaddrs[ns])) {
354 if (EXT(statp).nssocks[ns] == -1)
357 if (_getpeername(EXT(statp).nssocks[ns],
363 get_nsaddr(statp, ns))) {
369 res_nclose(statp);
370 EXT(statp).nscount = 0;
377 if (EXT(statp).nscount == 0) {
378 for (ns = 0; ns < statp->nscount; ns++) {
379 EXT(statp).nstimes[ns] = RES_MAXTIME;
380 EXT(statp).nssocks[ns] = -1;
381 if (!statp->nsaddr_list[ns].sin_family)
383 EXT(statp).ext->nsaddrs[ns].sin =
384 statp->nsaddr_list[ns];
386 EXT(statp).nscount = statp->nscount;
393 if ((statp->options & RES_ROTATE) != 0U &&
394 (statp->options & RES_BLAST) == 0U) {
397 int lastns = statp->nscount - 1;
401 if (EXT(statp).ext != NULL)
402 inu = EXT(statp).ext->nsaddrs[0];
403 ina = statp->nsaddr_list[0];
404 fd = EXT(statp).nssocks[0];
405 nstime = EXT(statp).nstimes[0];
407 if (EXT(statp).ext != NULL)
408 EXT(statp).ext->nsaddrs[ns] =
409 EXT(statp).ext->nsaddrs[ns + 1];
410 statp->nsaddr_list[ns] = statp->nsaddr_list[ns + 1];
411 EXT(statp).nssocks[ns] = EXT(statp).nssocks[ns + 1];
412 EXT(statp).nstimes[ns] = EXT(statp).nstimes[ns + 1];
414 if (EXT(statp).ext != NULL)
415 EXT(statp).ext->nsaddrs[lastns] = inu;
416 statp->nsaddr_list[lastns] = ina;
417 EXT(statp).nssocks[lastns] = fd;
418 EXT(statp).nstimes[lastns] = nstime;
424 for (tries = 0; tries < statp->retry; tries++) {
425 for (ns = 0; ns < statp->nscount; ns++) {
428 nsap = get_nsaddr(statp, ns);
430 statp->_flags &= ~RES_F_LASTMASK;
431 statp->_flags |= (ns << RES_F_LASTSHIFT);
433 if (statp->qhook) {
439 act = (*statp->qhook)(&nsap, &buf, &buflen,
446 res_nclose(statp);
466 Dprint(((statp->options & RES_DEBUG) &&
475 tries = statp->retry;
476 n = send_vc(statp, buf, buflen, ans, anssiz, &terrno,
485 n = send_dg(statp,
500 Dprint((statp->options & RES_DEBUG) ||
501 ((statp->pfcode & RES_PRF_REPLY) &&
502 (statp->pfcode & RES_PRF_HEAD1)),
505 DprintQ((statp->options & RES_DEBUG) ||
506 (statp->pfcode & RES_PRF_REPLY),
515 if ((v_circuit && (statp->options & RES_USEVC) == 0U) ||
516 (statp->options & RES_STAYOPEN) == 0U) {
517 res_nclose(statp);
519 if (statp->rhook) {
525 act = (*statp->rhook)(nsap, buf, buflen,
533 res_nclose(statp);
555 res_nclose(statp);
568 res_nclose(statp);
599 get_nsaddr(res_state statp, size_t n)
602 if (!statp->nsaddr_list[n].sin_family && EXT(statp).ext) {
604 * - EXT(statp).ext->nsaddrs[n] holds an address that is larger
606 * - user code did not update statp->nsaddr_list[n].
608 return (struct sockaddr *)(void *)&EXT(statp).ext->nsaddrs[n];
611 * - user code updated statp->nsaddr_list[n], or
612 * - statp->nsaddr_list[n] has the same content as
613 * EXT(statp).ext->nsaddrs[n].
615 return (struct sockaddr *)(void *)&statp->nsaddr_list[n];
620 send_vc(res_state statp,
637 nsap = get_nsaddr(statp, ns);
645 if (statp->_vcsock >= 0 && (statp->_flags & RES_F_VC) != 0) {
649 if (_getpeername(statp->_vcsock,
652 res_nclose(statp);
653 statp->_flags &= ~RES_F_VC;
657 if (statp->_vcsock < 0 || (statp->_flags & RES_F_VC) == 0) {
658 if (statp->_vcsock >= 0)
659 res_nclose(statp);
661 statp->_vcsock = _socket(nsap->sa_family, SOCK_STREAM |
664 if (statp->_vcsock > highestFD) {
665 res_nclose(statp);
669 if (statp->_vcsock < 0) {
676 Perror(statp, stderr, "socket(vc)", errno);
680 Perror(statp, stderr, "socket(vc)", errno);
692 (void)_setsockopt(statp->_vcsock, SOL_SOCKET, SO_NOSIGPIPE, &on,
696 if (_connect(statp->_vcsock, nsap, nsaplen) < 0) {
698 Aerror(statp, stderr, "connect/vc", errno, nsap,
700 res_nclose(statp);
703 statp->_flags |= RES_F_VC;
713 if (_writev(statp->_vcsock, iov, 2) != (INT16SZ + buflen)) {
715 Perror(statp, stderr, "write failed", errno);
716 res_nclose(statp);
725 while ((n = _read(statp->_vcsock, (char *)cp, (int)len)) > 0) {
732 Perror(statp, stderr, "read failed", errno);
733 res_nclose(statp);
745 res_nclose(statp);
748 res_nclose(statp);
753 Dprint(statp->options & RES_DEBUG,
764 Dprint(statp->options & RES_DEBUG,
767 res_nclose(statp);
772 (n = _read(statp->_vcsock, (char *)cp, (int)len)) > 0) {
778 Perror(statp, stderr, "read(vc)", errno);
779 res_nclose(statp);
791 n = _read(statp->_vcsock, junk,
807 DprintQ((statp->options & RES_DEBUG) ||
808 (statp->pfcode & RES_PRF_REPLY),
822 send_dg(res_state statp,
849 nsap = get_nsaddr(statp, ns);
851 if (EXT(statp).nssocks[ns] == -1) {
852 EXT(statp).nssocks[ns] = _socket(nsap->sa_family,
855 if (EXT(statp).nssocks[ns] > highestFD) {
856 res_nclose(statp);
860 if (EXT(statp).nssocks[ns] < 0) {
867 Perror(statp, stderr, "socket(dg)", errno);
871 Perror(statp, stderr, "socket(dg)", errno);
894 if (!(statp->options & RES_INSECURE1) &&
895 _connect(EXT(statp).nssocks[ns], nsap, nsaplen) < 0) {
896 Aerror(statp, stderr, "connect(dg)", errno, nsap,
898 res_nclose(statp);
902 Dprint(statp->options & RES_DEBUG,
905 s = EXT(statp).nssocks[ns];
907 if (statp->options & RES_INSECURE1) {
910 Aerror(statp, stderr, "sendto", errno, nsap, nsaplen);
911 res_nclose(statp);
915 Perror(statp, stderr, "send", errno);
916 res_nclose(statp);
922 Aerror(statp, stderr, "sendto", errno, nsap, nsaplen);
923 res_nclose(statp);
931 seconds = (statp->retrans << tries);
933 seconds /= statp->nscount;
968 Dprint(statp->options & RES_DEBUG, (stdout, ";; timeout\n"));
976 Perror(statp, stderr, "kevent", errno);
979 Perror(statp, stderr, "select", errno);
981 Perror(statp, stderr, "poll", errno);
984 res_nclose(statp);
996 Perror(statp, stderr, "recvfrom", errno);
997 res_nclose(statp);
1005 Dprint(statp->options & RES_DEBUG,
1009 res_nclose(statp);
1018 DprintQ((statp->options & RES_DEBUG) ||
1019 (statp->pfcode & RES_PRF_REPLY),
1024 if (!(statp->options & RES_INSECURE1) &&
1025 !res_ourserver_p(statp, (struct sockaddr *)&from)) {
1031 DprintQ((statp->options & RES_DEBUG) ||
1032 (statp->pfcode & RES_PRF_REPLY),
1038 if (anhp->rcode == FORMERR && (statp->options & RES_USE_EDNS0) != 0U) {
1044 DprintQ(statp->options & RES_DEBUG,
1048 statp->_flags |= RES_F_EDNS0ERR;
1049 res_nclose(statp);
1053 if (!(statp->options & RES_INSECURE2) &&
1061 DprintQ((statp->options & RES_DEBUG) ||
1062 (statp->pfcode & RES_PRF_REPLY),
1070 DprintQ(statp->options & RES_DEBUG,
1073 res_nclose(statp);
1075 if (!statp->pfcode)
1078 if (!(statp->options & RES_IGNTC) && anhp->tc) {
1083 Dprint(statp->options & RES_DEBUG,
1086 res_nclose(statp);
1097 Aerror(const res_state statp, FILE *file, const char *string, int error,
1104 if ((statp->options & RES_DEBUG) != 0U) {
1119 Perror(const res_state statp, FILE *file, const char *string, int error) {
1122 if ((statp->options & RES_DEBUG) != 0U)