diff options
Diffstat (limited to 'src/odhcpd.c')
-rw-r--r-- | src/odhcpd.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/odhcpd.c b/src/odhcpd.c index 0edf63e..3c384e8 100644 --- a/src/odhcpd.c +++ b/src/odhcpd.c @@ -263,6 +263,25 @@ ssize_t odhcpd_get_interface_addresses(int ifindex, return ret; } +int odhcpd_get_preferred_interface_address(int ifindex, struct in6_addr *addr) +{ + struct odhcpd_ipaddr ipaddrs[8]; + ssize_t ip_cnt = odhcpd_get_interface_addresses(ifindex, ipaddrs, ARRAY_SIZE(ipaddrs)); + uint32_t preferred = 0; + int ret = 0; + + for (ssize_t i = 0; i < ip_cnt; i++) { + struct odhcpd_ipaddr *ipaddr = &ipaddrs[i]; + + if (ipaddr->preferred > preferred || !preferred) { + preferred = ipaddr->preferred; + *addr = ipaddr->addr; + ret = 1; + } + } + + return ret; +} struct interface* odhcpd_get_interface_by_index(int ifindex) { |