4
// $Id: //poco/1.2/Net/include/Poco/Net/NetworkInterface.h#1 $
8
// Module: NetworkInterface
10
// Definition of the NetworkInterface class.
12
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
15
// Permission is hereby granted, free of charge, to any person or organization
16
// obtaining a copy of the software and accompanying documentation covered by
17
// this license (the "Software") to use, reproduce, display, distribute,
18
// execute, and transmit the Software, and to prepare derivative works of the
19
// Software, and to permit third-parties to whom the Software is furnished to
20
// do so, all subject to the following:
22
// The copyright notices in the Software and this entire statement, including
23
// the above license grant, this restriction and the following disclaimer,
24
// must be included in all copies of the Software, in whole or in part, and
25
// all derivative works of the Software, unless such copies or derivative
26
// works are solely in the form of machine-executable object code generated by
27
// a source language processor.
29
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
32
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
33
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
34
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
35
// DEALINGS IN THE SOFTWARE.
39
#ifndef Net_NetworkInterface_INCLUDED
40
#define Net_NetworkInterface_INCLUDED
43
#include "Poco/Net/Net.h"
44
#include "Poco/Net/IPAddress.h"
45
#include "Poco/Mutex.h"
53
class Net_API NetworkInterface
54
/// This class represents a network interface.
56
/// NetworkInterface is used with MulticastSocket to specify
57
/// multicast interfaces for sending and receiving multicast
61
typedef std::vector<NetworkInterface> NetworkInterfaceList;
64
/// Creates a NetworkInterface representing the
65
/// default interface.
67
/// The name is empty, the IP address is the wildcard
68
/// address and the index is zero.
70
NetworkInterface(const NetworkInterface& interface);
71
/// Creates the NetworkInterface by copying another one.
74
/// Destroys the NetworkInterface.
76
NetworkInterface& operator = (const NetworkInterface& interface);
77
/// Assigns another NetworkInterface.
80
/// Returns the interface index.
82
/// Only supported if IPv6 is available.
83
/// Returns -1 if IPv6 is not available.
85
const std::string& name() const;
86
/// Returns the interface name.
88
const IPAddress& address() const;
89
/// Returns the IP address bound to the interface.
91
bool supportsIPv4() const;
92
/// Returns true if the interface supports IPv4.
94
bool supportsIPv6() const;
95
/// Returns true if the interface supports IPv6.
97
static NetworkInterface forName(const std::string& name, bool requireIPv6 = false);
98
/// Returns the NetworkInterface for the given name.
100
/// If requireIPv6 is false, an IPv4 interface is returned.
101
/// Otherwise, an IPv6 interface is returned.
103
/// Throws an InterfaceNotFoundException if an interface
104
/// with the give name does not exist.
106
static NetworkInterface forAddress(const IPAddress& address);
107
/// Returns the NetworkInterface for the given IP address.
109
/// Throws an InterfaceNotFoundException if an interface
110
/// with the give address does not exist.
112
static NetworkInterface forIndex(int index);
113
/// Returns the NetworkInterface for the given interface index.
114
/// If an index of 0 is specified, a NetworkInterface instance
115
/// representing the default interface (empty name and
116
/// wildcard address) is returned.
118
/// Throws an InterfaceNotFoundException if an interface
119
/// with the given index does not exist (or IPv6 is not
122
static NetworkInterfaceList list();
123
/// Returns a list with all network interfaces
126
/// If there are multiple addresses bound to one interface,
127
/// multiple NetworkInterface instances are created for
128
/// the same interface.
131
NetworkInterface(const std::string& name, const IPAddress& address, int index = -1);
132
/// Creates the NetworkInterface.
134
IPAddress interfaceNameToAddress(const std::string& interfaceName) const;
135
/// Determines the IPAddress bound to the interface with the given name.
137
int interfaceNameToIndex(const std::string& interfaceName) const;
138
/// Determines the interface index of the interface with the given name.
145
static Poco::FastMutex _mutex;
152
inline int NetworkInterface::index() const
158
inline const std::string& NetworkInterface::name() const
164
inline const IPAddress& NetworkInterface::address() const
170
inline bool NetworkInterface::supportsIPv4() const
176
inline bool NetworkInterface::supportsIPv6() const
182
} } // namespace Poco::Net
185
#endif // Net_NetworkInterface_INCLUDED