commit 4f885f9: [Minor] Core: Add sockaddr access utility

Vsevolod Stakhov vsevolod at highsecure.ru
Sat Jan 19 20:56:03 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-01-19 17:28:09 +0000
URL: https://github.com/rspamd/rspamd/commit/4f885f95f90764a70821546100dbf8980267b812

[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


More information about the Commits mailing list