0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-07-02 16:58:19 +02:00

ircd::net: Add util to detect usable ipv6 interface.

This commit is contained in:
Jason Volk 2019-03-25 15:12:34 -07:00
parent 672e9dd712
commit c0cbfd2d23
2 changed files with 24 additions and 0 deletions

View file

@ -24,6 +24,8 @@ namespace ircd::net::addrs
bool for_each(const raw_closure &);
bool for_each(const closure &);
bool has_usable_ipv6_interface();
}
struct ircd::net::addrs::addr

View file

@ -690,6 +690,28 @@ ircd::net::open(socket &socket,
// net/addrs.h
//
bool
ircd::net::addrs::has_usable_ipv6_interface()
{
return !for_each([](const addr &a)
{
if(a.family != AF_INET6)
return true;
if(a.scope_id != 0) // global scope
return true;
if(~a.flags & IFF_UP) // not up
return true;
if(a.flags & IFF_LOOPBACK) // not usable
return true;
// return false to break
return false;
});
}
bool
ircd::net::addrs::for_each(const closure &closure)
{