Lines Matching refs:statp

379 res_ourserver_p(const res_state statp, const struct sockaddr *sa)
389 for (ns = 0; ns < statp->nscount; ns++)
391 srv = (struct sockaddr_in *)get_nsaddr(statp, ns);
400 if (EXT(statp).ext == NULL) break;
402 for (ns = 0; ns < statp->nscount; ns++)
404 srv6 = (struct sockaddr_in6 *)get_nsaddr(statp, ns);
505 dns_res_send(res_state statp, const u_char *buf, int buflen, u_char *ans, int *anssiz, struct sockaddr *from, int *fromlen)
513 if (statp->nscount == 0)
526 DprintQ((statp->options & RES_DEBUG) || (statp->pfcode & RES_PRF_QUERY), (stdout, ";; res_send()\n"), buf, buflen);
528 v_circuit = (statp->options & RES_USEVC) || (buflen > NS_PACKETSZ);
537 if (EXT(statp).nscount != 0)
543 if (EXT(statp).nscount != statp->nscount)
549 for (ns = 0; ns < statp->nscount; ns++)
551 if ((statp->nsaddr_list[ns].sin_family) && (EXT(statp).ext != NULL) && (!sock_eq((struct sockaddr *)&statp->nsaddr_list[ns], (struct sockaddr *)&EXT(statp).ext->nsaddrs[ns])))
557 if (EXT(statp).nssocks[ns] == -1) continue;
560 if (getsockname(EXT(statp).nssocks[ns], (struct sockaddr *)&peer, &peerlen) < 0)
566 if (!sock_eq((struct sockaddr *)&peer, get_nsaddr(statp, ns)))
576 res_nclose(statp);
577 EXT(statp).nscount = 0;
584 if (EXT(statp).nscount == 0)
586 for (ns = 0; ns < statp->nscount; ns++)
588 EXT(statp).nstimes[ns] = RES_MAXTIME;
589 EXT(statp).nssocks[ns] = -1;
590 if (!statp->nsaddr_list[ns].sin_family) continue;
591 if (EXT(statp).ext != NULL) EXT(statp).ext->nsaddrs[ns].sin = statp->nsaddr_list[ns];
594 EXT(statp).nscount = statp->nscount;
601 if (((statp->options & RES_ROTATE) != 0) && ((statp->options & RES_BLAST) == 0))
605 int lastns = statp->nscount - 1;
609 if (EXT(statp).ext != NULL) inu = EXT(statp).ext->nsaddrs[0];
610 ina = statp->nsaddr_list[0];
611 fd = EXT(statp).nssocks[0];
612 nstime = EXT(statp).nstimes[0];
616 if (EXT(statp).ext != NULL)
618 EXT(statp).ext->nsaddrs[ns] =EXT(statp).ext->nsaddrs[ns + 1];
621 statp->nsaddr_list[ns] = statp->nsaddr_list[ns + 1];
622 EXT(statp).nssocks[ns] = EXT(statp).nssocks[ns + 1];
623 EXT(statp).nstimes[ns] = EXT(statp).nstimes[ns + 1];
626 if (EXT(statp).ext != NULL) EXT(statp).ext->nsaddrs[lastns] = inu;
627 statp->nsaddr_list[lastns] = ina;
628 EXT(statp).nssocks[lastns] = fd;
629 EXT(statp).nstimes[lastns] = nstime;
650 for (try = 0; try < statp->retry; try++)
652 for (ns = 0; ns < statp->nscount; ns++)
656 nsap = get_nsaddr(statp, ns);
661 if (statp->qhook)
669 act = (*statp->qhook)(&nsap, &buf, &buflen, ans, reply_buf_size, &resplen);
676 res_nclose(statp);
700 Dprint(statp->options & RES_DEBUG, (stdout, ";; cancelled\n"));
701 res_nclose(statp);
707 Dprint(((statp->options & RES_DEBUG) && getnameinfo(nsap, nsaplen, abuf, sizeof(abuf), NULL, 0, niflags) == 0), (stdout, ";; Querying server (# %d) address = %s\n", ns + 1, abuf));
714 try = statp->retry;
717 send_status = send_vc(statp, buf, buflen, ans, anssiz, &terrno, ns, from, fromlen, notify_token);
722 send_status = send_dg(statp, buf, buflen, ans, anssiz, &terrno, ns, &v_circuit, &gotsomewhere, from, fromlen, notify_token);
728 res_nclose(statp);
735 Dprint((statp->options & RES_DEBUG) || ((statp->pfcode & RES_PRF_REPLY) && (statp->pfcode & RES_PRF_HEAD1)), (stdout, ";; got answer:\n"));
736 DprintQ((statp->options & RES_DEBUG) || (statp->pfcode & RES_PRF_REPLY), (stdout, "%s", ""), ans, (*anssiz > reply_buf_size) ? reply_buf_size : *anssiz);
743 if (((v_circuit != 0) && (statp->options & RES_USEVC) == 0) || (statp->options & RES_STAYOPEN) == 0) res_nclose(statp);
745 if (statp->rhook)
753 act = (*statp->rhook)(nsap, buf, buflen, ans, *anssiz, &resplen);
761 res_nclose(statp);
770 res_nclose(statp);
785 res_nclose(statp);
807 res_nsend_2(res_state statp, const u_char *buf, int buflen, u_char *ans, int anssiz, struct sockaddr *from, int *fromlen)
812 status = dns_res_send(statp, buf, buflen, ans, &len, from, fromlen);
818 res_nsend(res_state statp, const u_char *buf, int buflen, u_char *ans, int anssiz)
825 return res_nsend_2(statp, buf, buflen, ans, anssiz, (struct sockaddr *)&from, &fromlen);
847 get_nsaddr(res_state statp, size_t n)
849 if ((!statp->nsaddr_list[n].sin_family) && (EXT(statp).ext != NULL))
852 * - EXT(statp).ext->nsaddrs[n] holds an address that is larger
854 * - user code did not update statp->nsaddr_list[n].
856 return (struct sockaddr *)(void *)&EXT(statp).ext->nsaddrs[n];
861 * - user code updated statp->nsaddr_list[n], or
862 * - statp->nsaddr_list[n] has the same content as
863 * EXT(statp).ext->nsaddrs[n].
865 return (struct sockaddr *)(void *)&statp->nsaddr_list[n];
870 send_vc(res_state statp, const u_char *buf, int buflen, u_char *ans, int *anssiz, int *terrno, int ns, struct sockaddr *from, int *fromlen, int notify_token)
884 nsap = get_nsaddr(statp, ns);
897 Dprint(statp->options & RES_DEBUG, (stdout, ";; cancelled\n"));
906 if (statp->_vcsock >= 0 && (statp->_flags & RES_F_VC) != 0)
911 if (getpeername(statp->_vcsock, (struct sockaddr *)&peer, &size) < 0 || !sock_eq((struct sockaddr *)&peer, nsap))
913 res_nclose(statp);
914 statp->_flags &= ~RES_F_VC;
918 if ((statp->_vcsock < 0) || ((statp->_flags & RES_F_VC) == 0))
920 if (statp->_vcsock >= 0) res_nclose(statp);
922 statp->_vcsock = socket(nsap->sa_family, SOCK_STREAM, 0);
923 if (statp->_vcsock > highestFD)
925 res_nclose(statp);
929 if (statp->_vcsock < 0)
932 Perror(statp, stderr, "socket(vc)", errno);
937 if (connect(statp->_vcsock, nsap, nsaplen) < 0)
940 Aerror(statp, stderr, "connect(vc)", errno, nsap, nsaplen);
941 res_nclose(statp);
945 statp->_flags |= RES_F_VC;
959 if (writev(statp->_vcsock, iov, 2) != (NS_INT16SZ + buflen))
962 Perror(statp, stderr, "write failed", errno);
963 res_nclose(statp);
978 Dprint(statp->options & RES_DEBUG, (stdout, ";; cancelled\n"));
986 while ((n = read(statp->_vcsock, (char *)cp, (int)len)) > 0)
995 Perror(statp, stderr, "read failed", errno);
996 res_nclose(statp);
1010 res_nclose(statp);
1014 res_nclose(statp);
1021 Dprint(statp->options & RES_DEBUG, (stdout, ";; response truncated\n"));
1035 Dprint(statp->options & RES_DEBUG, (stdout, ";; undersized: %d\n", len));
1037 res_nclose(statp);
1043 while (len != 0 && (n = read(statp->_vcsock, (char *)cp, (int)len)) > 0)
1052 Perror(statp, stderr, "read(vc)", errno);
1053 res_nclose(statp);
1068 n = read(statp->_vcsock, junk, (len > sizeof junk) ? sizeof junk : len);
1083 DprintQ((statp->options & RES_DEBUG) || (statp->pfcode & RES_PRF_REPLY), (stdout, ";; old answer (unexpected):\n"), ans, (resplen > *anssiz) ? *anssiz : resplen);
1154 send_dg(res_state statp, const u_char *buf, int buflen, u_char *ans, int *anssiz, int *terrno, int ns, int *v_circuit, int *gotsomewhere, struct sockaddr *from, int *fromlen, int notify_token)
1176 nsap = get_nsaddr(statp, ns);
1178 if (EXT(statp).nssocks[ns] == -1)
1180 EXT(statp).nssocks[ns] = socket(nsap->sa_family, SOCK_DGRAM, 0);
1181 if (EXT(statp).nssocks[ns] > highestFD)
1183 res_nclose(statp);
1187 if (EXT(statp).nssocks[ns] < 0)
1190 Perror(statp, stderr, "socket(dg)", errno);
1194 bind_random(EXT(statp).nssocks[ns]);
1208 if (connect(EXT(statp).nssocks[ns], nsap, nsaplen) < 0)
1210 Aerror(statp, stderr, "connect(dg)", errno, nsap, nsaplen);
1211 res_nclose(statp);
1216 Dprint(statp->options & RES_DEBUG, (stdout, ";; new DG socket\n"))
1219 s = EXT(statp).nssocks[ns];
1239 Aerror(statp, stderr, "getifaddrs", errno, nsap, nsaplen);
1240 res_nclose(statp);
1268 Aerror(statp, stderr, "setsockopt", errno, nsap, nsaplen);
1276 Aerror(statp, stderr, "sendto", errno, nsap, nsaplen);
1294 Perror(statp, stderr, "send", errno);
1295 res_nclose(statp);
1302 Aerror(statp, stderr, "sendto", errno, nsap, nsaplen);
1303 res_nclose(statp);
1316 ntry = statp->nscount * statp->retry;
1317 seconds = statp->retrans / ntry;
1320 timeout.tv_nsec = ((statp->retrans - (seconds * ntry)) * 1000) / ntry;
1327 seconds = (statp->retrans << ns);
1328 if (ns > 0) seconds /= statp->nscount;
1347 Dprint(statp->options & RES_DEBUG, (stdout, ";; cancelled\n"));
1375 Dprint(statp->options & RES_DEBUG, (stdout, ";; timeout\n"));
1383 Perror(statp, stderr, "select", errno);
1384 res_nclose(statp);
1391 Dprint(statp->options & RES_DEBUG, (stdout, ";; cancelled\n"));
1400 Perror(statp, stderr, "recvfrom", errno);
1401 res_nclose(statp);
1414 Dprint(statp->options & RES_DEBUG, (stdout, ";; undersized: %d\n", resplen));
1416 res_nclose(statp);
1427 DprintQ((statp->options & RES_DEBUG) || (statp->pfcode & RES_PRF_REPLY), (stdout, ";; old answer:\n"), ans, (resplen > *anssiz) ? *anssiz : resplen);
1436 if (!(statp->options & RES_INSECURE1) && !res_ourserver_p(statp, from))
1443 DprintQ((statp->options & RES_DEBUG) || (statp->pfcode & RES_PRF_REPLY), (stdout, ";; not our server:\n"), ans, (resplen > *anssiz) ? *anssiz : resplen);
1452 if (anhp->rcode == ns_r_formerr && (statp->options & RES_USE_EDNS0) != 0)
1459 DprintQ(statp->options & RES_DEBUG, (stdout, "server rejected query with EDNS0:\n"), ans, (resplen > *anssiz) ? *anssiz : resplen);
1461 statp->_flags |= RES_F_EDNS0ERR;
1462 res_nclose(statp);
1467 if (!(statp->options & RES_INSECURE2) && !res_queriesmatch(buf, buf + buflen, ans, ans + *anssiz))
1474 DprintQ((statp->options & RES_DEBUG) || (statp->pfcode & RES_PRF_REPLY), (stdout, ";; wrong query name:\n"), ans, (resplen > *anssiz) ? *anssiz : resplen);
1475 res_nclose(statp);
1481 DprintQ(statp->options & RES_DEBUG, (stdout, "server rejected query:\n"), ans, (resplen > *anssiz) ? *anssiz : resplen);
1482 res_nclose(statp);
1484 if (!statp->pfcode) return anhp->rcode;
1487 if (!(statp->options & RES_IGNTC) && anhp->tc)
1493 Dprint(statp->options & RES_DEBUG, (stdout, ";; truncated answer\n"));
1495 res_nclose(statp);
1508 Aerror(const res_state statp, FILE *file, const char *string, int error, const struct sockaddr *address, int alen)
1514 if ((statp->options & RES_DEBUG) != 0)
1531 Perror(const res_state statp, FILE *file, const char *string, int error)
1535 if ((statp->options & RES_DEBUG) != 0) fprintf(file, "res_send: %s: %s\n", string, strerror(error));