From: Vsevolod Stakhov Date: Tue, 16 Feb 2016 16:22:55 +0000 (+0000) Subject: Add routine to create inet address from the rdns reply X-Git-Tag: 1.2.0~219 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=947bd90138c8e5a5288a76708cf59349b79ebfe4;p=rspamd.git Add routine to create inet address from the rdns reply --- diff --git a/src/libutil/addr.c b/src/libutil/addr.c index e95ac4c64..414c48538 100644 --- a/src/libutil/addr.c +++ b/src/libutil/addr.c @@ -1214,6 +1214,27 @@ rspamd_inet_address_from_sa (const struct sockaddr *sa, socklen_t slen) return addr; } +rspamd_inet_addr_t * +rspamd_inet_address_from_rnds (const struct rdns_reply_entry *rep) +{ + rspamd_inet_addr_t *addr = NULL; + + g_assert (rep != NULL); + + if (rep->type == RDNS_REQUEST_A) { + addr = rspamd_inet_addr_create (AF_INET); + memcpy (&addr->u.in.addr.s4.sin_addr, &rep->content.a.addr, + sizeof (struct in_addr)); + } + else if (rep->type == RDNS_REQUEST_AAAA) { + addr = rspamd_inet_addr_create (AF_INET6); + memcpy (&addr->u.in.addr.s6.sin6_addr, &rep->content.aaa.addr, + sizeof (struct in6_addr)); + } + + return addr; +} + void rspamd_inet_address_apply_mask (rspamd_inet_addr_t *addr, guint mask) { diff --git a/src/libutil/addr.h b/src/libutil/addr.h index f6bbb40ae..afed3f8fc 100644 --- a/src/libutil/addr.h +++ b/src/libutil/addr.h @@ -17,6 +17,7 @@ #define ADDR_H_ #include "config.h" +#include "rdns.h" #ifdef HAVE_SYS_SOCKET_H #include @@ -59,6 +60,14 @@ rspamd_inet_addr_t * rspamd_inet_address_new (int af, const void *init); rspamd_inet_addr_t * rspamd_inet_address_from_sa (const struct sockaddr *sa, socklen_t slen); +/** + * Create new inet address from rdns reply + * @param rep reply element + * @return new ipv4 or ipv6 addr (port is NOT set) + */ +rspamd_inet_addr_t * rspamd_inet_address_from_rnds ( + const struct rdns_reply_entry *rep); + /** * Parse string with ipv6 address of length `len` to `target` which should be * at least sizeof (in6_addr_t)