libtins  4.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
Tins::NetworkInterface Class Reference

Abstraction of a network interface. More...

#include <network_interface.h>

Classes

struct  Info
 Struct that holds an interface's addresses. More...
 
struct  IPv6Prefix
 

Public Types

typedef uint32_t id_type
 The type used to store the interface's identifier.
 
typedef HWAddress< 6 > address_type
 The type of this interface's address.
 

Public Member Functions

 NetworkInterface ()
 
 NetworkInterface (const std::string &name)
 Constructor from std::string. More...
 
 NetworkInterface (const char *name)
 Constructor from const char*. More...
 
 NetworkInterface (IPv4Address ip)
 Constructs a NetworkInterface from an ip address. More...
 
 NetworkInterface (IPv6Address ipv6)
 Constructs a NetworkInterface from an ipv6 address. More...
 
id_type id () const
 Getter for this interface's identifier. More...
 
std::string name () const
 Retrieves this interface's name. More...
 
std::wstring friendly_name () const
 Retrieves this interface's friendly name. More...
 
Info addresses () const
 Retrieve this interface's addresses. More...
 
Info info () const
 Retrieve this interface's information. More...
 
 operator bool () const
 Tests whether this is a valid interface;. More...
 
bool is_loopback () const
 Indicates whether this is a loopback device. More...
 
bool is_up () const
 Indicates whether this interface is up. More...
 
address_type hw_address () const
 Retrieves the hardware address for this interface.
 
IPv4Address ipv4_address () const
 Retrieves the IPv4 address for this interface.
 
IPv4Address ipv4_mask () const
 Retrieves the IPv4 netmask for this interface.
 
IPv4Address ipv4_broadcast () const
 Retrieves the broadcast IPv4 address for this interface.
 
std::vector< IPv6Prefixipv6_addresses () const
 Retrieves the IPv6 addresses for this interface.
 
bool operator== (const NetworkInterface &rhs) const
 Compares this interface for equality. More...
 
bool operator!= (const NetworkInterface &rhs) const
 Compares this interface for inequality. More...
 

Static Public Member Functions

static NetworkInterface default_interface ()
 
static std::vector< NetworkInterfaceall ()
 
static NetworkInterface from_index (id_type identifier)
 

Detailed Description

Abstraction of a network interface.

Constructor & Destructor Documentation

Tins::NetworkInterface::NetworkInterface ( )

Default constructor.

Tins::NetworkInterface::NetworkInterface ( const std::string &  name)

Constructor from std::string.

Parameters
nameThe name of the interface this object will abstract.
Tins::NetworkInterface::NetworkInterface ( const char *  name)

Constructor from const char*.

Parameters
nameThe name of the interface this object will abstract.
Tins::NetworkInterface::NetworkInterface ( IPv4Address  ip)

Constructs a NetworkInterface from an ip address.

This abstracted interface will be the one that would be the gateway when sending a packet to the given ip.

Parameters
ipThe ip address being looked up.
Tins::NetworkInterface::NetworkInterface ( IPv6Address  ipv6)

Constructs a NetworkInterface from an ipv6 address.

This abstracted interface will be the one that would be the gateway when sending a packet to the given ip.

Parameters
ipThe ipv6 address being looked up.

Member Function Documentation

NetworkInterface::Info Tins::NetworkInterface::addresses ( ) const

Retrieve this interface's addresses.

This method is deprecated. You should use NetworkInterface::info (this is just a naming deprecation, NetworkInterface::info is equivalent).

Deprecated:
vector< NetworkInterface > Tins::NetworkInterface::all ( )
static

Returns all available network interfaces.

NetworkInterface Tins::NetworkInterface::default_interface ( )
static

Returns a NetworkInterface object associated with the default interface.

wstring Tins::NetworkInterface::friendly_name ( ) const

Retrieves this interface's friendly name.

The name returned by this method can be more human-friendly than the one returned by NetworkInterface::name, depending on the platform in which it's used.

On GNU/Linux and OSX/FreeBSD, this returns the same string as NetworkInterface::name.

On Windows, this method returns a name such as "Local Area Connection 1".

Note thaat this returns a wstring rather than a string, to comply with Window's adapter's FriendlyName type.

Returns
std::wstring containing this interface's name.
NetworkInterface Tins::NetworkInterface::from_index ( id_type  identifier)
static

Returns a network interface for the given index.

id_type Tins::NetworkInterface::id ( ) const
inline

Getter for this interface's identifier.

Returns
id_type containing the identifier.
NetworkInterface::Info Tins::NetworkInterface::info ( ) const

Retrieve this interface's information.

This method iterates through all the interface's until the correct one is found. Therefore it's O(N), being N the amount of interfaces in the system.

bool Tins::NetworkInterface::is_loopback ( ) const

Indicates whether this is a loopback device.

Returns
true iff this is a loopback device.
bool Tins::NetworkInterface::is_up ( ) const

Indicates whether this interface is up.

This is equivalent to getting the interface info and checking for the is_up attribute.

string Tins::NetworkInterface::name ( ) const

Retrieves this interface's name.

This name can be used as the interface name provided to the Sniffer class when starting a sniffing session.

See also
Sniffer
Returns
std::string containing this interface's name.
Tins::NetworkInterface::operator bool ( ) const
inline

Tests whether this is a valid interface;.

An interface will not be valid iff it was created using the default constructor.

bool Tins::NetworkInterface::operator!= ( const NetworkInterface rhs) const
inline

Compares this interface for inequality.

Parameters
rhsThe interface being compared.
bool Tins::NetworkInterface::operator== ( const NetworkInterface rhs) const
inline

Compares this interface for equality.

Parameters
rhsThe interface being compared.

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