Library: Net
Package: Sockets
Header: Poco/Net/NetworkInterface.h
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 Functions: address, broadcastAddress, displayName, forAddress, forIndex, forName, index, interfaceNameToAddress, interfaceNameToIndex, list, name, operator =, subnetMask, supportsIPv4, supportsIPv6, swap
typedef std::vector < NetworkInterface > NetworkInterfaceList;
Return interfaces with IPv4 address only
Return interfaces with IPv6 address only
Return interfaces with IPv4 or IPv6 address
Creates a NetworkInterface representing the default interface.
The name is empty, the IP address is the wildcard address and the index is zero.
NetworkInterface(
const NetworkInterface & interfc
);
Creates the NetworkInterface by copying another one.
NetworkInterface(
const std::string & name,
const IPAddress & address,
int index = - 1
);
Creates the NetworkInterface.
NetworkInterface(
const std::string & name,
const std::string & displayName,
const IPAddress & address,
int index = - 1
);
Creates the NetworkInterface.
NetworkInterface(
const std::string & name,
const IPAddress & address,
const IPAddress & subnetMask,
const IPAddress & broadcastAddress,
int index = - 1
);
Creates the 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.
~NetworkInterface();
Destroys the NetworkInterface.
const IPAddress & address() const;
Returns the IP address bound to the interface.
const IPAddress & broadcastAddress() const;
Returns the IPv4 broadcast address for this network interface.
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().
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.
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).
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.
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).
int index() const;
Returns the interface index.
Only supported if IPv6 is available. Returns -1 if IPv6 is not available.
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.
const std::string & name() const;
Returns the interface name.
NetworkInterface & operator = (
const NetworkInterface & interfc
);
Assigns another NetworkInterface.
const IPAddress & subnetMask() const;
Returns the IPv4 subnet mask for this network interface.
bool supportsIPv4() const;
Returns true if the interface supports IPv4.
bool supportsIPv6() const;
Returns true if the interface supports IPv6.
void swap(
NetworkInterface & other
);
Swaps the NetworkInterface with another one.
IPAddress interfaceNameToAddress(
const std::string & interfaceName
) const;
Determines the IPAddress bound to the interface with the given name.
int interfaceNameToIndex(
const std::string & interfaceName
) const;
Determines the interface index of the interface with the given name.