libDwm-0.6.0
DwmIpv6Prefix.hh
Go to the documentation of this file.
1 //===========================================================================
2 // @(#) $DwmPath: dwm/libDwm/tags/libDwm-0.6.0/include/DwmIpv6Prefix.hh 8401 $
3 // @(#) $Id: DwmIpv6Prefix.hh 8401 2016-04-17 06:44:31Z dwm $
4 //===========================================================================
5 // Copyright (c) Daniel W. McRobb 2005-2006, 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
33 // PURPOSE, OR THAT THE USE OF THIS SOFTWARE WILL NOT INFRINGE ANY
34 // PATENT, TRADEMARK OR OTHER RIGHTS.
35 //===========================================================================
36 
37 //---------------------------------------------------------------------------
40 //---------------------------------------------------------------------------
41 
42 #ifndef _DWMIPV6PREFIX_HH_
43 #define _DWMIPV6PREFIX_HH_
44 
45 extern "C" {
46  #include <inttypes.h>
47  #include <stdio.h>
48 }
49 
50 #include "DwmIpv6Address.hh"
51 #include "DwmReadable.hh"
52 #include "DwmWritable.hh"
53 #include "DwmGZReadable.hh"
54 #include "DwmGZWritable.hh"
55 #include "DwmBZ2Readable.hh"
56 #include "DwmBZ2Writable.hh"
57 
58 namespace Dwm {
59 
60  //--------------------------------------------------------------------------
62  //--------------------------------------------------------------------------
63  class Ipv6Prefix
64  : public Readable, public Writable,
65  public GZReadable, public GZWritable,
66  public BZ2Readable, public BZ2Writable
67  {
68  public:
69  //------------------------------------------------------------------------
71  //------------------------------------------------------------------------
72  Ipv6Prefix();
73 
74  //------------------------------------------------------------------------
76  //------------------------------------------------------------------------
77  Ipv6Prefix(const std::string & prefix);
78 
79  //------------------------------------------------------------------------
83  //------------------------------------------------------------------------
84  Ipv6Prefix(const Ipv6Address & network, uint8_t maskLength);
85 
86  //------------------------------------------------------------------------
88  //------------------------------------------------------------------------
89  Ipv6Prefix(const Ipv6Prefix & prefix);
90 
91  //------------------------------------------------------------------------
93  //------------------------------------------------------------------------
94  Ipv6Address Network() const;
95 
96  //------------------------------------------------------------------------
98  //------------------------------------------------------------------------
99  Ipv6Address Netmask() const;
100 
101  //------------------------------------------------------------------------
103  //------------------------------------------------------------------------
104  uint8_t MaskLength() const;
105 
106  //------------------------------------------------------------------------
109  //------------------------------------------------------------------------
110  bool Set(const Ipv6Address & network, uint8_t maskLength);
111 
112  //------------------------------------------------------------------------
114  //------------------------------------------------------------------------
115  bool operator < (const Ipv6Prefix & prefix) const;
116 
117  //------------------------------------------------------------------------
119  //------------------------------------------------------------------------
120  bool operator > (const Ipv6Prefix & prefix) const;
121 
122  //------------------------------------------------------------------------
124  //------------------------------------------------------------------------
125  bool operator == (const Ipv6Prefix & prefix) const;
126 
127  //------------------------------------------------------------------------
129  //------------------------------------------------------------------------
130  bool Contains(const Ipv6Address & addr) const;
131 
132  //------------------------------------------------------------------------
134  //------------------------------------------------------------------------
135  ssize_t Read(int fd);
136 
137  //------------------------------------------------------------------------
139  //------------------------------------------------------------------------
140  ssize_t Write(int fd) const;
141 
142  //------------------------------------------------------------------------
145  //------------------------------------------------------------------------
146  size_t Read(FILE *f);
147 
148  //------------------------------------------------------------------------
151  //------------------------------------------------------------------------
152  size_t Write(FILE *f) const;
153 
154  //------------------------------------------------------------------------
156  //------------------------------------------------------------------------
157  std::istream & Read(std::istream & is);
158 
159  //------------------------------------------------------------------------
161  //------------------------------------------------------------------------
162  std::ostream & Write(std::ostream & os) const;
163 
164  //------------------------------------------------------------------------
166  //------------------------------------------------------------------------
167  int Read(gzFile gzf);
168 
169  //------------------------------------------------------------------------
171  //------------------------------------------------------------------------
172  int Write(gzFile gzf) const;
173 
174  //------------------------------------------------------------------------
176  //------------------------------------------------------------------------
177  int BZRead(BZFILE *bzf);
178 
179  //------------------------------------------------------------------------
181  //------------------------------------------------------------------------
182  int BZWrite(BZFILE *bzf) const;
183 
184  //------------------------------------------------------------------------
186  //------------------------------------------------------------------------
187  friend std::ostream & operator << (std::ostream & os,
188  const Ipv6Prefix & prefix);
189 
190  //------------------------------------------------------------------------
193  //------------------------------------------------------------------------
194  std::string ToString() const;
195 
196  //------------------------------------------------------------------------
199  //------------------------------------------------------------------------
200  uint32_t StreamedLength() const;
201 
202  private:
203  struct in6_addr _addr;
204  uint8_t _length;
205 
206  inline uint8_t NumAddrBytes() const
207  {
208  return((_length + 7) / 8);
209  }
210 
211  };
212 
213 } // namespace Dwm
214 
215 #endif // _DWMIPV6PREFIX_HH_
216 
217 //---------------------------- emacs settings -----------------------------
218 // Local Variables:
219 // mode: C++/la
220 // tab-width: 2
221 // indent-tabs-mode: nil
222 // c-basic-offset: 2
223 // End:
224 //-------------------------------------------------------------------------
bool Contains(const Ipv6Address &addr) const
Returns true if addr falls within the prefix.
ssize_t Write(int fd) const
Writes the prefix to a file descriptor.
friend std::ostream & operator<<(std::ostream &os, const Ipv6Prefix &prefix)
Prints a prefix to an ostream in the usual colon-delimited form.
This class is a pure virtual class, defining an interface for classes that can write their contents t...
Definition: DwmGZWritable.hh:57
This class encapsulates an IPv6 address.
Definition: DwmIpv6Address.hh:59
Dwm::Writable pure virtual class definition.
Dwm::BZ2Readable pure virtual class definition.
Dwm::GZReadable pure virtual class definition.
std::string ToString() const
Returns a string representation of the prefix in the usual form, for example "1234:5678::/32".
Dwm::Readable pure virtual class definition.
Ipv6Prefix()
Constructor.
ssize_t Read(int fd)
Reads the prefix from a file descriptor.
This class is a pure virtual class, defining an interface for classes that can read their contents fr...
Definition: DwmBZ2Readable.hh:57
bool operator==(const Ipv6Prefix &prefix) const
Equal-to operator.
int BZWrite(BZFILE *bzf) const
Writes the prefix to a BZFILE pointer.
Ipv6Address Netmask() const
Returns the netmask.
bool operator<(const Ipv6Prefix &prefix) const
Less-than operator.
uint32_t StreamedLength() const
Returns the number of bytes that would be written if the prefix was written to a file descriptor or o...
bool Set(const Ipv6Address &network, uint8_t maskLength)
Set the prefix using a network address and netmask length.
Dwm::BZ2Writable pure virtual class definition.
Definition: DwmBZ2IO.hh:67
int BZRead(BZFILE *bzf)
Reads the prefix from a BZFILE pointer.
This class is a pure virtual class, defining an interface for classes that can read their contents fr...
Definition: DwmGZReadable.hh:57
This class defines an interface for classes that can write their contents to an ostream, file descriptor or FILE pointer.
Definition: DwmWritable.hh:58
This class is a pure virtual class, defining an interface for classes that can write their contents t...
Definition: DwmBZ2Writable.hh:57
Dwm::GZWritable pure virtual class definition.
bool operator>(const Ipv6Prefix &prefix) const
Greater-than operator.
Dwm::Ipv6Address class definition.
This class defines an interface for classes that can read their contents from an istream, file descriptor or FILE pointer.
Definition: DwmReadable.hh:58
uint8_t MaskLength() const
Returns the netmask length.
Ipv6Address Network() const
Returns the network address.
This class encapsulates an IPv6 network prefix.
Definition: DwmIpv6Prefix.hh:63