From a64e721cf0abfce2821fd2eee23c8816a6100248 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Sat, 2 Feb 2019 19:09:35 +1100 Subject: [PATCH] posix/interface: add initial interface query logic --- CMakeLists.txt | 2 ++ posix/interface.cpp | 12 ++++++++++ posix/interface.hpp | 54 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 posix/interface.cpp create mode 100644 posix/interface.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 0aa54030..80d1b08d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/posix/interface.cpp b/posix/interface.cpp new file mode 100644 index 00000000..4ea56005 --- /dev/null +++ b/posix/interface.cpp @@ -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 + */ + +#include "interface.hpp" + + +/////////////////////////////////////////////////////////////////////////////// diff --git a/posix/interface.hpp b/posix/interface.hpp new file mode 100644 index 00000000..dfdb5cab --- /dev/null +++ b/posix/interface.hpp @@ -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 + */ + +#pragma once + +#include "except.hpp" + +#include +#include + + +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 (); + } +} \ No newline at end of file