int id;
time_t ttl;
char type;
- char queryname[128]; /* name currently being queried */
+ char queryname[IRCD_RES_HOSTLEN + 1]; /* name currently being queried */
char retries; /* retry counter */
char sends; /* number of sends (>1 means resent) */
time_t sentat;
static void do_query_name(struct DNSQuery *query, const char *name, struct reslist *request,
int type)
{
- char host_name[HOSTLEN + 1];
+ char host_name[IRCD_RES_HOSTLEN + 1];
- rb_strlcpy(host_name, name, HOSTLEN + 1);
- add_local_domain(host_name, HOSTLEN);
+ rb_strlcpy(host_name, name, IRCD_RES_HOSTLEN + 1);
+ add_local_domain(host_name, IRCD_RES_HOSTLEN);
if (request == NULL)
{
{
request = make_request(query);
memcpy(&request->addr, addr, sizeof(struct rb_sockaddr_storage));
- request->name = (char *)rb_malloc(HOSTLEN + 1);
+ request->name = (char *)rb_malloc(IRCD_RES_HOSTLEN + 1);
}
if (addr->ss_family == AF_INET)
*/
static int check_question(struct reslist *request, HEADER * header, char *buf, char *eob)
{
- char hostbuf[128]; /* working buffer */
+ char hostbuf[IRCD_RES_HOSTLEN + 1]; /* working buffer */
unsigned char *current; /* current position in buf */
int n; /* temp count */
*/
static int proc_answer(struct reslist *request, HEADER * header, char *buf, char *eob)
{
- char hostbuf[HOSTLEN + 100]; /* working buffer */
+ char hostbuf[IRCD_RES_HOSTLEN + 100]; /* working buffer */
unsigned char *current; /* current position in buf */
int query_class; /* answer class */
int type; /* answer type */
return (0);
}
- hostbuf[HOSTLEN] = '\0';
+ hostbuf[IRCD_RES_HOSTLEN] = '\0';
/* With Address arithmetic you have to be very anal
* this code was not working on alpha due to that
else if (n == 0)
return (0); /* no more answers left */
- rb_strlcpy(request->name, hostbuf, HOSTLEN + 1);
+ rb_strlcpy(request->name, hostbuf, IRCD_RES_HOSTLEN + 1);
return (1);
break;
}
/*
- * res_readreply - read a dns reply from the nameserver and process it.
+ * res_read_single_reply - read a dns reply from the nameserver and process it.
+ * Return value: 1 if a packet was read, 0 otherwise
*/
-static void res_readreply(rb_fde_t *F, void *data)
+static int res_read_single_reply(rb_fde_t *F, void *data)
{
char buf[sizeof(HEADER) + MAXPACKET]
/* Sparc and alpha need 16bit-alignment for accessing header->id
rc = recvfrom(rb_get_fd(F), buf, sizeof(buf), 0, (struct sockaddr *)&lsin, &len);
- /* Re-schedule a read *after* recvfrom, or we'll be registering
- * interest where it'll instantly be ready for read :-) -- adrian
- */
- rb_setselect(F, RB_SELECT_READ, res_readreply, NULL);
- /* Better to cast the sizeof instead of rc */
+ /* No packet */
+ if (rc == 0 || rc == -1)
+ return 0;
+
+ /* Too small */
if (rc <= (int)(sizeof(HEADER)))
- return;
+ return 1;
/*
* convert DNS reply reader from Network byte order to CPU byte order.
* just ignore this response.
*/
if (0 == (request = find_id(header->id)))
- return;
+ return 1;
/*
* check against possibly fake replies
*/
if (!res_ourserver(&lsin))
- return;
+ return 1;
if (!check_question(request, header, buf, buf + rc))
- return;
+ return 1;
if ((header->rcode != NO_ERRORS) || (header->ancount == 0))
{
(*request->query->callback) (request->query->ptr, NULL);
rem_request(request);
}
- return;
+ return 1;
}
/*
* If this fails there was an error decoding the received packet,
*/
(*request->query->callback) (request->query->ptr, reply);
rem_request(request);
- return;
+ return 1;
}
/*
(*request->query->callback) (request->query->ptr, NULL);
rem_request(request);
}
+ return 1;
+}
+
+static void res_readreply(rb_fde_t *F, void *data)
+{
+ while (res_read_single_reply(F, data))
+ ;
+ rb_setselect(F, RB_SELECT_READ, res_readreply, NULL);
}
static struct DNSReply *make_dnsreply(struct reslist *request)