libcommonc++  0.7
NetworkInterface.h++
Go to the documentation of this file.
1 /* ---------------------------------------------------------------------------
2  commonc++ - A C++ Common Class Library
3  Copyright (C) 2005-2014 Mark A Lindner
4 
5  This file is part of commonc++.
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public
18  License along with this library; if not, write to the Free
19  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  ---------------------------------------------------------------------------
21 */
22 
23 #ifndef __ccxx_NetworkInterface_hxx
24 #define __ccxx_NetworkInterface_hxx
25 
26 #include <commonc++/Common.h++>
28 #include <commonc++/MACAddress.h++>
29 #include <commonc++/String.h++>
30 
31 namespace ccxx {
32 
39 {
40  friend class Network;
41 
42  public:
43 
45  static const uint32_t FLAG_UP;
46 
48  static const uint32_t FLAG_BROADCAST;
49 
51  static const uint32_t FLAG_LOOPBACK;
52 
54  static const uint32_t FLAG_PPP;
55 
57  static const uint32_t FLAG_RUNNING;
58 
60  static const uint32_t FLAG_MULTICAST;
61 
63  static const uint32_t FLAG_MASK;
64 
67 
69  inline String getName() const
70  { return(_name); }
71 
73  inline InetAddress getAddress() const
74  { return(_addr); }
75 
78  { return(_hwAddr); }
79 
82  { return(_broadcastAddr); }
83 
85  inline InetAddress getDestAddress() const
86  { return(_destAddr); }
87 
89  inline InetAddress getNetMask() const
90  { return(_netmask); }
91 
93  inline uint_t getPrefixLength() const
94  { return(_prefixLength); }
95 
97  inline uint32_t getFlags() const
98  { return(_flags); }
99 
101  inline bool isUp() const
102  { return((_flags & FLAG_UP) != 0); }
103 
105  inline bool isBroadcastSupported() const
106  { return((_flags & FLAG_BROADCAST) != 0); }
107 
109  inline bool isMulticastSupported() const
110  { return((_flags & FLAG_MULTICAST) != 0); }
111 
113  inline bool isLoopback() const
114  { return((_flags & FLAG_LOOPBACK) != 0); }
115 
117  inline bool isPPP() const
118  { return((_flags & FLAG_PPP) != 0); }
119 
121  inline bool isRunning() const
122  { return((_flags & FLAG_RUNNING) != 0); }
123 
125  inline int getMTU() const
126  { return(_mtu); }
127 
129  inline int getMetric() const
130  { return(_metric); }
131 
132  private:
133 
135 
136  inline void setName(const String& name)
137  { _name = name; }
138 
139  inline void setAddress(const InetAddress& addr)
140  { _addr = addr; }
141 
142  inline void setHardwareAddress(const MACAddress& addr)
143  { _hwAddr = addr; }
144 
145  inline void setBroadcastAddress(const InetAddress& addr)
146  { _broadcastAddr = addr; }
147 
148  inline void setDestAddress(const InetAddress& addr)
149  { _destAddr = addr; }
150 
151  void setNetmask(const InetAddress& addr);
152 
153  inline void setUp(bool flag)
154  { flag ? _flags |= FLAG_UP : _flags &= ~FLAG_UP; }
155 
156  inline void setBroadcastSupported(bool flag)
157  { flag ? _flags |= FLAG_BROADCAST : _flags &= ~FLAG_BROADCAST; }
158 
159  inline void setLoopback(bool flag)
160  { flag ? _flags |= FLAG_LOOPBACK : _flags &= ~FLAG_LOOPBACK; }
161 
162  inline void setPPP(bool flag)
163  { flag ? _flags |= FLAG_PPP : _flags &= ~FLAG_PPP; }
164 
165  inline void setRunning(bool flag)
166  { flag ? _flags |= FLAG_RUNNING : _flags &= ~FLAG_RUNNING; }
167 
168  inline void setMulticastSupported(bool flag)
169  { flag ? _flags |= FLAG_MULTICAST : _flags &= ~FLAG_MULTICAST; }
170 
171  inline void setFlags(int flags)
172  { _flags = flags & FLAG_MASK; }
173 
174  inline void setMTU(int mtu)
175  { _mtu = mtu; }
176 
177  inline void setMetric(int metric)
178  { _metric = metric; }
179 
180  String _name;
181  MACAddress _hwAddr;
182  InetAddress _addr;
183  InetAddress _broadcastAddr;
184  InetAddress _destAddr;
185  InetAddress _netmask;
186  int _mtu;
187  int _metric;
188  uint_t _prefixLength;
189  uint32_t _flags;
190 };
191 
192 } // namespace ccxx
193 
194 #endif // __ccxx_NetworkInterface_hxx
A network hardware (MAC) address.
Definition: MACAddress.h++:37
static const uint32_t FLAG_BROADCAST
A flag indicating that an interface has broadcast capability.
Definition: NetworkInterface.h++:48
String getName() const
Get the interface name.
Definition: NetworkInterface.h++:69
int getMTU() const
Get the maximum transmission unit (MTU).
Definition: NetworkInterface.h++:125
InetAddress getNetMask() const
Get the netmask.
Definition: NetworkInterface.h++:89
static const uint32_t FLAG_RUNNING
A flag indicating that an interface is running.
Definition: NetworkInterface.h++:57
bool isRunning() const
Test if the interface is running.
Definition: NetworkInterface.h++:121
An aggregation of information about a network interface.
Definition: NetworkInterface.h++:38
static const uint32_t FLAG_MASK
Flag mask (all flag bits set).
Definition: NetworkInterface.h++:63
static const uint32_t FLAG_LOOPBACK
A flag identifying an interface as a loopback interface.
Definition: NetworkInterface.h++:51
bool isUp() const
Test if the interface is up.
Definition: NetworkInterface.h++:101
unsigned int uint_t
An alias for unsigned int.
Definition: Integers.h++:74
int getMetric() const
Get the routing metric.
Definition: NetworkInterface.h++:129
uint32_t getFlags() const
Get the interface flags.
Definition: NetworkInterface.h++:97
static const uint32_t FLAG_PPP
A flag identifying an interface as a Point-to-Point link interface.
Definition: NetworkInterface.h++:54
static const uint32_t FLAG_MULTICAST
A flag indicating that an interface has multicast capability.
Definition: NetworkInterface.h++:60
InetAddress getAddress() const
Get the unicast address.
Definition: NetworkInterface.h++:73
InetAddress getBroadcastAddress() const
Get the broadcast address.
Definition: NetworkInterface.h++:81
bool isBroadcastSupported() const
Test if the interface has broadcast capability.
Definition: NetworkInterface.h++:105
#define COMMONCPP_API
Definition: Common.h++:126
A flexible, reference counted, copy-on-write, thread-safe, nullable string.
Definition: String.h++:50
Network-related routines.
Definition: Network.h++:54
bool isMulticastSupported() const
Test if the interface has multicast capability.
Definition: NetworkInterface.h++:109
bool isLoopback() const
Test if the interface is a loopback interface.
Definition: NetworkInterface.h++:113
InetAddress getDestAddress() const
Get the destination address.
Definition: NetworkInterface.h++:85
bool isPPP() const
Test if the interface is a PPP interface.
Definition: NetworkInterface.h++:117
An IPv4 Internet address.
Definition: InetAddress.h++:64
MACAddress getHardwareAddress() const
Get the hardware (MAC) address.
Definition: NetworkInterface.h++:77
Definition: AllocationMap.c++:25
static const uint32_t FLAG_UP
A flag indicating that an interface is up.
Definition: NetworkInterface.h++:45
uint_t getPrefixLength() const
Get the subnet prefix length.
Definition: NetworkInterface.h++:93