Alien-cares
view release on metacpan or search on metacpan
libcares/ares_process.c view on Meta::CPAN
{
struct {
const unsigned char *p;
int qdcount;
char *name;
long namelen;
int type;
int dnsclass;
} q, a;
int i, j;
if (qlen < HFIXEDSZ || alen < HFIXEDSZ)
return 0;
/* Extract qdcount from the request and reply buffers and compare them. */
q.qdcount = DNS_HEADER_QDCOUNT(qbuf);
a.qdcount = DNS_HEADER_QDCOUNT(abuf);
if (q.qdcount != a.qdcount)
return 0;
/* For each question in qbuf, find it in abuf. */
q.p = qbuf + HFIXEDSZ;
for (i = 0; i < q.qdcount; i++)
{
/* Decode the question in the query. */
if (ares_expand_name(q.p, qbuf, qlen, &q.name, &q.namelen)
!= ARES_SUCCESS)
return 0;
q.p += q.namelen;
if (q.p + QFIXEDSZ > qbuf + qlen)
{
ares_free(q.name);
return 0;
}
q.type = DNS_QUESTION_TYPE(q.p);
q.dnsclass = DNS_QUESTION_CLASS(q.p);
q.p += QFIXEDSZ;
/* Search for this question in the answer. */
a.p = abuf + HFIXEDSZ;
for (j = 0; j < a.qdcount; j++)
{
/* Decode the question in the answer. */
if (ares_expand_name(a.p, abuf, alen, &a.name, &a.namelen)
!= ARES_SUCCESS)
{
ares_free(q.name);
return 0;
}
a.p += a.namelen;
if (a.p + QFIXEDSZ > abuf + alen)
{
ares_free(q.name);
ares_free(a.name);
return 0;
}
a.type = DNS_QUESTION_TYPE(a.p);
a.dnsclass = DNS_QUESTION_CLASS(a.p);
a.p += QFIXEDSZ;
/* Compare the decoded questions. */
if (strcasecmp(q.name, a.name) == 0 && q.type == a.type
&& q.dnsclass == a.dnsclass)
{
ares_free(a.name);
break;
}
ares_free(a.name);
}
ares_free(q.name);
if (j == a.qdcount)
return 0;
}
return 1;
}
static int same_address(struct sockaddr *sa, struct ares_addr *aa)
{
void *addr1;
void *addr2;
if (sa->sa_family == aa->family)
{
switch (aa->family)
{
case AF_INET:
addr1 = &aa->addrV4;
addr2 = &((struct sockaddr_in *)sa)->sin_addr;
if (memcmp(addr1, addr2, sizeof(aa->addrV4)) == 0)
return 1; /* match */
break;
case AF_INET6:
addr1 = &aa->addrV6;
addr2 = &((struct sockaddr_in6 *)sa)->sin6_addr;
if (memcmp(addr1, addr2, sizeof(aa->addrV6)) == 0)
return 1; /* match */
break;
default:
break; /* LCOV_EXCL_LINE */
}
}
return 0; /* different */
}
static void end_query (ares_channel channel, struct query *query, int status,
unsigned char *abuf, int alen)
{
int i;
/* First we check to see if this query ended while one of our send
* queues still has pointers to it.
*/
for (i = 0; i < channel->nservers; i++)
{
struct server_state *server = &channel->servers[i];
struct send_request *sendreq;
for (sendreq = server->qhead; sendreq; sendreq = sendreq->next)
if (sendreq->owner_query == query)
{
sendreq->owner_query = NULL;
( run in 1.610 second using v1.01-cache-2.11-cpan-ed4147ee29a )