libDwm-0.9.45
DwmLocalInterfaces.hh
Go to the documentation of this file.
1//===========================================================================
2// @(#) $DwmPath$
3//===========================================================================
4// Copyright (c) Daniel W. McRobb 2005, 2016
5// All rights reserved.
6//
7// Redistribution and use in source and binary forms, with or without
8// modification, are permitted provided that the following conditions
9// are met:
10//
11// 1. Redistributions of source code must retain the above copyright
12// notice, this list of conditions and the following disclaimer.
13// 2. Redistributions in binary form must reproduce the above copyright
14// notice, this list of conditions and the following disclaimer in the
15// documentation and/or other materials provided with the distribution.
16// 3. The names of the authors and copyright holders may not be used to
17// endorse or promote products derived from this software without
18// specific prior written permission.
19//
20// IN NO EVENT SHALL DANIEL W. MCROBB BE LIABLE TO ANY PARTY FOR
21// DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
22// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE,
23// EVEN IF DANIEL W. MCROBB HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
24// DAMAGE.
25//
26// THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND
27// DANIEL W. MCROBB HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
28// UPDATES, ENHANCEMENTS, OR MODIFICATIONS. DANIEL W. MCROBB MAKES NO
29// REPRESENTATIONS AND EXTENDS NO WARRANTIES OF ANY KIND, EITHER
30// IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
31// WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE,
32// OR THAT THE USE OF THIS SOFTWARE WILL NOT INFRINGE ANY PATENT,
33// TRADEMARK OR OTHER RIGHTS.
34//===========================================================================
35
36//---------------------------------------------------------------------------
40//---------------------------------------------------------------------------
41
42#ifndef _DWMLOCALINTERFACES_HH_
43#define _DWMLOCALINTERFACES_HH_
44
45extern "C" {
46 #include <sys/types.h>
47 #include <sys/socket.h>
48 #include <netinet/in.h>
49 #include <arpa/inet.h>
50}
51
52#include <set>
53#include <string>
54#include <map>
55
56#include "DwmIpv4Address.hh"
57
58namespace Dwm {
59
60 //--------------------------------------------------------------------------
62 //--------------------------------------------------------------------------
64 {
65 public:
66 //------------------------------------------------------------------------
68 //------------------------------------------------------------------------
70
71 //------------------------------------------------------------------------
73 //------------------------------------------------------------------------
74 LocalInterfaceAlias(const Ipv4Address & address, const Ipv4Address & mask);
75
76 //------------------------------------------------------------------------
78 //------------------------------------------------------------------------
79 const Ipv4Address & Addr() const;
80
81 //------------------------------------------------------------------------
83 //------------------------------------------------------------------------
84 const Ipv4Address & Addr(const Ipv4Address & addr);
85
86 //------------------------------------------------------------------------
88 //------------------------------------------------------------------------
89 const Ipv4Address & Mask() const;
90
91 //------------------------------------------------------------------------
93 //------------------------------------------------------------------------
94 const Ipv4Address & Mask(const Ipv4Address & mask);
95
96 //------------------------------------------------------------------------
98 //------------------------------------------------------------------------
99 bool operator < (const LocalInterfaceAlias & alias) const;
100
101 //------------------------------------------------------------------------
103 //------------------------------------------------------------------------
104 bool operator == (const LocalInterfaceAlias & alias) const;
105
106 //------------------------------------------------------------------------
108 //------------------------------------------------------------------------
109 friend std::ostream &
110 operator << (std::ostream & os, const LocalInterfaceAlias & alias);
111
112 private:
113 Ipv4Address _addr;
114 Ipv4Address _mask;
115 };
116
117 //------------------------------------------------------------------------
120 //------------------------------------------------------------------------
122 {
123 public:
124 //------------------------------------------------------------------------
126 //------------------------------------------------------------------------
128
129 //--------------------------------------------------------------------
131 //--------------------------------------------------------------------
132 const std::string & Name() const;
133
134 //--------------------------------------------------------------------
136 //--------------------------------------------------------------------
137 const std::string & Name(const std::string & name);
138
139 //--------------------------------------------------------------------
141 //--------------------------------------------------------------------
142 const Ipv4Address & Addr() const;
143
144 //--------------------------------------------------------------------
146 //--------------------------------------------------------------------
147 const Ipv4Address & Addr(const Ipv4Address & addr);
148
149 //--------------------------------------------------------------------
151 //--------------------------------------------------------------------
152 const Ipv4Address & Mask() const;
153
154 //--------------------------------------------------------------------
156 //--------------------------------------------------------------------
157 const Ipv4Address & Mask(const Ipv4Address & mask);
158
159 //------------------------------------------------------------------------
161 //------------------------------------------------------------------------
162 int Mtu() const;
163
164 //------------------------------------------------------------------------
166 //------------------------------------------------------------------------
167 int Mtu(int mtu);
168
169 //--------------------------------------------------------------------
172 //--------------------------------------------------------------------
173 bool IsUp() const;
174
175 bool IsRunning() const;
176
177 //------------------------------------------------------------------------
180 //------------------------------------------------------------------------
181 bool AddAlias(const Ipv4Address & address, const Ipv4Address & netmask);
182
183 //------------------------------------------------------------------------
186 //------------------------------------------------------------------------
187 bool RemoveAlias(const Ipv4Address & address, const Ipv4Address & netmask);
188
189 //------------------------------------------------------------------------
191 //------------------------------------------------------------------------
192 const std::set<LocalInterfaceAlias> & Aliases() const;
193
194 //------------------------------------------------------------------------
196 //------------------------------------------------------------------------
197 std::set<LocalInterfaceAlias> & Aliases();
198
199 //------------------------------------------------------------------------
201 //------------------------------------------------------------------------
202 friend std::ostream & operator << (std::ostream & os,
203 const LocalInterface & li);
204
205 private:
206 std::string _name;
207 Ipv4Address _addr;
208 Ipv4Address _mask;
209 int _mtu;
210 std::set<LocalInterfaceAlias> _aliases;
211 };
212
213 //------------------------------------------------------------------------
217 //------------------------------------------------------------------------
218 bool GetLocalInterfaces(std::map<std::string,LocalInterface> & interfaces);
219
220} // namespace Dwm
221
222#endif // _DWMLOCALINTERFACES_HH_
223
224//---------------------------- emacs settings -----------------------------
225// Local Variables:
226// mode: C++
227// tab-width: 2
228// indent-tabs-mode: nil
229// c-basic-offset: 2
230// End:
231//-------------------------------------------------------------------------
Dwm::Ipv4Address class definition.
bool GetLocalInterfaces(std::map< std::string, LocalInterface > &interfaces)
Fetches local interfaces with IP addresses into interfaces.
This class encapsulates an IPv4 address.
Definition DwmIpv4Address.hh:63
Holds an interface alias, which is just IP address and netmask.
Definition DwmLocalInterfaces.hh:64
bool operator==(const LocalInterfaceAlias &alias) const
operator ==
const Ipv4Address & Mask(const Ipv4Address &mask)
Sets and returns the netmask.
const Ipv4Address & Addr() const
Returns the IP address.
bool operator<(const LocalInterfaceAlias &alias) const
operator <
LocalInterfaceAlias()
Constructor.
const Ipv4Address & Addr(const Ipv4Address &addr)
Sets and returns the IP address.
friend std::ostream & operator<<(std::ostream &os, const LocalInterfaceAlias &alias)
Prints a LocalInterfaceAlias to an ostream.
const Ipv4Address & Mask() const
Returns the netmask.
LocalInterfaceAlias(const Ipv4Address &address, const Ipv4Address &mask)
Construct from an address and netmask.
Simple class to hold the name and IPv4 address of a local interface.
Definition DwmLocalInterfaces.hh:122
const std::string & Name() const
Returns the interface name.
bool RemoveAlias(const Ipv4Address &address, const Ipv4Address &netmask)
Removes an alias with the given address and netmask.
const Ipv4Address & Addr(const Ipv4Address &addr)
Sets and returns the interface address.
bool IsUp() const
Returns true if the interface is administratively 'up'.
bool AddAlias(const Ipv4Address &address, const Ipv4Address &netmask)
Adds an alias with the given address and netmask.
std::set< LocalInterfaceAlias > & Aliases()
Returns a mutable reference to the aliases.
const Ipv4Address & Mask(const Ipv4Address &mask)
Sets and returns the interface netmask.
int Mtu(int mtu)
Sets and returns the MTU.
const Ipv4Address & Mask() const
Returns the interface netmask.
friend std::ostream & operator<<(std::ostream &os, const LocalInterface &li)
Prints a LocalInterface to an ostream.
const std::set< LocalInterfaceAlias > & Aliases() const
Returns a const reference to the aliases.
int Mtu() const
Returns the MTU.
const std::string & Name(const std::string &name)
Sets and returns the interface name.
LocalInterface()
Constructor.
const Ipv4Address & Addr() const
Returns the interface address.