#include "macro.h"
#include "netlink-util.h"
-static int address_compare(const void *_a, const void *_b) {
- const struct local_address *a = _a, *b = _b;
+static int address_compare(const struct local_address *a, const struct local_address *b) {
+ int r;
/* Order lowest scope first, IPv4 before IPv6, lowest interface index first */
if (a->family == AF_INET6 && b->family == AF_INET)
return 1;
- if (a->scope < b->scope)
- return -1;
- if (a->scope > b->scope)
- return 1;
+ r = CMP(a->scope, b->scope);
+ if (r != 0)
+ return r;
- if (a->metric < b->metric)
- return -1;
- if (a->metric > b->metric)
- return 1;
+ r = CMP(a->metric, b->metric);
+ if (r != 0)
+ return r;
- if (a->ifindex < b->ifindex)
- return -1;
- if (a->ifindex > b->ifindex)
- return 1;
+ r = CMP(a->ifindex, b->ifindex);
+ if (r != 0)
+ return r;
return memcmp(&a->address, &b->address, FAMILY_ADDRESS_SIZE(a->family));
}
n_list++;
};
- qsort_safe(list, n_list, sizeof(struct local_address), address_compare);
+ typesafe_qsort(list, n_list, address_compare);
*ret = TAKE_PTR(list);
n_list++;
}
- if (n_list > 0)
- qsort(list, n_list, sizeof(struct local_address), address_compare);
+ typesafe_qsort(list, n_list, address_compare);
*ret = TAKE_PTR(list);