* The authors takes no responsibility for any damage or loss
* of property which results from the use of this software.
*
- * $Id: res.c 2023 2006-09-02 23:47:27Z jilles $
+ * $Id: res.c 3301 2007-03-28 15:04:06Z jilles $
* from Hybrid Id: res.c 459 2006-02-12 22:21:37Z db $
*
* July 1999 - Rewrote a bunch of stuff here. Change hostent builder code,
#include "ircd_defs.h"
#include "common.h"
#include "ircd.h"
-#include "commio.h"
#include "res.h"
#include "reslib.h"
-#include "tools.h"
-#include "event.h"
#include "irc_string.h"
#include "sprintf_irc.h"
#include "numeric.h"
struct reslist
{
- dlink_node node;
+ rb_dlink_node node;
int id;
int sent; /* number of requests sent */
request_state state; /* State the resolver machine is in */
char resend; /* send flag. 0 == dont resend */
time_t sentat;
time_t timeout;
- struct irc_sockaddr_storage addr;
+ struct rb_sockaddr_storage addr;
char *name;
struct DNSQuery *query; /* query callback for this request */
};
static int res_fd;
-static dlink_list request_list = { NULL, NULL, 0 };
+static rb_dlink_list request_list = { NULL, NULL, 0 };
static void rem_request(struct reslist *request);
static struct reslist *make_request(struct DNSQuery *query);
static void do_query_name(struct DNSQuery *query, const char *name, struct reslist *request, int);
-static void do_query_number(struct DNSQuery *query, const struct irc_sockaddr_storage *,
+static void do_query_number(struct DNSQuery *query, const struct rb_sockaddr_storage *,
struct reslist *request);
static void query_name(struct reslist *request);
static int send_res_msg(const char *buf, int len, int count);
static struct reslist *find_id(int id);
static struct DNSReply *make_dnsreply(struct reslist *request);
-extern struct irc_sockaddr_storage irc_nsaddr_list[IRCD_MAXNS];
+extern struct rb_sockaddr_storage irc_nsaddr_list[IRCD_MAXNS];
extern int irc_nscount;
extern char irc_domain[HOSTLEN + 1];
* paul vixie, 29may94
* revised for ircd, cryogen(stu) may03
*/
-static int res_ourserver(const struct irc_sockaddr_storage *inp)
+static int res_ourserver(const struct rb_sockaddr_storage *inp)
{
#ifdef IPV6
struct sockaddr_in6 *v6;
for (ns = 0; ns < irc_nscount; ns++)
{
- const struct irc_sockaddr_storage *srv = &irc_nsaddr_list[ns];
+ const struct rb_sockaddr_storage *srv = &irc_nsaddr_list[ns];
#ifdef IPV6
v6 = (struct sockaddr_in6 *)srv;
#endif
*/
static time_t timeout_query_list(time_t now)
{
- dlink_node *ptr;
- dlink_node *next_ptr;
+ rb_dlink_node *ptr;
+ rb_dlink_node *next_ptr;
struct reslist *request;
time_t next_time = 0;
time_t timeout = 0;
- DLINK_FOREACH_SAFE(ptr, next_ptr, request_list.head)
+ RB_DLINK_FOREACH_SAFE(ptr, next_ptr, request_list.head)
{
request = ptr->data;
timeout = request->sentat + request->timeout;
*/
static void timeout_resolver(void *notused)
{
- timeout_query_list(CurrentTime);
+ timeout_query_list(rb_current_time());
}
/*
if (res_fd <= 0) /* there isn't any such thing as fd 0, that's just a myth. */
{
- if ((res_fd = comm_socket(irc_nsaddr_list[0].ss_family, SOCK_DGRAM, 0,
+ if ((res_fd = rb_socket(irc_nsaddr_list[0].ss_family, SOCK_DGRAM, 0,
"UDP resolver socket")) == -1)
return;
/* At the moment, the resolver FD data is global .. */
- comm_setselect(res_fd, FDLIST_NONE, COMM_SELECT_READ, res_readreply, NULL, 0);
- eventAdd("timeout_resolver", timeout_resolver, NULL, 1);
+ rb_setselect(res_fd, FDLIST_NONE, COMM_SELECT_READ, res_readreply, NULL, 0);
+ rb_event_add("timeout_resolver", timeout_resolver, NULL, 1);
}
}
void init_resolver(void)
{
#ifdef HAVE_SRAND48
- srand48(CurrentTime);
+ srand48(rb_current_time());
#endif
start_resolver();
}
*/
void restart_resolver(void)
{
- comm_close(res_fd);
+ rb_close(res_fd);
res_fd = -1;
eventDelete(timeout_resolver, NULL); /* -ddosen */
start_resolver();
*/
static void rem_request(struct reslist *request)
{
- dlinkDelete(&request->node, &request_list);
- MyFree(request->name);
- MyFree(request);
+ rb_dlinkDelete(&request->node, &request_list);
+ rb_free(request->name);
+ rb_free(request);
}
/*
*/
static struct reslist *make_request(struct DNSQuery *query)
{
- struct reslist *request = MyMalloc(sizeof(struct reslist));
+ struct reslist *request = rb_malloc(sizeof(struct reslist));
- request->sentat = CurrentTime;
+ request->sentat = rb_current_time();
request->retries = 3;
request->resend = 1;
request->timeout = 4; /* start at 4 and exponential inc. */
request->query = query;
request->state = REQ_IDLE;
- dlinkAdd(request, &request->node, &request_list);
+ rb_dlinkAdd(request, &request->node, &request_list);
return request;
}
*/
void delete_resolver_queries(const struct DNSQuery *query)
{
- dlink_node *ptr;
- dlink_node *next_ptr;
+ rb_dlink_node *ptr;
+ rb_dlink_node *next_ptr;
struct reslist *request;
- DLINK_FOREACH_SAFE(ptr, next_ptr, request_list.head)
+ RB_DLINK_FOREACH_SAFE(ptr, next_ptr, request_list.head)
{
if ((request = ptr->data) != NULL)
{
if (max_queries == 0)
max_queries = 1;
- for (i = 0; i < max_queries; i++)
+ for (i = 0; sent < max_queries && i < irc_nscount; i++)
{
if (sendto(res_fd, msg, len, 0,
(struct sockaddr *)&(irc_nsaddr_list[i]),
*/
static struct reslist *find_id(int id)
{
- dlink_node *ptr;
+ rb_dlink_node *ptr;
struct reslist *request;
- DLINK_FOREACH(ptr, request_list.head)
+ RB_DLINK_FOREACH(ptr, request_list.head)
{
request = ptr->data;
/*
* gethost_byaddr - get host name from address
*/
-void gethost_byaddr(const struct irc_sockaddr_storage *addr, struct DNSQuery *query)
+void gethost_byaddr(const struct rb_sockaddr_storage *addr, struct DNSQuery *query)
{
do_query_number(query, addr, NULL);
}
{
char host_name[HOSTLEN + 1];
- strlcpy(host_name, name, HOSTLEN);
+ strlcpy(host_name, name, HOSTLEN + 1);
add_local_domain(host_name, HOSTLEN);
if (request == NULL)
{
request = make_request(query);
- request->name = (char *)MyMalloc(strlen(host_name) + 1);
+ request->name = (char *)rb_malloc(strlen(host_name) + 1);
strcpy(request->name, host_name);
request->state = REQ_A;
}
/*
* do_query_number - Use this to do reverse IP# lookups.
*/
-static void do_query_number(struct DNSQuery *query, const struct irc_sockaddr_storage *addr,
+static void do_query_number(struct DNSQuery *query, const struct rb_sockaddr_storage *addr,
struct reslist *request)
{
const unsigned char *cp;
if (request == NULL)
{
request = make_request(query);
- memcpy(&request->addr, addr, sizeof(struct irc_sockaddr_storage));
- request->name = (char *)MyMalloc(HOSTLEN + 1);
+ memcpy(&request->addr, addr, sizeof(struct rb_sockaddr_storage));
+ request->name = (char *)rb_malloc(HOSTLEN + 1);
}
if (addr->ss_family == AF_INET)
struct sockaddr_in *v4 = (struct sockaddr_in *)addr;
cp = (const unsigned char *)&v4->sin_addr.s_addr;
- ircsprintf(request->queryname, "%u.%u.%u.%u.in-addr.arpa", (unsigned int)(cp[3]),
+ rb_sprintf(request->queryname, "%u.%u.%u.%u.in-addr.arpa", (unsigned int)(cp[3]),
(unsigned int)(cp[2]), (unsigned int)(cp[1]), (unsigned int)(cp[0]));
}
#ifdef IPV6
else if (n == 0)
return (0); /* no more answers left */
- strlcpy(request->name, hostbuf, HOSTLEN);
+ strlcpy(request->name, hostbuf, HOSTLEN + 1);
return (1);
break;
struct DNSReply *reply = NULL;
int rc;
int answer_count;
- socklen_t len = sizeof(struct irc_sockaddr_storage);
- struct irc_sockaddr_storage lsin;
+ socklen_t len = sizeof(struct rb_sockaddr_storage);
+ struct rb_sockaddr_storage lsin;
rc = recvfrom(fd, 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
*/
- comm_setselect(fd, FDLIST_NONE, COMM_SELECT_READ, res_readreply, NULL, 0);
+ rb_setselect(fd, FDLIST_NONE, COMM_SELECT_READ, res_readreply, NULL, 0);
/* Better to cast the sizeof instead of rc */
if (rc <= (int)(sizeof(HEADER)))
return;
*/
reply = make_dnsreply(request);
(*request->query->callback) (request->query->ptr, reply);
- MyFree(reply);
+ rb_free(reply);
rem_request(request);
}
}
struct DNSReply *cp;
s_assert(request != 0);
- cp = (struct DNSReply *)MyMalloc(sizeof(struct DNSReply));
+ cp = (struct DNSReply *)rb_malloc(sizeof(struct DNSReply));
cp->h_name = request->name;
memcpy(&cp->addr, &request->addr, sizeof(cp->addr));