* --Bleep (Thomas Helvey <tomh@inxpress.net>)
*
* This was all needlessly complicated for irc. Simplified. No more hostent
- * All we really care about is the IP -> hostname mappings. Thats all.
+ * All we really care about is the IP -> hostname mappings. Thats all.
*
* Apr 28, 2003 --cryogen and Dianora
*
static void rem_request(struct reslist *request);
static struct reslist *make_request(struct DNSQuery *query);
+static void gethost_byname_type_fqdn(const char *name, struct DNSQuery *query,
+ int type);
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 rb_sockaddr_storage *,
struct reslist *request);
}
/*
- * timeout_query_list - Remove queries from the list which have been
+ * timeout_query_list - Remove queries from the list which have been
* there too long without being resolved.
*/
static time_t timeout_query_list(time_t now)
}
/*
- * rem_request - remove a request from the list.
- * This must also free any memory that has been allocated for
+ * rem_request - remove a request from the list.
+ * This must also free any memory that has been allocated for
* temporary storage of DNS results.
*/
static void rem_request(struct reslist *request)
}
/*
- * delete_resolver_queries - cleanup outstanding queries
+ * delete_resolver_queries - cleanup outstanding queries
* for which there no longer exist clients or conf lines.
*/
void delete_resolver_queries(const struct DNSQuery *query)
/*
* send_res_msg - sends msg to a nameserver.
* This should reflect /etc/resolv.conf.
- * Returns number of nameserver successfully sent to
+ * Returns number of nameserver successfully sent to
* or -1 if no successful sends.
*/
static int send_res_msg(const char *msg, int len, int rcount)
if (ns_failure_count[ns] && retrycnt % retryfreq(ns_failure_count[ns]))
continue;
if (sendto(rb_get_fd(res_fd), msg, len, 0,
- (struct sockaddr *)&(irc_nsaddr_list[ns]),
+ (struct sockaddr *)&(irc_nsaddr_list[ns]),
GET_SS_LEN(&irc_nsaddr_list[ns])) == len)
return ns;
}
if (!ns_failure_count[ns])
continue;
if (sendto(rb_get_fd(res_fd), msg, len, 0,
- (struct sockaddr *)&(irc_nsaddr_list[ns]),
+ (struct sockaddr *)&(irc_nsaddr_list[ns]),
GET_SS_LEN(&irc_nsaddr_list[ns])) == len)
return ns;
}
return (NULL);
}
-/*
- * gethost_byname_type - get host address from name
- *
+/*
+ * gethost_byname_type - get host address from name, adding domain if needed
*/
void gethost_byname_type(const char *name, struct DNSQuery *query, int type)
+{
+ char fqdn[IRCD_RES_HOSTLEN + 1];
+ assert(name != 0);
+
+ rb_strlcpy(fqdn, name, sizeof fqdn);
+ add_local_domain(fqdn, IRCD_RES_HOSTLEN);
+ gethost_byname_type_fqdn(fqdn, query, type);
+}
+
+/*
+ * gethost_byname_type_fqdn - get host address from fqdn
+ */
+static void gethost_byname_type_fqdn(const char *name, struct DNSQuery *query,
+ int type)
{
assert(name != 0);
do_query_name(query, name, NULL, type);
static void do_query_name(struct DNSQuery *query, const char *name, struct reslist *request,
int type)
{
- char host_name[IRCD_RES_HOSTLEN + 1];
-
- rb_strlcpy(host_name, name, IRCD_RES_HOSTLEN + 1);
- add_local_domain(host_name, IRCD_RES_HOSTLEN);
-
if (request == NULL)
{
request = make_request(query);
- request->name = (char *)rb_malloc(strlen(host_name) + 1);
- strcpy(request->name, host_name);
+ request->name = rb_strdup(name);
}
- rb_strlcpy(request->queryname, host_name, sizeof(request->queryname));
+ rb_strlcpy(request->queryname, name, sizeof(request->queryname));
request->type = type;
query_name(request);
}
rd_length = irc_ns_get16(current);
current += RDLENGTH_SIZE;
- /*
- * Wait to set request->type until we verify this structure
+ /*
+ * Wait to set request->type until we verify this structure
*/
switch (type)
{
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
- * (which is uint16_t). Because of the header = (HEADER*) buf;
+ /* Sparc and alpha need 16bit-alignment for accessing header->id
+ * (which is uint16_t). Because of the header = (HEADER*) buf;
* lateron, this is neeeded. --FaUl
*/
#if defined(__sparc__) || defined(__alpha__)
/*
* Lookup the 'authoritative' name that we were given for the
- * ip#.
+ * ip#.
*/
#ifdef RB_IPV6
if (request->addr.ss_family == AF_INET6)
- gethost_byname_type(request->name, request->query, T_AAAA);
+ gethost_byname_type_fqdn(request->name, request->query, T_AAAA);
else
#endif
- gethost_byname_type(request->name, request->query, T_A);
+ gethost_byname_type_fqdn(request->name, request->query, T_A);
rem_request(request);
}
else