E-MailRelay
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
GNet::Interfaces Class Reference

A class for getting a list of network interfaces and their addresses. More...

#include <ginterfaces.h>

+ Inheritance diagram for GNet::Interfaces:

Classes

struct  Item
 Used by GNet::Interfaces to describe an interface address binding. More...
 

Public Types

using const_iterator = std::vector< Item >::const_iterator
 
- Public Types inherited from GNet::EventHandler
enum class  Reason {
  closed , down , reset , abort ,
  other
}
 

Public Member Functions

 Interfaces ()
 Default constructor resulting in an empty list. More...
 
 Interfaces (ExceptionSink, InterfacesHandler &)
 Constructor resulting in an empty list with an attached event handler. More...
 
 ~Interfaces () override
 Destructor.
 
void load ()
 Loads or reloads the list. More...
 
bool loaded () const
 Returns true if load()ed. More...
 
G::StringArray names (bool all=false) const
 Returns the interface names, optionally including interfaces that are not up. More...
 
const_iterator begin () const
 Returns a begin iterator. More...
 
const_iterator end () const
 Returns a one-off-the-end iterator. More...
 
std::vector< Addressfind (const std::string &name, unsigned int port, bool allow_decoration=true) const
 Finds the named interface and returns its addresses if it is up. More...
 
std::vector< Addressaddresses (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. More...
 
 Interfaces (const Interfaces &)=delete
 
 Interfaces (Interfaces &&)=delete
 
void operator= (const Interfaces &)=delete
 
void operator= (Interfaces &&)=delete
 
- Public Member Functions inherited from GNet::EventHandler
virtual ~EventHandler ()=default
 Destructor.
 
virtual void readEvent ()
 Called for a read event. More...
 
virtual void writeEvent ()
 Called for a write event. More...
 
virtual void otherEvent (Reason)
 Called for a socket-exception event, or a socket-close event on windows. More...
 
- Public Member Functions inherited from GNet::FutureEventHandler
virtual ~FutureEventHandler ()=default
 Destructor.
 
virtual void onFutureEvent ()=0
 Callback function that delivers the future event.
 

Static Public Member Functions

static bool supported ()
 Returns false if a stubbed-out implementation. More...
 
static bool active ()
 Returns true if the implementation can raise InterfacesHandler events. More...
 
- Static Public Member Functions inherited from GNet::EventHandler
static std::string str (Reason)
 Returns a printable description of the other-event reason. More...
 

Detailed Description

A class for getting a list of network interfaces and their addresses.

Definition at line 44 of file ginterfaces.h.

Member Typedef Documentation

◆ const_iterator

using GNet::Interfaces::const_iterator = std::vector<Item>::const_iterator

Definition at line 60 of file ginterfaces.h.

Constructor & Destructor Documentation

◆ Interfaces() [1/2]

GNet::Interfaces::Interfaces ( )
default

Default constructor resulting in an empty list.

Use load() to initialise.

◆ Interfaces() [2/2]

GNet::Interfaces::Interfaces ( ExceptionSink  es,
InterfacesHandler handler 
)

Constructor resulting in an empty list with an attached event handler.

Use load() or find() to initialise the list and activate the event listener.

Definition at line 30 of file ginterfaces_common.cpp.

Member Function Documentation

◆ active()

bool GNet::Interfaces::active ( )
static

Returns true if the implementation can raise InterfacesHandler events.

Definition at line 72 of file ginterfaces_unix.cpp.

◆ addresses()

std::vector< GNet::Address > GNet::Interfaces::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.

Returns by reference (1) names that are, or have, addresses, (2) names that might be interfaces with no bound addresses, and (3) the remainder, ie. names that are not addresses and cannot be a valid interface name.

Definition at line 100 of file ginterfaces_common.cpp.

◆ begin()

GNet::Interfaces::const_iterator GNet::Interfaces::begin ( ) const

Returns a begin iterator.

Definition at line 147 of file ginterfaces_common.cpp.

◆ end()

GNet::Interfaces::const_iterator GNet::Interfaces::end ( ) const

Returns a one-off-the-end iterator.

Definition at line 152 of file ginterfaces_common.cpp.

◆ find()

std::vector< GNet::Address > GNet::Interfaces::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.

If the decoration flag is used and the name is decorated with "-ipv4" or "-ipv6" then only those addresses are returned. The returned addresses all have the given port number. Returns the empty list if not found or if found but not up. Does lazy load()ing.

Definition at line 58 of file ginterfaces_common.cpp.

◆ load()

void GNet::Interfaces::load ( )

Loads or reloads the list.

Definition at line 39 of file ginterfaces_common.cpp.

◆ loaded()

bool GNet::Interfaces::loaded ( ) const

Returns true if load()ed.

Definition at line 53 of file ginterfaces_common.cpp.

◆ names()

G::StringArray GNet::Interfaces::names ( bool  all = false) const

Returns the interface names, optionally including interfaces that are not up.

Definition at line 134 of file ginterfaces_common.cpp.

◆ supported()

bool GNet::Interfaces::supported ( )
static

Returns false if a stubbed-out implementation.

Definition at line 48 of file ginterfaces_common.cpp.


The documentation for this class was generated from the following files: