mirror of
https://github.com/matrix-construct/construct
synced 2024-12-27 07:54:05 +01:00
ircd::net: Use a structured argument to addrs closure; add more data.
This commit is contained in:
parent
67c1ff06aa
commit
28569176f2
3 changed files with 32 additions and 11 deletions
|
@ -18,9 +18,20 @@ extern "C"
|
|||
|
||||
namespace ircd::net::addrs
|
||||
{
|
||||
using closure = std::function<bool (const string_view &, const ipport &, const uint &)>;
|
||||
struct addr;
|
||||
using closure = std::function<bool (const addr &)>;
|
||||
using raw_closure = std::function<bool (const struct ::ifaddrs &)>;
|
||||
|
||||
bool for_each(const raw_closure &);
|
||||
bool for_each(const closure &);
|
||||
}
|
||||
|
||||
struct ircd::net::addrs::addr
|
||||
{
|
||||
string_view name;
|
||||
ipport address;
|
||||
uint32_t flags {0};
|
||||
uint32_t flowinfo {0};
|
||||
uint32_t scope_id {0};
|
||||
uint16_t family {0};
|
||||
};
|
||||
|
|
19
ircd/net.cc
19
ircd/net.cc
|
@ -696,27 +696,34 @@ ircd::net::addrs::for_each(const closure &closure)
|
|||
return for_each([&closure]
|
||||
(const struct ::ifaddrs &ifa)
|
||||
{
|
||||
const string_view &name(ifa.ifa_name);
|
||||
const uint &flags(ifa.ifa_flags);
|
||||
addr a;
|
||||
a.name = ifa.ifa_name;
|
||||
a.flags = ifa.ifa_flags;
|
||||
|
||||
ipport ipport;
|
||||
if(ifa.ifa_addr) switch(ifa.ifa_addr->sa_family)
|
||||
{
|
||||
case AF_INET6:
|
||||
{
|
||||
const auto &sin(reinterpret_cast<const struct sockaddr_in6 *>(ifa.ifa_addr));
|
||||
ipport =
|
||||
a.family = sin->sin6_family;
|
||||
a.address =
|
||||
{
|
||||
ntoh(*reinterpret_cast<const uint128_t *>(sin->sin6_addr.s6_addr)),
|
||||
sin->sin6_port
|
||||
};
|
||||
a.scope_id = sin->sin6_scope_id;
|
||||
a.flowinfo = sin->sin6_flowinfo;
|
||||
break;
|
||||
}
|
||||
|
||||
case AF_INET:
|
||||
{
|
||||
const auto &sin(reinterpret_cast<const struct sockaddr_in *>(ifa.ifa_addr));
|
||||
ipport = { ntoh(sin->sin_addr.s_addr), sin->sin_port };
|
||||
a.family = sin->sin_family;
|
||||
a.address =
|
||||
{
|
||||
ntoh(sin->sin_addr.s_addr), sin->sin_port
|
||||
};
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -724,7 +731,7 @@ ircd::net::addrs::for_each(const closure &closure)
|
|||
return true;
|
||||
}
|
||||
|
||||
return closure(name, ipport, flags);
|
||||
return closure(a);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -4183,11 +4183,14 @@ bool
|
|||
console_cmd__net__addrs(opt &out, const string_view &line)
|
||||
{
|
||||
net::addrs::for_each([&out]
|
||||
(const string_view &name, const ipport &addr, const uint &flags)
|
||||
(const net::addrs::addr &addr)
|
||||
{
|
||||
out << std::left << std::setw(16) << name << " "
|
||||
<< std::setw(32) << addr << " "
|
||||
<< "(0x" << std::hex << flags << ")" << std::dec
|
||||
out << std::left << std::setw(16) << addr.name << " "
|
||||
<< std::setw(32) << addr.address << " "
|
||||
<< "family[" << std::setw(2) << addr.family << "] "
|
||||
<< "scope[" << addr.scope_id << "] "
|
||||
<< "flowinfo[" << addr.flowinfo << "] "
|
||||
<< "flags[0x" << std::hex << addr.flags << "]" << std::dec
|
||||
<< std::endl;
|
||||
|
||||
return true;
|
||||
|
|
Loading…
Reference in a new issue