libDwm-0.9.45
DwmMacAddress.hh
Go to the documentation of this file.
1//===========================================================================
2// @(#) $DwmPath$
3//===========================================================================
4// Copyright (c) Daniel W. McRobb 2007, 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
42#ifndef _DWMMACADDRESS_HH_
43#define _DWMMACADDRESS_HH_
44
45extern "C" {
46 #include <bzlib.h>
47 #include <zlib.h>
48}
49
50#include <cstdint>
51#include <cstdio>
52#include <iostream>
53#include <string>
54
55namespace Dwm {
56
57 //--------------------------------------------------------------------------
59 //--------------------------------------------------------------------------
61 {
62 public:
63 //------------------------------------------------------------------------
65 //------------------------------------------------------------------------
67
68 //------------------------------------------------------------------------
70 //------------------------------------------------------------------------
71 MacAddress(const std::string & s);
72
73 //------------------------------------------------------------------------
75 //------------------------------------------------------------------------
76 MacAddress(const MacAddress & addr);
77
78 //------------------------------------------------------------------------
80 //------------------------------------------------------------------------
82
83 //------------------------------------------------------------------------
85 //------------------------------------------------------------------------
86 operator std::string () const;
87
88 //------------------------------------------------------------------------
90 //------------------------------------------------------------------------
91 bool operator == (const MacAddress & addr) const;
92
93 //------------------------------------------------------------------------
95 //------------------------------------------------------------------------
96 bool operator < (const MacAddress & addr) const;
97
98 //------------------------------------------------------------------------
100 //------------------------------------------------------------------------
101 std::istream & Read(std::istream & is);
102
103 //------------------------------------------------------------------------
105 //------------------------------------------------------------------------
106 std::ostream & Write(std::ostream & os) const;
107
108 //------------------------------------------------------------------------
111 //------------------------------------------------------------------------
112 ssize_t Read(int fd);
113
114 //------------------------------------------------------------------------
117 //------------------------------------------------------------------------
118 ssize_t Write(int fd) const;
119
120 //------------------------------------------------------------------------
123 //------------------------------------------------------------------------
124 size_t Read(FILE *f);
125
126 //------------------------------------------------------------------------
129 //------------------------------------------------------------------------
130 size_t Write(FILE *f) const;
131
132 //------------------------------------------------------------------------
135 //------------------------------------------------------------------------
136 int Read(gzFile gzf);
137
138 //------------------------------------------------------------------------
141 //------------------------------------------------------------------------
142 int Write(gzFile gzf) const;
143
144 //------------------------------------------------------------------------
147 //------------------------------------------------------------------------
148 int BZRead(BZFILE *bzf);
149
150 //------------------------------------------------------------------------
153 //------------------------------------------------------------------------
154 int BZWrite(BZFILE *bzf) const;
155
156 //------------------------------------------------------------------------
159 //------------------------------------------------------------------------
160 uint64_t StreamedLength() const;
161
162 //------------------------------------------------------------------------
164 //------------------------------------------------------------------------
165 friend std::ostream &
166 operator << (std::ostream & os, const MacAddress & addr);
167
168 //------------------------------------------------------------------------
170 //------------------------------------------------------------------------
171 friend std::istream &
172 operator >> (std::istream & is, MacAddress & addr);
173
174 protected:
175 uint8_t _addr[6];
176 };
177
178} // namespace Dwm
179
180#endif // _DWMMACADDRESS_HH_
181
182//---------------------------- emacs settings -----------------------------
183// Local Variables:
184// mode: C++
185// tab-width: 2
186// indent-tabs-mode: nil
187// c-basic-offset: 2
188// End:
189//-------------------------------------------------------------------------
Encapsulates a 6-byte MAC address.
Definition DwmMacAddress.hh:61
ssize_t Write(int fd) const
Writes the MAC address to a file descriptor.
MacAddress(const std::string &s)
Construct from a string of the form xx:xx:xx:xx:xx:xx.
size_t Read(FILE *f)
Reads the MAC address from a FILE.
MacAddress()
Constructor. Sets the address to 00:00:00:00:00:00.
int Read(gzFile gzf)
Reads the MAC address from a gzFile.
bool operator==(const MacAddress &addr) const
operator ==
int BZWrite(BZFILE *bzf) const
Writes the MAC address to a BZFILE.
std::ostream & Write(std::ostream &os) const
Writes the MAC address to an ostream. Returns the ostream.
MacAddress(const MacAddress &addr)
Copy constructor.
int Write(gzFile gzf) const
Writes the MAC address to a gzFile.
bool operator<(const MacAddress &addr) const
operator <
std::istream & Read(std::istream &is)
Reads the MAC address from an istream. Returns the istream.
MacAddress & operator=(const MacAddress &addr)
operator =
uint64_t StreamedLength() const
Returns the number of bytes that should be written if we call one of the Write() members.
int BZRead(BZFILE *bzf)
Reads the MAC address from a BZFILE.
friend std::istream & operator>>(std::istream &is, MacAddress &addr)
Reads from an istream in 'xx:xx:xx:xx:xx:xx' format.
friend std::ostream & operator<<(std::ostream &os, const MacAddress &addr)
Prints to an ostream in 'xx:xx:xx:xx:xx:xx' format.
ssize_t Read(int fd)
Reads the MAC address from a file descriptor.
size_t Write(FILE *f) const
Writes the MAC address to a FILE.