if (src[0] == '/' || src[0] == '.') {
return rspamd_parse_unix_path (target, src);
}
+ else if (inet_pton (AF_INET, src, &su.s4.sin_addr) == 1) {
+ addr = rspamd_inet_addr_create (AF_INET);
+ memcpy (&addr->u.in.addr.s4.sin_addr, &su.s4.sin_addr,
+ sizeof (struct in_addr));
+ ret = TRUE;
+ }
else if (ipv6_status == RSPAMD_IPV6_SUPPORTED &&
inet_pton (AF_INET6, src, &su.s6.sin6_addr) == 1) {
addr = rspamd_inet_addr_create (AF_INET6);
sizeof (struct in6_addr));
ret = TRUE;
}
- else if (inet_pton (AF_INET, src, &su.s4.sin_addr) == 1) {
- addr = rspamd_inet_addr_create (AF_INET6);
- memcpy (&addr->u.in.addr.s4.sin_addr, &su.s4.sin_addr,
- sizeof (struct in_addr));
- ret = TRUE;
- }
if (ret && target) {
*target = addr;
g_assert (a2 != NULL);
if (a1->af != a2->af) {
- return (rspamd_inet_address_af_order (a1) -
- rspamd_inet_address_af_order (a2));
+ return (rspamd_inet_address_af_order (a2) -
+ rspamd_inet_address_af_order (a1));
}
else {
switch (a1->af) {
return 0;
}
+gint
+rspamd_inet_address_compare_ptr (const gpointer a1,
+ const gpointer a2)
+{
+ const rspamd_inet_addr_t **i1 = a1, **i2 = a2;
+
+ return rspamd_inet_address_compare (*i1, *i2);
+}
+
rspamd_inet_addr_t *
rspamd_inet_address_copy (const rspamd_inet_addr_t *addr)
{
gint rspamd_inet_address_compare (const rspamd_inet_addr_t *a1,
const rspamd_inet_addr_t *a2);
+/**
+ * Utility function to compare addresses by in g_ptr_array
+ * @param a1
+ * @param a2
+ * @return
+ */
+gint rspamd_inet_address_compare_ptr (const gpointer a1,
+ const gpointer a2);
/**
* Performs deep copy of rspamd inet addr
* @param addr
static gint
rspamd_upstream_addr_sort_func (gconstpointer a, gconstpointer b)
{
- const rspamd_inet_addr_t *ip1 = (const rspamd_inet_addr_t *)a,
- *ip2 = (const rspamd_inet_addr_t *)b;
+ const rspamd_inet_addr_t **ip1 = (const rspamd_inet_addr_t **)a,
+ **ip2 = (const rspamd_inet_addr_t **)b;
gint w1, w2;
- w1 = rspamd_upstream_af_to_weight (ip1);
- w2 = rspamd_upstream_af_to_weight (ip2);
+ w1 = rspamd_upstream_af_to_weight (*ip1);
+ w2 = rspamd_upstream_af_to_weight (*ip2);
return w2 - w1;
}
rspamd_mutex_free (up->lock);
g_free (up->name);
- g_free (up->addrs.addr);
g_slice_free1 (sizeof (*up), up);
}
gint fd;
guint i;
- g_ptr_array_sort (addrs, (GCompareFunc)rspamd_inet_address_compare);
+ g_ptr_array_sort (addrs, rspamd_inet_address_compare_ptr);
for (i = 0; i < cnt; i ++) {
fd = rspamd_inet_address_listen (g_ptr_array_index (addrs, i),
listen_type, TRUE);