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