libDwm-0.6.0
DwmIpv4IcmpMessage.hh
Go to the documentation of this file.
1 //===========================================================================
2 // @(#) $DwmPath: dwm/libDwm/tags/libDwm-0.6.0/include/DwmIpv4IcmpMessage.hh 8401 $
3 // @(#) $Id: DwmIpv4IcmpMessage.hh 8401 2016-04-17 06:44:31Z dwm $
4 //===========================================================================
5 // Copyright (c) Daniel W. McRobb 2007, 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 //---------------------------------------------------------------------------
40 //---------------------------------------------------------------------------
41 
42 #ifndef _DWMIPV4ICMPMESSAGE_HH_
43 #define _DWMIPV4ICMPMESSAGE_HH_
44 
45 extern "C" {
46 #include <inttypes.h>
47 }
48 
49 #include <utility>
50 
51 #include "DwmBZ2Writable.hh"
52 #include "DwmGZWritable.hh"
53 #include "DwmWritable.hh"
54 
55 namespace Dwm {
56 
57  //--------------------------------------------------------------------------
59  //--------------------------------------------------------------------------
61  : public Writable, public GZWritable, public BZ2Writable
62  {
63  public:
64  //------------------------------------------------------------------------
66  //------------------------------------------------------------------------
68 
69  //------------------------------------------------------------------------
71  //------------------------------------------------------------------------
73 
74  //------------------------------------------------------------------------
76  //------------------------------------------------------------------------
77  uint8_t Type() const;
78 
79  //------------------------------------------------------------------------
81  //------------------------------------------------------------------------
82  uint8_t Type(uint8_t type);
83 
84  //------------------------------------------------------------------------
86  //------------------------------------------------------------------------
87  uint8_t Code() const;
88 
89  //------------------------------------------------------------------------
91  //------------------------------------------------------------------------
92  uint8_t Code(uint8_t code);
93 
94  //------------------------------------------------------------------------
96  //------------------------------------------------------------------------
97  uint16_t Checksum();
98 
99  //------------------------------------------------------------------------
101  //------------------------------------------------------------------------
102  void SetChecksum();
103 
104  //------------------------------------------------------------------------
107  //------------------------------------------------------------------------
108  std::istream & Read(std::istream & is, uint16_t len);
109 
110  //------------------------------------------------------------------------
112  //------------------------------------------------------------------------
113  std::ostream & Write(std::ostream & os) const;
114 
115  //------------------------------------------------------------------------
118  //------------------------------------------------------------------------
119  ssize_t Read(int fd, uint16_t len);
120 
121  //------------------------------------------------------------------------
124  //------------------------------------------------------------------------
125  ssize_t Write(int fd) const;
126 
127  //------------------------------------------------------------------------
130  //------------------------------------------------------------------------
131  size_t Read(FILE *f, uint16_t len);
132 
133  //------------------------------------------------------------------------
135  //------------------------------------------------------------------------
136  size_t Write(FILE *f) const;
137 
138  //------------------------------------------------------------------------
141  //------------------------------------------------------------------------
142  int Read(gzFile gzf, uint16_t len);
143 
144  //------------------------------------------------------------------------
147  //------------------------------------------------------------------------
148  int Write(gzFile gzf) const;
149 
150  //------------------------------------------------------------------------
153  //------------------------------------------------------------------------
154  int BZRead(BZFILE *bzf, uint16_t len);
155 
156  //------------------------------------------------------------------------
159  //------------------------------------------------------------------------
160  int BZWrite(BZFILE *bzf) const;
161 
162  //------------------------------------------------------------------------
165  //------------------------------------------------------------------------
166  uint32_t StreamedLength() const;
167 
168  //------------------------------------------------------------------------
170  //------------------------------------------------------------------------
171  bool operator == (const Ipv4IcmpMessage & msg) const;
172 
173  protected:
174  std::pair<uint16_t, uint8_t *> _data;
175  bool _ownData;
176 
177  void Free();
178  void Allocate(uint16_t len);
179  void Reallocate(uint16_t len);
180  };
181 
182 } // namespace Dwm
183 
184 #endif // _DWMIPV4ICMPMESSAGE_HH_
185 
186 //---------------------------- emacs settings -----------------------------
187 // Local Variables:
188 // mode: C++/la
189 // tab-width: 2
190 // indent-tabs-mode: nil
191 // c-basic-offset: 2
192 // End:
193 //-------------------------------------------------------------------------
This class is a pure virtual class, defining an interface for classes that can write their contents t...
Definition: DwmGZWritable.hh:57
Base class for ICMP messages.
Definition: DwmIpv4IcmpMessage.hh:60
Dwm::Writable pure virtual class definition.
std::istream & Read(std::istream &is, uint16_t len)
Reads the message of length len from an istream.
uint16_t Checksum()
Returns the ICMP checksum.
int BZRead(BZFILE *bzf, uint16_t len)
Reads the message of length len from a BZFILE.
std::ostream & Write(std::ostream &os) const
Writes the message to an ostream. Returns the ostream.
uint32_t StreamedLength() const
Returns the number of bytes that would be written if we called one of the Write() members...
Dwm::BZ2Writable pure virtual class definition.
bool operator==(const Ipv4IcmpMessage &msg) const
operator ==
Definition: DwmBZ2IO.hh:67
int BZWrite(BZFILE *bzf) const
Writes the message to a BZFILE.
~Ipv4IcmpMessage()
Destructor.
Ipv4IcmpMessage()
Default constructor.
void SetChecksum()
Computes and sets the checksum.
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.
uint8_t Type() const
Returns the ICMP message type.
uint8_t Code() const
Returns the ICMP message code.