source: XMLIO_V2/external/include/Poco/Net/NetworkInterface.h @ 80

Last change on this file since 80 was 80, checked in by ymipsl, 14 years ago

ajout lib externe

  • Property svn:eol-style set to native
File size: 6.1 KB
Line 
1//
2// NetworkInterface.h
3//
4// $Id: //poco/1.3/Net/include/Poco/Net/NetworkInterface.h#7 $
5//
6// Library: Net
7// Package: Sockets
8// Module:  NetworkInterface
9//
10// Definition of the NetworkInterface class.
11//
12// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
13// and Contributors.
14//
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:
21//
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.
28//
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.
36//
37
38
39#ifndef Net_NetworkInterface_INCLUDED
40#define Net_NetworkInterface_INCLUDED
41
42
43#include "Poco/Net/Net.h"
44#include "Poco/Net/IPAddress.h"
45#include "Poco/Mutex.h"
46#include <vector>
47
48
49namespace Poco {
50namespace Net {
51
52
53class NetworkInterfaceImpl;
54
55
56class Net_API NetworkInterface
57        /// This class represents a network interface.
58        ///
59        /// NetworkInterface is used with MulticastSocket to specify
60        /// multicast interfaces for sending and receiving multicast
61        /// messages.
62{
63public:
64        typedef std::vector<NetworkInterface> NetworkInterfaceList;
65
66        NetworkInterface();
67                /// Creates a NetworkInterface representing the
68                /// default interface.
69                ///
70                /// The name is empty, the IP address is the wildcard
71                /// address and the index is zero.
72       
73        NetworkInterface(const NetworkInterface& interfc);
74                /// Creates the NetworkInterface by copying another one.
75
76        ~NetworkInterface();
77                /// Destroys the NetworkInterface.
78
79        NetworkInterface& operator = (const NetworkInterface& interfc);
80                /// Assigns another NetworkInterface.
81               
82        void swap(NetworkInterface& other);
83                /// Swaps the NetworkInterface with another one.       
84               
85        int index() const;
86                /// Returns the interface index.
87                ///
88                /// Only supported if IPv6 is available.
89                /// Returns -1 if IPv6 is not available.
90               
91        const std::string& name() const;
92                /// Returns the interface name.
93               
94        const std::string& displayName() const;
95                /// Returns the interface display name.
96                ///
97                /// On Windows platforms, this is currently the network adapter
98                /// name. This may change to the "friendly name" of the network
99                /// connection in a future version, however.
100                ///
101                /// On other platforms this is the same as name().
102               
103        const IPAddress& address() const;
104                /// Returns the IP address bound to the interface.
105               
106        const IPAddress& subnetMask() const;
107                /// Returns the IPv4 subnet mask for this network interface.
108               
109        const IPAddress& broadcastAddress() const;
110                /// Returns the IPv4 broadcast address for this network interface.
111               
112        bool supportsIPv4() const;
113                /// Returns true if the interface supports IPv4.
114               
115        bool supportsIPv6() const;
116                /// Returns true if the interface supports IPv6.       
117               
118        static NetworkInterface forName(const std::string& name, bool requireIPv6 = false);
119                /// Returns the NetworkInterface for the given name.
120                ///
121                /// If requireIPv6 is false, an IPv4 interface is returned.
122                /// Otherwise, an IPv6 interface is returned.
123                ///
124                /// Throws an InterfaceNotFoundException if an interface
125                /// with the give name does not exist.
126               
127        static NetworkInterface forAddress(const IPAddress& address);
128                /// Returns the NetworkInterface for the given IP address.
129                ///
130                /// Throws an InterfaceNotFoundException if an interface
131                /// with the give address does not exist.
132
133        static NetworkInterface forIndex(int index);
134                /// Returns the NetworkInterface for the given interface index.
135                /// If an index of 0 is specified, a NetworkInterface instance
136                /// representing the default interface (empty name and
137                /// wildcard address) is returned.
138                ///
139                /// Throws an InterfaceNotFoundException if an interface
140                /// with the given index does not exist (or IPv6 is not
141                /// available).
142               
143        static NetworkInterfaceList list();
144                /// Returns a list with all network interfaces
145                /// on the system.
146                ///
147                /// If there are multiple addresses bound to one interface,
148                /// multiple NetworkInterface instances are created for
149                /// the same interface.
150
151protected:
152        NetworkInterface(const std::string& name, const std::string& displayName, const IPAddress& address, int index = -1);
153                /// Creates the NetworkInterface.
154
155        NetworkInterface(const std::string& name, const std::string& displayName, const IPAddress& address, const IPAddress& subnetMask, const IPAddress& broadcastAddress, int index = -1);
156                /// Creates the NetworkInterface.
157               
158        NetworkInterface(const std::string& name, const IPAddress& address, int index = -1);
159                /// Creates the NetworkInterface.
160
161        NetworkInterface(const std::string& name, const IPAddress& address, const IPAddress& subnetMask, const IPAddress& broadcastAddress, int index = -1);
162                /// Creates the NetworkInterface.
163               
164        IPAddress interfaceNameToAddress(const std::string& interfaceName) const;
165                /// Determines the IPAddress bound to the interface with the given name.
166               
167        int interfaceNameToIndex(const std::string& interfaceName) const;
168                /// Determines the interface index of the interface with the given name.
169
170private:
171        NetworkInterfaceImpl* _pImpl;
172       
173        static Poco::FastMutex _mutex;
174};
175
176
177} } // namespace Poco::Net
178
179
180#endif // Net_NetworkInterface_INCLUDED
Note: See TracBrowser for help on using the repository browser.