Poco::Net

class NetworkInterface

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.

Member Summary

Member Functions: address, forAddress, forIndex, forName, index, interfaceNameToAddress, interfaceNameToIndex, list, name, operator =, supportsIPv4, supportsIPv6

Types

NetworkInterfaceList

typedef std::vector < NetworkInterface > NetworkInterfaceList;

Constructors

NetworkInterface

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 & interface
);

Creates the NetworkInterface by copying another one.

NetworkInterface protected

NetworkInterface(
    const std::string & name,
    const IPAddress & address,
    int index = - 1
);

Creates the NetworkInterface.

Destructor

~NetworkInterface

~NetworkInterface();

Destroys the NetworkInterface.

Member Functions

address inline

const IPAddress & address() const;

Returns the IP address bound to the interface.

forAddress static

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

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

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.

index inline

int index() const;

Returns the interface index.

Only supported if IPv6 is available. Returns -1 if IPv6 is not available.

list static

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 inline

const std::string & name() const;

Returns the interface name.

operator =

NetworkInterface & operator = (
    const NetworkInterface & interface
);

Assigns another NetworkInterface.

supportsIPv4 inline

bool supportsIPv4() const;

Returns true if the interface supports IPv4.

supportsIPv6 inline

bool supportsIPv6() const;

Returns true if the interface supports IPv6.

interfaceNameToAddress protected

IPAddress interfaceNameToAddress(
    const std::string & interfaceName
) const;

Determines the IPAddress bound to the interface with the given name.

interfaceNameToIndex protected

int interfaceNameToIndex(
    const std::string & interfaceName
) const;

Determines the interface index of the interface with the given name.