posix/interface: add initial interface query logic
This commit is contained in:
parent
46ff7299bf
commit
a64e721cf0
@ -118,6 +118,8 @@ if (NOT WIN32)
|
||||
library_posix.hpp
|
||||
library_posix.cpp
|
||||
posix/fwd.hpp
|
||||
posix/interface.hpp
|
||||
posix/interface.cpp
|
||||
posix/map.cpp
|
||||
posix/map.hpp
|
||||
posix/socket.cpp
|
||||
|
12
posix/interface.cpp
Normal file
12
posix/interface.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
/*
|
||||
* 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>
|
||||
*/
|
||||
|
||||
#include "interface.hpp"
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
54
posix/interface.hpp
Normal file
54
posix/interface.hpp
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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 ();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user