query_name(request);
}
-/*
- * 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)
+/* Build an rDNS style query - if suffix is NULL, use the appropriate .arpa zone */
+void build_rdns(char *buf, size_t size, const struct rb_sockaddr_storage *addr, const char *suffix)
{
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)
{
const struct sockaddr_in *v4 = (const struct sockaddr_in *)addr;
cp = (const unsigned char *)&v4->sin_addr.s_addr;
- 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]));
+ (void) snprintf(buf, size, "%u.%u.%u.%u.%s",
+ (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
else if (GET_SS_FAMILY(addr) == AF_INET6)
const struct sockaddr_in6 *v6 = (const struct sockaddr_in6 *)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."
- "%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.ip6.arpa",
- (unsigned int)(cp[15] & 0xf), (unsigned int)(cp[15] >> 4),
- (unsigned int)(cp[14] & 0xf), (unsigned int)(cp[14] >> 4),
- (unsigned int)(cp[13] & 0xf), (unsigned int)(cp[13] >> 4),
- (unsigned int)(cp[12] & 0xf), (unsigned int)(cp[12] >> 4),
- (unsigned int)(cp[11] & 0xf), (unsigned int)(cp[11] >> 4),
- (unsigned int)(cp[10] & 0xf), (unsigned int)(cp[10] >> 4),
- (unsigned int)(cp[9] & 0xf), (unsigned int)(cp[9] >> 4),
- (unsigned int)(cp[8] & 0xf), (unsigned int)(cp[8] >> 4),
- (unsigned int)(cp[7] & 0xf), (unsigned int)(cp[7] >> 4),
- (unsigned int)(cp[6] & 0xf), (unsigned int)(cp[6] >> 4),
- (unsigned int)(cp[5] & 0xf), (unsigned int)(cp[5] >> 4),
- (unsigned int)(cp[4] & 0xf), (unsigned int)(cp[4] >> 4),
- (unsigned int)(cp[3] & 0xf), (unsigned int)(cp[3] >> 4),
- (unsigned int)(cp[2] & 0xf), (unsigned int)(cp[2] >> 4),
- (unsigned int)(cp[1] & 0xf), (unsigned int)(cp[1] >> 4),
- (unsigned int)(cp[0] & 0xf), (unsigned int)(cp[0] >> 4));
+ (void) snprintf(buf, size,
+ "%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[14] & 0xf), (unsigned int)(cp[14] >> 4),
+ (unsigned int)(cp[13] & 0xf), (unsigned int)(cp[13] >> 4),
+ (unsigned int)(cp[12] & 0xf), (unsigned int)(cp[12] >> 4),
+ (unsigned int)(cp[11] & 0xf), (unsigned int)(cp[11] >> 4),
+ (unsigned int)(cp[10] & 0xf), (unsigned int)(cp[10] >> 4),
+ (unsigned int)(cp[9] & 0xf), (unsigned int)(cp[9] >> 4),
+ (unsigned int)(cp[8] & 0xf), (unsigned int)(cp[8] >> 4),
+ (unsigned int)(cp[7] & 0xf), (unsigned int)(cp[7] >> 4),
+ (unsigned int)(cp[6] & 0xf), (unsigned int)(cp[6] >> 4),
+ (unsigned int)(cp[5] & 0xf), (unsigned int)(cp[5] >> 4),
+ (unsigned int)(cp[4] & 0xf), (unsigned int)(cp[4] >> 4),
+ (unsigned int)(cp[3] & 0xf), (unsigned int)(cp[3] >> 4),
+ (unsigned int)(cp[2] & 0xf), (unsigned int)(cp[2] >> 4),
+ (unsigned int)(cp[1] & 0xf), (unsigned int)(cp[1] >> 4),
+ (unsigned int)(cp[0] & 0xf), (unsigned int)(cp[0] >> 4),
+ suffix == NULL ? "ip6.arpa" : suffix);
}
#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;
query_name(request);