4#include "Stroika/Foundation/StroikaPreComp.h"
9#include "Stroika/Foundation/Characters/String2Int.h"
11#include "Stroika/Foundation/Execution/Exceptions.h"
12#include "Stroika/Foundation/Execution/ProcessRunner.h"
16#include "Stroika/Foundation/Streams/MemoryStream.h"
27using namespace Stroika::Foundation::Memory;
28using namespace Stroika::Foundation::IO;
30using namespace Stroika::Foundation::Streams;
43#if USE_NOISY_TRACE_IN_THIS_MODULE_
46#if qStroika_Foundation_Common_Platform_Windows
51#if qStroika_Foundation_Common_Platform_POSIX
53#elif qStroika_Foundation_Common_Platform_Windows
54 ProcessRunner pr{includePurgedEntries ?
"arp -av"sv :
"arp -a"sv};
57 pr.Run (
nullptr, useStdOut);
59#if qStroika_Foundation_Common_Platform_Windows
64#if qStroika_Foundation_Common_Platform_POSIX
79 if (s[1].StartsWith (
"("sv) and s[1].EndsWith (
")"sv)) {
80 if (not includePurgedEntries and s[3].Contains (
"incomplete"sv)) {
85 if (l >= 6 and s[l - 2] ==
"on"sv) {
86 interfaceID = s[l - 1];
91#elif qStroika_Foundation_Common_Platform_Windows
92 if (i.StartsWith (
"Interface:"sv)) {
97 curInterface = iface->fInternalInterfaceID;
105 if (i.StartsWith (
" "sv) and not curInterface.empty ()) {
107 if (s.
length () >= 3 and (s[2] ==
"static"sv or s[2] ==
"dynamic"sv)) {
110 static const String kDash_ =
"-"sv;
111 static const String kColon_ =
":"sv;
112 if (omitAllFFHardwareAddresses) {
113 static const String kFFFF_ =
"ff-ff-ff-ff-ff-ff"sv;
114 if (s[1] == kFFFF_) {
124#if USE_NOISY_TRACE_IN_THIS_MODULE_
125 DbgTrace (
"returning: {}"_f, result);
131#if qStroika_Foundation_Common_Platform_Linux
135#if USE_NOISY_TRACE_IN_THIS_MODULE_
139 using Characters::String2Int;
141 static const filesystem::path kProcFileName_{
"/proc/net/arp"sv};
149 bool readFirstLine =
false;
152 reader.ReadMatrix (IO::FileSystem::FileInputStream::New (kProcFileName_, IO::FileSystem::FileInputStream::eNotSeekable))) {
153#if USE_NOISY_TRACE_IN_THIS_MODULE_
154 DbgTrace (
"in ProcNetArp_ capture_ line={}"_f, line);
156 if (not readFirstLine) {
157 readFirstLine =
true;
160 if (line[2] ==
"0x0"sv) {
165#if USE_NOISY_TRACE_IN_THIS_MODULE_
166 DbgTrace (
"returning: {}"_f, result);
182 sb <<
"InternetAddress:"sv << fInternetAddress <<
","sv;
183 sb <<
"HardwareAddress:"sv << fHardwareAddress <<
","sv;
184 sb <<
"InterfaceID:"sv << fInterfaceID;
194class NeighborsMonitor::Rep_ {
196 Rep_ (
const Options& o)
199 Require (not o.fMonitor.has_value ());
203 std::exception_ptr e =
nullptr;
206 if (not fOptions_.fStategies or fOptions_.fStategies->Contains (s)) {
208 return GetNeighbors_ (s);
212 e = current_exception ();
219#if qStroika_Foundation_Common_Platform_Linux
220 if (
auto o = tryStrategy (Options::Strategy::eProcNetArp)) {
224 if (
auto o = tryStrategy (Options::Strategy::eArpProgram)) {
228 rethrow_exception (e);
230 Throw (
Exception{
"No matching / available neighbors strategy"sv});
234#if USE_NOISY_TRACE_IN_THIS_MODULE_
238 case Options::Strategy::eArpProgram:
239 return ArpDashA_ (fOptions_.fIncludePurgedEntries.value_or (
false), fOptions_.fOmitAllFFHardwareAddresses.value_or (
true));
240#if qStroika_Foundation_Common_Platform_Linux
241 case Options::Strategy::eProcNetArp:
243 return ProcNetArp_ (fOptions_.fIncludePurgedEntries.value_or (
false));
253NeighborsMonitor::NeighborsMonitor (
const Options& options)
260 return fRep_->GetNeighbors ();
#define WeakAssert(c)
A WeakAssert() is for things that aren't guaranteed to be true, but are overwhelmingly likely to be t...
auto MakeSharedPtr(ARGS_TYPE &&... args) -> shared_ptr< T >
same as make_shared, but if type T has block allocation, then use block allocation for the 'shared pa...
Similar to String, but intended to more efficiently construct a String. Mutable type (String is large...
String is like std::u32string, except it is much easier to use, often much more space efficient,...
A Collection<T> is a container to manage an un-ordered collection of items, without equality defined ...
A generalization of a vector: a container whose elements are keyed by the natural numbers.
This COULD be easily used to read CSV files, or tab-delimited files, for example.
Exception<> is a replacement (subclass) for any std c++ exception class (e.g. the default 'std::excep...
Run the given command, and optionally support stdin/stdout/stderr as streams (either sync with Run,...
nonvirtual optional< Interface > GetContainingAddress(const InternetAddress &ia)
nonvirtual size_t length() const
STL-ish alias for size() - really in STL only used in string, I think, but still makes sense as an al...
void Throw(T &&e2Throw)
identical to builtin C++ 'throw' except that it does helpful, type dependent DbgTrace() messages firs...
Ptr New(const InputStream::Ptr< byte > &src, optional< AutomaticCodeCvtFlags > codeCvtFlags={}, optional< SeekableFlag > seekable={}, ReadAhead readAhead=eReadAheadAllowed)
Create an InputStream::Ptr<Character> from the arguments (usually binary source) - which can be used ...
nonvirtual String ToString() const