1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
/*
* Represents an Inet interface
* Copyright (C) 2002 Tim Jansen <tim@tjansen.de>
*
* $Id$
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef KINETINTERFACE_H
#define KINETINTERFACE_H
#include <qvaluevector.h>
#include <qcstring.h>
#include <qstring.h>
class KInetInterfacePrivate;
class KInetSocketAddress;
/**
* An Internet (IPv4 or IPv6) network interface.
*
* Represents a snapshot of the network interface's state. It is
* not possible to modify the interface using this class, only
* to read it. Note that the interfaces can change it any time
* (for example when the internet connection goes up or down),
* so when you use it in a server you may want to use it together
* with a @ref KInetInterfaceWatcher.
* Use @ref getAllInterfaces() to get all interfaces of a system.
*
* @author Tim Jansen <tim@tjansen.de>
* @short Represents an IPv4 or IPv6 Network Interface
* @see KInetInterfaceWatcher
* @since 3.2
*/
class KInetInterface {
private:
KInetInterface(const QString &name,
int flags,
KInetSocketAddress *address,
KInetSocketAddress *netmask,
KInetSocketAddress *broadcast,
KInetSocketAddress *destination);
public:
/**
* Default constructor. Creates an uninitialized KInetInterface.
* @see isValid()
*/
KInetInterface();
/**
* Copy constructor. Makes a deep copy.
* @param i the KInetInterface to copy
*/
KInetInterface(const KInetInterface &i);
/**
* Destructor
*/
virtual ~KInetInterface();
/**
* Assignment, makes a deep copy of @p i.
* @param i the KInetInterface to copy
* @return this KInetInterface
*/
KInetInterface& operator =(const KInetInterface& i);
/**
* Checks whether the object is valid. Only interfaces that
* have been created using the default constructor are invalid.
* @return true if valid, false if invalid
*/
bool isValid() const;
/**
* Returns a user-readable name of the interface, if available.
* Otherwise it returns the same value as @ref name().
* @return the display name of the interface
* @see name()
*/
QString displayName() const;
/**
* Returns the name of the interface, e.g. 'eth0'.
* @return the name of the interface
* @see displayName()
*/
QString name() const;
/**
* Flags describing the interface. These flags
* can be ORed.
*/
enum Flags {
Up = 1, ///< Interface is up.
Broadcast = 2, ///< Broadcast address (@ref broadcastAddress()) is valid..
Loopback = 8, ///< Interface is a loopback interface.
PointToPoint = 16, ///< Interface is a point-to-point interface.
Running = 128, ///< Interface is running.
Multicast = 65536 ///< Interface is multicast-capable.
};
/**
* A set of ORed flags describing the interface. See
* @ref Flags for description of the flags.
* @return the ORed @ref Flags of the interface
*/
int flags() const;
/**
* Returns the address of the interface.
* The returned object is valid as long as this object
* exists.
* @return the address of this interface, can be 0 if the interface
* does not have an address
*/
KInetSocketAddress *address() const;
/**
* Returns the netmask of the interface.
* The returned object is valid as long as this object
* exists.
* @return the netmask of this interface, can be 0 if the interface
* does not have an address
*/
KInetSocketAddress *netmask() const;
/**
* Returns the broadcast address of the interface.
* The returned object is valid as long as this object
* exists.
* @return the broadcast address of this interface. Can be 0 if
* the interface is a peer-to-peer interface (like PPP)
*/
KInetSocketAddress *broadcastAddress() const;
/**
* Returns the destination / peer address of the interface.
* It is used for peer-to-peer interfaces like PPP.
* The returned object is valid as long as this object
* exists.
* @return the destination address of this interface. Can be 0
* if the interface is not a peer-to-peer interface
*/
KInetSocketAddress *destinationAddress() const;
/**
* Tries to guess the public internet address of this computer.
* This is not always successful, especially when the computer
* is behind a firewall or NAT gateway. In the worst case, it
* returns localhost.
* @return a KInetAddress object that contains the best match.
* The caller takes ownership of the object and is
* responsible for freeing it
*/
static KInetSocketAddress *getPublicInetAddress();
/**
* Returns all active interfaces of the system.
*
* @param includeLoopback if true, include the loopback interface's
* name
* @return the list of IP addresses
*/
static QValueVector<KInetInterface> getAllInterfaces(bool includeLoopback = false);
private:
KInetInterfacePrivate* d;
};
#endif
|