Library: Net
Package: Sockets
Header: Poco/Net/NetworkInterface.h
Description
This class represents a network interface.
NetworkInterface is used with MulticastSocket to specify multicast interfaces for sending and receiving multicast messages.
The class also provides static member functions for enumerating or searching network interfaces.
Member Summary
Member Functions: address, broadcastAddress, displayName, forAddress, forIndex, forName, index, interfaceNameToAddress, interfaceNameToIndex, list, name, operator =, subnetMask, supportsIPv4, supportsIPv6, swap
Types
NetworkInterfaceList
typedef std::vector < NetworkInterface > NetworkInterfaceList;
Enumerations
IPVersion
Return interfaces with IPv4 address only
Return interfaces with IPv6 address only
Return interfaces with IPv4 or IPv6 address
Constructors
NetworkInterface
Creates a NetworkInterface representing the default interface.
The name is empty, the IP address is the wildcard address and the index is zero.
NetworkInterface
NetworkInterface(
const NetworkInterface & interfc
);
Creates the NetworkInterface by copying another one.
NetworkInterface
NetworkInterface(
const std::string & name,
const IPAddress & address,
int index = - 1
);
Creates the NetworkInterface.
NetworkInterface
NetworkInterface(
const std::string & name,
const std::string & displayName,
const IPAddress & address,
int index = - 1
);
Creates the NetworkInterface.
NetworkInterface
NetworkInterface(
const std::string & name,
const IPAddress & address,
const IPAddress & subnetMask,
const IPAddress & broadcastAddress,
int index = - 1
);
Creates the NetworkInterface.
NetworkInterface
NetworkInterface(
const std::string & name,
const std::string & displayName,
const IPAddress & address,
const IPAddress & subnetMask,
const IPAddress & broadcastAddress,
int index = - 1
);
Creates the NetworkInterface.
Destructor
~NetworkInterface
~NetworkInterface();
Destroys the NetworkInterface.
Member Functions
address
const IPAddress & address() const;
Returns the IP address bound to the interface.
broadcastAddress
const IPAddress & broadcastAddress() const;
Returns the IPv4 broadcast address for this network interface.
displayName
const std::string & displayName() const;
Returns the interface display name.
On Windows platforms, this is currently the network adapter name. This may change to the "friendly name" of the network connection in a future version, however.
On other platforms this is the same as name().
forAddress
static NetworkInterface forAddress(
const IPAddress & address
);
Returns the NetworkInterface for the given IP address.
Throws an InterfaceNotFoundException if an interface with the give address does not exist.
forIndex
static NetworkInterface forIndex(
int index
);
Returns the NetworkInterface for the given interface index. If an index of 0 is specified, a NetworkInterface instance representing the default interface (empty name and wildcard address) is returned.
Throws an InterfaceNotFoundException if an interface with the given index does not exist (or IPv6 is not available).
forName
static NetworkInterface forName(
const std::string & name,
bool requireIPv6 = false
);
Returns the NetworkInterface for the given name.
If requireIPv6 is false, an IPv4 interface is returned. Otherwise, an IPv6 interface is returned.
Throws an InterfaceNotFoundException if an interface with the give name does not exist.
forName
static NetworkInterface forName(
const std::string & name,
IPVersion ipVersion
);
Returns the NetworkInterface for the given name.
The ipVersion argument can be used to specify whether an IPv4 (IPv4_ONLY) or IPv6 (IPv6_ONLY) interface is required, or whether the caller does not care (IPv4_OR_IPv6).
index
int index() const;
Returns the interface index.
Only supported if IPv6 is available. Returns -1 if IPv6 is not available.
list
static NetworkInterfaceList list();
Returns a list with all network interfaces on the system.
If there are multiple addresses bound to one interface, multiple NetworkInterface instances are created for the same interface.
name
const std::string & name() const;
Returns the interface name.
operator =
NetworkInterface & operator = (
const NetworkInterface & interfc
);
Assigns another NetworkInterface.
subnetMask
const IPAddress & subnetMask() const;
Returns the IPv4 subnet mask for this network interface.
supportsIPv4
bool supportsIPv4() const;
Returns true if the interface supports IPv4.
supportsIPv6
bool supportsIPv6() const;
Returns true if the interface supports IPv6.
swap
void swap(
NetworkInterface & other
);
Swaps the NetworkInterface with another one.
interfaceNameToAddress
IPAddress interfaceNameToAddress(
const std::string & interfaceName
) const;
Determines the IPAddress bound to the interface with the given name.
interfaceNameToIndex
int interfaceNameToIndex(
const std::string & interfaceName
) const;
Determines the interface index of the interface with the given name.