res: expose rDNS building functions

This will be used by the blacklist code to avoid duplication of code.
This commit is contained in:
Elizabeth Myers 2016-03-23 16:40:31 -05:00
parent 2f355b7e3c
commit 8ed8e5cae8
2 changed files with 48 additions and 34 deletions

View file

@ -465,28 +465,22 @@ static void do_query_name(struct DNSQuery *query, const char *name, struct resli
query_name(request); query_name(request);
} }
/* /* Build an rDNS style query - if suffix is NULL, use the appropriate .arpa zone */
* do_query_number - Use this to do reverse IP# lookups. void build_rdns(char *buf, size_t size, const struct rb_sockaddr_storage *addr, const char *suffix)
*/
static void do_query_number(struct DNSQuery *query, const struct rb_sockaddr_storage *addr,
struct reslist *request)
{ {
const unsigned char *cp; const unsigned char *cp;
if (request == NULL)
{
request = make_request(query);
memcpy(&request->addr, addr, sizeof(struct rb_sockaddr_storage));
request->name = (char *)rb_malloc(IRCD_RES_HOSTLEN + 1);
}
if (GET_SS_FAMILY(addr) == AF_INET) if (GET_SS_FAMILY(addr) == AF_INET)
{ {
const struct sockaddr_in *v4 = (const struct sockaddr_in *)addr; const struct sockaddr_in *v4 = (const struct sockaddr_in *)addr;
cp = (const unsigned char *)&v4->sin_addr.s_addr; cp = (const unsigned char *)&v4->sin_addr.s_addr;
sprintf(request->queryname, "%u.%u.%u.%u.in-addr.arpa", (unsigned int)(cp[3]), (void) snprintf(buf, size, "%u.%u.%u.%u.%s",
(unsigned int)(cp[2]), (unsigned int)(cp[1]), (unsigned int)(cp[0])); (unsigned int)(cp[3]),
(unsigned int)(cp[2]),
(unsigned int)(cp[1]),
(unsigned int)(cp[0]),
suffix == NULL ? "in-addr.arpa" : suffix);
} }
#ifdef RB_IPV6 #ifdef RB_IPV6
else if (GET_SS_FAMILY(addr) == AF_INET6) else if (GET_SS_FAMILY(addr) == AF_INET6)
@ -494,8 +488,8 @@ static void do_query_number(struct DNSQuery *query, const struct rb_sockaddr_sto
const struct sockaddr_in6 *v6 = (const struct sockaddr_in6 *)addr; const struct sockaddr_in6 *v6 = (const struct sockaddr_in6 *)addr;
cp = (const unsigned char *)&v6->sin6_addr.s6_addr; cp = (const unsigned char *)&v6->sin6_addr.s6_addr;
(void)sprintf(request->queryname, "%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x." (void) snprintf(buf, size,
"%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.ip6.arpa", "%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%s",
(unsigned int)(cp[15] & 0xf), (unsigned int)(cp[15] >> 4), (unsigned int)(cp[15] & 0xf), (unsigned int)(cp[15] >> 4),
(unsigned int)(cp[14] & 0xf), (unsigned int)(cp[14] >> 4), (unsigned int)(cp[14] & 0xf), (unsigned int)(cp[14] >> 4),
(unsigned int)(cp[13] & 0xf), (unsigned int)(cp[13] >> 4), (unsigned int)(cp[13] & 0xf), (unsigned int)(cp[13] >> 4),
@ -511,9 +505,28 @@ static void do_query_number(struct DNSQuery *query, const struct rb_sockaddr_sto
(unsigned int)(cp[3] & 0xf), (unsigned int)(cp[3] >> 4), (unsigned int)(cp[3] & 0xf), (unsigned int)(cp[3] >> 4),
(unsigned int)(cp[2] & 0xf), (unsigned int)(cp[2] >> 4), (unsigned int)(cp[2] & 0xf), (unsigned int)(cp[2] >> 4),
(unsigned int)(cp[1] & 0xf), (unsigned int)(cp[1] >> 4), (unsigned int)(cp[1] & 0xf), (unsigned int)(cp[1] >> 4),
(unsigned int)(cp[0] & 0xf), (unsigned int)(cp[0] >> 4)); (unsigned int)(cp[0] & 0xf), (unsigned int)(cp[0] >> 4),
suffix == NULL ? "ip6.arpa" : suffix);
} }
#endif #endif
}
/*
* do_query_number - Use this to do reverse IP# lookups.
*/
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 rb_sockaddr_storage));
request->name = (char *)rb_malloc(IRCD_RES_HOSTLEN + 1);
}
build_rdns(request->queryname, IRCD_RES_HOSTLEN + 1, addr, NULL);
request->type = T_PTR; request->type = T_PTR;
query_name(request); query_name(request);

View file

@ -32,5 +32,6 @@ extern void init_resolver(void);
extern void restart_resolver(void); extern void restart_resolver(void);
extern void gethost_byname_type(const char *, struct DNSQuery *, int); extern void gethost_byname_type(const char *, struct DNSQuery *, int);
extern void gethost_byaddr(const struct rb_sockaddr_storage *, struct DNSQuery *); extern void gethost_byaddr(const struct rb_sockaddr_storage *, struct DNSQuery *);
extern void build_rdns(char *, size_t, const struct rb_sockaddr_storage *, const char *);
#endif #endif