libDwm-0.9.45
DwmMplsLabel.hh
Go to the documentation of this file.
1//===========================================================================
2// @(#) $DwmPath$
3//===========================================================================
4// Copyright (c) Daniel W. McRobb 2007, 2016, 2020, 2024
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#ifndef _DWMMPLSLABEL_HH_
42#define _DWMMPLSLABEL_HH_
43
44extern "C" {
45 #include <bzlib.h>
46 #include <zlib.h>
47}
48
49#include <cstdint>
50#include <cstdio>
51#include <iostream>
52
53namespace Dwm {
54
55 //--------------------------------------------------------------------------
57 //--------------------------------------------------------------------------
59 {
60 public:
61 //------------------------------------------------------------------------
63 //------------------------------------------------------------------------
65
66 //------------------------------------------------------------------------
68 //------------------------------------------------------------------------
69 MplsLabel(const std::string & s);
70
71 //------------------------------------------------------------------------
73 //------------------------------------------------------------------------
74 uint32_t Label() const;
75
76 //------------------------------------------------------------------------
78 //------------------------------------------------------------------------
79 uint32_t Label(uint32_t label);
80
81 //------------------------------------------------------------------------
83 //------------------------------------------------------------------------
84 uint8_t Exp() const;
85
86 //------------------------------------------------------------------------
88 //------------------------------------------------------------------------
89 uint8_t Exp(uint8_t exp);
90
91 //------------------------------------------------------------------------
93 //------------------------------------------------------------------------
94 bool S() const;
95
96 //------------------------------------------------------------------------
98 //------------------------------------------------------------------------
99 bool S(bool s);
100
101 //------------------------------------------------------------------------
103 //------------------------------------------------------------------------
104 uint8_t Ttl() const;
105
106 //------------------------------------------------------------------------
108 //------------------------------------------------------------------------
109 uint8_t Ttl(uint8_t ttl);
110
111 //------------------------------------------------------------------------
113 //------------------------------------------------------------------------
114 bool operator == (const MplsLabel & label) const;
115
116 //------------------------------------------------------------------------
118 //------------------------------------------------------------------------
119 std::istream & Read(std::istream & is);
120
121 //------------------------------------------------------------------------
123 //------------------------------------------------------------------------
124 std::ostream & Write(std::ostream & os) const;
125
126 //------------------------------------------------------------------------
129 //------------------------------------------------------------------------
130 ssize_t Read(int fd);
131
132 //------------------------------------------------------------------------
135 //------------------------------------------------------------------------
136 ssize_t Write(int fd) const;
137
138 //------------------------------------------------------------------------
141 //------------------------------------------------------------------------
142 size_t Read(FILE *f);
143
144 //------------------------------------------------------------------------
147 //------------------------------------------------------------------------
148 size_t Write(FILE *f) const;
149
150 //------------------------------------------------------------------------
153 //------------------------------------------------------------------------
154 int Read(gzFile gzf);
155
156 //------------------------------------------------------------------------
159 //------------------------------------------------------------------------
160 int Write(gzFile gzf) const;
161
162 //------------------------------------------------------------------------
165 //------------------------------------------------------------------------
166 int BZRead(BZFILE *bzf);
167
168 //------------------------------------------------------------------------
171 //------------------------------------------------------------------------
172 int BZWrite(BZFILE *bzf) const;
173
174 //------------------------------------------------------------------------
177 //------------------------------------------------------------------------
178 uint64_t StreamedLength() const;
179
180 //------------------------------------------------------------------------
182 //------------------------------------------------------------------------
183 friend std::ostream &
184 operator << (std::ostream & os, const MplsLabel & label);
185
186 //------------------------------------------------------------------------
188 //------------------------------------------------------------------------
189 friend std::istream &
190 operator >> (std::istream & is, MplsLabel & label);
191
192 protected:
193 uint32_t _data;
194 };
195
196} // namespace Dwm
197
198#endif // _DWMMPLSLABEL_HH_
199
200//---------------------------- emacs settings -----------------------------
201// Local Variables:
202// mode: C++
203// tab-width: 2
204// indent-tabs-mode: nil
205// c-basic-offset: 2
206// End:
207//-------------------------------------------------------------------------
Encapsulates an MPLS label.
Definition DwmMplsLabel.hh:59
bool S() const
Returns true if the S (bottom-of-stack) bit is set.
ssize_t Write(int fd) const
Writes the MPLS label to a file descriptor.
size_t Write(FILE *f) const
Writes the MPLS label to a FILE.
friend std::ostream & operator<<(std::ostream &os, const MplsLabel &label)
Prints to an ostream in 'label:exp:s:ttl' format.
bool S(bool s)
Sets the S bit.
bool operator==(const MplsLabel &label) const
operator ==
size_t Read(FILE *f)
Reads the MPLS label from a FILE.
int Write(gzFile gzf) const
Writes the MPLS lable to the given gzFile gzf.
std::ostream & Write(std::ostream &os) const
Writes the MPLS label to an ostream. Returns the ostream.
ssize_t Read(int fd)
Reads the MPLS label from a file descriptor.
uint8_t Exp() const
Returns the 3-bit exp portion of the label.
std::istream & Read(std::istream &is)
Reads the MPLS label from an istream. Returns the istream.
int BZRead(BZFILE *bzf)
Reads the MPLS label from the given BZFILE bzf.
MplsLabel()
Constructor. Sets all label bits to 0.
int BZWrite(BZFILE *bzf) const
Writes the MPLS lable to the given BZFILE bzf.
MplsLabel(const std::string &s)
Construct from a string of the form 'label:exp:s:ttl'.
uint32_t Label(uint32_t label)
Sets and returns the 20-bit label portion of the label.
uint8_t Ttl(uint8_t ttl)
Sets and returns the TTL portion of the label.
int Read(gzFile gzf)
Reads the MPLS label from the given gzFile gzf.
friend std::istream & operator>>(std::istream &is, MplsLabel &label)
Reads from an istream in 'label:exp:s:ttl' format.
uint8_t Exp(uint8_t exp)
Sets and returns the 3-bit exp portion of the label.
uint64_t StreamedLength() const
Returns the number of bytes that should be written if we call one of the Write() members.
uint32_t Label() const
Returns the 20-bit label portion of the label.
uint8_t Ttl() const
Returns the TTL portion of the label.