13 #ifndef __STOUT_POSIX_IP_HPP__ 14 #define __STOUT_POSIX_IP_HPP__ 18 #include <sys/types.h> 31 const std::string&
name,
34 if (family != AF_INET && family != AF_INET6) {
38 struct ifaddrs* ifaddr =
nullptr;
39 if (getifaddrs(&ifaddr) == -1) {
46 for (
struct ifaddrs* ifa = ifaddr; ifa !=
nullptr; ifa = ifa->ifa_next) {
47 if (ifa->ifa_name !=
nullptr && !strcmp(ifa->ifa_name, name.c_str())) {
50 if (ifa->ifa_addr !=
nullptr && ifa->ifa_addr->sa_family == family) {
53 if (ifa->ifa_netmask !=
nullptr &&
54 ifa->ifa_netmask->sa_family == family) {
72 int prefix = (family == AF_INET ? 32 : 64);
87 return Error(
"Cannot find the link device");
95 #endif // __STOUT_POSIX_IP_HPP__ IP address() const
Definition: ip.hpp:261
Definition: errorbase.hpp:36
T & get()&
Definition: try.hpp:80
Definition: errorbase.hpp:50
IP netmask() const
Definition: ip.hpp:263
static Result< Network > fromLinkDevice(const std::string &name, int family)
Definition: ip.hpp:30
static Try error(const E &e)
Definition: try.hpp:43
static Try< Network > create(const IP &address, const IP &netmask)
Definition: ip.hpp:570
bool isError() const
Definition: try.hpp:78
std::string stringify(int flags)
static Try< IP > create(const struct sockaddr_storage &_storage)
Definition: ip.hpp:454
constexpr const char * name
Definition: shell.hpp:41
int prefix() const
Definition: ip.hpp:266