54 lines
1.3 KiB
C++
54 lines
1.3 KiB
C++
|
/*
|
||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||
|
*
|
||
|
* Copyright 2019 Danny Robson <danny@nerdcruft.net>
|
||
|
*/
|
||
|
|
||
|
#pragma once
|
||
|
|
||
|
#include "except.hpp"
|
||
|
|
||
|
#include <sys/types.h>
|
||
|
#include <ifaddrs.h>
|
||
|
|
||
|
|
||
|
namespace cruft::posix {
|
||
|
auto
|
||
|
interface (void)
|
||
|
{
|
||
|
struct iterator {
|
||
|
iterator ()
|
||
|
{
|
||
|
error::try_call (getifaddrs, &cursor);
|
||
|
}
|
||
|
|
||
|
iterator (ifaddrs *_cursor):
|
||
|
cursor (_cursor)
|
||
|
{ ; }
|
||
|
|
||
|
ifaddrs *cursor;
|
||
|
|
||
|
decltype (auto) operator* (void) { return *cursor; }
|
||
|
decltype (auto) operator-> (void) { return cursor; }
|
||
|
|
||
|
iterator& operator++ (void)
|
||
|
{
|
||
|
cursor = cursor->ifa_next;
|
||
|
return *this;
|
||
|
}
|
||
|
|
||
|
bool operator== (iterator const &rhs) const noexcept { return cursor == rhs.cursor; }
|
||
|
bool operator!= (iterator const &rhs) const noexcept { return cursor != rhs.cursor; }
|
||
|
};
|
||
|
|
||
|
|
||
|
struct container {
|
||
|
auto begin (void) { return iterator ( ); }
|
||
|
auto end (void) { return iterator (nullptr); }
|
||
|
};
|
||
|
|
||
|
return container ();
|
||
|
}
|
||
|
}
|