From 4f885f95f90764a70821546100dbf8980267b812 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sat, 19 Jan 2019 17:28:09 +0000 Subject: [PATCH] [Minor] Core: Add sockaddr access utility --- src/libutil/addr.c | 16 ++++++++++++++++ src/libutil/addr.h | 8 ++++++++ 2 files changed, 24 insertions(+) diff --git a/src/libutil/addr.c b/src/libutil/addr.c index 5cbc1c044..73b72690e 100644 --- a/src/libutil/addr.c +++ b/src/libutil/addr.c @@ -1659,6 +1659,22 @@ rspamd_inet_address_get_af (const rspamd_inet_addr_t *addr) return addr->af; } +struct sockaddr* +rspamd_inet_address_get_sa (const rspamd_inet_addr_t *addr, + socklen_t *sz) +{ + g_assert (addr != NULL); + + if (addr->af == AF_UNIX) { + *sz = addr->slen; + return (struct sockaddr *)&addr->u.un->addr; + } + else { + *sz = addr->slen; + return (struct sockaddr *)&addr->u.in.addr.sa; + } +} + guint rspamd_inet_address_hash (gconstpointer a) diff --git a/src/libutil/addr.h b/src/libutil/addr.h index 389cd1e97..3aa24bb1c 100644 --- a/src/libutil/addr.h +++ b/src/libutil/addr.h @@ -140,6 +140,14 @@ uint16_t rspamd_inet_address_get_port (const rspamd_inet_addr_t *addr); */ gint rspamd_inet_address_get_af (const rspamd_inet_addr_t *addr); +/** + * Returns sockaddr and size for this address + * @param addr + * @param sz + * @return + */ +struct sockaddr* rspamd_inet_address_get_sa (const rspamd_inet_addr_t *addr, + socklen_t *sz); /** * Makes a radix key from inet address -- 2.39.5