diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-01-19 17:28:09 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-01-19 20:51:51 +0000 |
commit | 4f885f95f90764a70821546100dbf8980267b812 (patch) | |
tree | 83ebdd9b503864af57967c01c7d12d67fb88317e | |
parent | 97efd226102375efb9a4e770d0d5823aa7d4fdfa (diff) | |
download | rspamd-4f885f95f90764a70821546100dbf8980267b812.tar.gz rspamd-4f885f95f90764a70821546100dbf8980267b812.zip |
[Minor] Core: Add sockaddr access utility
-rw-r--r-- | src/libutil/addr.c | 16 | ||||
-rw-r--r-- | src/libutil/addr.h | 8 |
2 files changed, 24 insertions, 0 deletions
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 |