41 std::vector<Item> new_list ;
42 loadImp( m_es , new_list ) ;
45 swap( m_list , new_list ) ;
59 bool decoration )
const
61 std::string name = name_in ;
67 name = name_in.substr( 0U , name_in.length()-5U ) ;
72 name = name_in.substr( 0U , name_in.length()-5U ) ;
78 return AddressList() ;
84 for(
const auto & item : m_list )
86 if( ( item.name == name || item.altname == name ) && item.up && item.valid_address )
89 ( type == 6 && item.address.is6() ) ||
90 ( type == 4 && item.address.is4() ) )
92 result.push_back( item.address ) ;
93 result.back().setPort( port ) ;
104 for(
const auto & name : names )
115 AddressList list = find( name , port ,
true ) ;
116 if( list.empty() && ( name.empty() || ( name.find(
'/') != std::string::npos && name.find(
"/dev/") != 0U ) ) )
118 bad_names.push_back( name ) ;
120 else if( list.empty() )
122 empty_names.push_back( name ) ;
126 used_names.push_back( name ) ;
128 result.insert( result.end() , list.begin() , list.end() ) ;
137 for(
const auto & iface : *
this )
139 if( all || iface.up )
140 list.push_back( iface.name ) ;
142 std::sort( list.begin() , list.end() ) ;
143 list.erase( std::unique(list.begin(),list.end()) , list.end() ) ;
149 return m_list.begin() ;
154 return m_list.end() ;
157void GNet::Interfaces::readEvent()
161 std::string s = m_notifier->readEvent() ;
162 if( m_handler && !s.empty() )
163 m_handler->onInterfaceEvent( s ) ;
167void GNet::Interfaces::onFutureEvent()
171 std::string s = m_notifier->onFutureEvent() ;
172 if( m_handler && !s.empty() )
173 m_handler->onInterfaceEvent( s ) ;
179GNet::Interfaces::Item::Item() :
180 address(Address::defaultAddress())
static bool validStrings(const std::string &ip, const std::string &port_string, std::string *reason=nullptr)
Returns true if the combined network-address string and port string is valid.
static Address parse(const std::string &display_string)
Factory function for any address family.
A tuple containing an ExceptionHandler interface pointer and a bound 'exception source' pointer.
An interface for receiving notification of network changes.
A class for getting a list of network interfaces and their addresses.
void load()
Loads or reloads the list.
Interfaces()
Default constructor resulting in an empty list.
bool loaded() const
Returns true if load()ed.
~Interfaces() override
Destructor.
static bool supported()
Returns false if a stubbed-out implementation.
const_iterator begin() const
Returns a begin iterator.
std::vector< Address > addresses(const G::StringArray &names, unsigned int port, G::StringArray &used_names, G::StringArray &empty_names, G::StringArray &bad_names) const
Treats each name given as an address or interface name and returns the total set of addresses.
const_iterator end() const
Returns a one-off-the-end iterator.
std::vector< Address > find(const std::string &name, unsigned int port, bool allow_decoration=true) const
Finds the named interface and returns its addresses if it is up.
G::StringArray names(bool all=false) const
Returns the interface names, optionally including interfaces that are not up.
static bool tailMatch(const std::string &in, const std::string &ending)
Returns true if the string has the given ending (or the given ending is empty).
static std::string fromUInt(unsigned int ui)
Converts unsigned int 'ui' to a string.
std::vector< std::string > StringArray
A std::vector of std::strings.