libDwm-0.6.0
DwmIpv4PacketHeader.hh
Go to the documentation of this file.
1 //===========================================================================
2 // @(#) $DwmPath: dwm/libDwm/tags/libDwm-0.6.0/include/DwmIpv4PacketHeader.hh 8401 $
3 // @(#) $Id: DwmIpv4PacketHeader.hh 8401 2016-04-17 06:44:31Z dwm $
4 //===========================================================================
5 // Copyright (c) Daniel W. McRobb 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 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 _DWMIPV4PACKETHEADER_HH_
43 #define _DWMIPV4PACKETHEADER_HH_
44 
45 extern "C" {
46 #include <sys/types.h>
47 #include <netinet/in_systm.h>
48 #include <netinet/in.h>
49 #include <netinet/ip.h>
50 }
51 
52 #include "DwmBZ2Readable.hh"
53 #include "DwmBZ2Writable.hh"
54 #include "DwmGZReadable.hh"
55 #include "DwmGZWritable.hh"
56 #include "DwmIpv4Address.hh"
57 #include "DwmReadable.hh"
58 #include "DwmWritable.hh"
59 
60 namespace Dwm {
61 
62  //--------------------------------------------------------------------------
64  //--------------------------------------------------------------------------
66  : public Readable, public Writable,
67  public GZReadable, public GZWritable,
68  public BZ2Readable, public BZ2Writable
69  {
70  public:
71  //------------------------------------------------------------------------
73  //------------------------------------------------------------------------
75 
76  //------------------------------------------------------------------------
78  //------------------------------------------------------------------------
79  Ipv4PacketHeader(const Ipv4PacketHeader & ipHeader);
80 
81  //------------------------------------------------------------------------
84  //------------------------------------------------------------------------
85  Ipv4PacketHeader(const struct ip & ip);
86 
87  //------------------------------------------------------------------------
91  //------------------------------------------------------------------------
92  Ipv4PacketHeader(struct ip *ip);
93 
94  //------------------------------------------------------------------------
97  //------------------------------------------------------------------------
99 
100  //------------------------------------------------------------------------
102  //------------------------------------------------------------------------
103  Ipv4PacketHeader & operator = (const Ipv4PacketHeader & ipHeader);
104 
105  //------------------------------------------------------------------------
107  //------------------------------------------------------------------------
108  bool operator == (const Ipv4PacketHeader & ipHeader) const;
109 
110  //------------------------------------------------------------------------
112  //------------------------------------------------------------------------
113  void Set(const struct ip & ip);
114 
115  //------------------------------------------------------------------------
117  //------------------------------------------------------------------------
118  uint8_t HeaderLength() const;
119 
120  //------------------------------------------------------------------------
122  //------------------------------------------------------------------------
123  uint8_t HeaderLength(uint8_t headerLength);
124 
125  //------------------------------------------------------------------------
127  //------------------------------------------------------------------------
128  uint8_t TypeOfService() const;
129 
130  //------------------------------------------------------------------------
132  //------------------------------------------------------------------------
133  uint8_t TypeOfService(uint8_t typeOfService);
134 
135  //------------------------------------------------------------------------
137  //------------------------------------------------------------------------
138  uint16_t TotalLength() const;
139 
140  //------------------------------------------------------------------------
142  //------------------------------------------------------------------------
143  uint16_t TotalLength(uint16_t totalLength);
144 
145  //------------------------------------------------------------------------
147  //------------------------------------------------------------------------
148  uint16_t Id() const;
149 
150  //------------------------------------------------------------------------
152  //------------------------------------------------------------------------
153  uint16_t Id(uint16_t id);
154 
155  //------------------------------------------------------------------------
157  //------------------------------------------------------------------------
158  uint16_t FragmentOffset() const;
159 
160  //------------------------------------------------------------------------
162  //------------------------------------------------------------------------
163  uint16_t FragmentOffset(uint16_t fragmentOffset);
164 
165  //------------------------------------------------------------------------
167  //------------------------------------------------------------------------
168  uint8_t TimeToLive() const;
169 
170  //------------------------------------------------------------------------
172  //------------------------------------------------------------------------
173  uint8_t TimeToLive(uint8_t timeToLive);
174 
175  //------------------------------------------------------------------------
177  //------------------------------------------------------------------------
178  uint8_t Protocol() const;
179 
180  //------------------------------------------------------------------------
182  //------------------------------------------------------------------------
183  uint8_t Protocol(uint8_t protocol);
184 
185  //------------------------------------------------------------------------
187  //------------------------------------------------------------------------
188  uint16_t Checksum() const;
189 
190  //------------------------------------------------------------------------
192  //------------------------------------------------------------------------
193  Ipv4Address SourceAddress() const;
194 
195  //------------------------------------------------------------------------
197  //------------------------------------------------------------------------
198  Ipv4Address SourceAddress(const Ipv4Address & sourceAddress);
199 
200  //------------------------------------------------------------------------
202  //------------------------------------------------------------------------
204 
205  //------------------------------------------------------------------------
207  //------------------------------------------------------------------------
208  Ipv4Address DestinationAddress(const Ipv4Address & destinationAddress);
209 
210  //------------------------------------------------------------------------
212  //------------------------------------------------------------------------
213  void SetChecksum();
214 
215  //------------------------------------------------------------------------
217  //------------------------------------------------------------------------
218  std::istream & Read(std::istream & is);
219 
220  //------------------------------------------------------------------------
222  //------------------------------------------------------------------------
223  std::ostream & Write(std::ostream & os) const;
224 
225  //------------------------------------------------------------------------
228  //------------------------------------------------------------------------
229  ssize_t Read(int fd);
230 
231  //------------------------------------------------------------------------
234  //------------------------------------------------------------------------
235  ssize_t Write(int fd) const;
236 
237  //------------------------------------------------------------------------
239  //------------------------------------------------------------------------
240  size_t Read(FILE *f);
241 
242  //------------------------------------------------------------------------
244  //------------------------------------------------------------------------
245  size_t Write(FILE *f) const;
246 
247  //------------------------------------------------------------------------
250  //------------------------------------------------------------------------
251  uint32_t StreamedLength() const;
252 
253  //------------------------------------------------------------------------
256  //------------------------------------------------------------------------
257  int Read(gzFile gzf);
258 
259  //------------------------------------------------------------------------
262  //------------------------------------------------------------------------
263  int Write(gzFile gzf) const;
264 
265  //------------------------------------------------------------------------
268  //------------------------------------------------------------------------
269  int BZRead(BZFILE *bzf);
270 
271  //------------------------------------------------------------------------
274  //------------------------------------------------------------------------
275  int BZWrite(BZFILE *bzf) const;
276 
277  //------------------------------------------------------------------------
280  //------------------------------------------------------------------------
281  std::ostream & PrintXML(std::ostream & os,
282  const std::string & pre = "") const;
283 
284  uint8_t *End() const;
285 
286  private:
287  struct ip *_ip;
288  bool _ownData;
289  };
290 
291 } // namespace Dwm
292 
293 #endif // _DWMIPV4PACKETHEADER_HH_
294 
295 //---------------------------- emacs settings -----------------------------
296 // Local Variables:
297 // mode: C++/la
298 // tab-width: 2
299 // indent-tabs-mode: nil
300 // c-basic-offset: 2
301 // End:
302 //-------------------------------------------------------------------------
std::ostream & Write(std::ostream &os) const
Writes the header to an ostream. Returns the ostream.
This class is a pure virtual class, defining an interface for classes that can write their contents t...
Definition: DwmGZWritable.hh:57
uint16_t Id() const
Returns the IP ID field in host byte order.
int BZRead(BZFILE *bzf)
Reads the header from a BZFILE.
Dwm::Writable pure virtual class definition.
Dwm::BZ2Readable pure virtual class definition.
uint16_t TotalLength() const
Returns the total length field in host byte order.
Dwm::GZReadable pure virtual class definition.
This class encapsulates an IPv4 address.
Definition: DwmIpv4Address.hh:62
Dwm::Readable pure virtual class definition.
Ipv4Address DestinationAddress() const
Returns the destination IP address.
std::istream & Read(std::istream &is)
Reads the header from an istream. Returns the istream.
Ipv4Address SourceAddress() const
Returns the source IP address.
uint32_t StreamedLength() const
Returns the number of bytes that should be written if we called one of the Write() members...
uint16_t Checksum() const
Returns the checksum field in host byte order.
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 Ipv4PacketHeader &ipHeader) const
operator ==
~Ipv4PacketHeader()
Destructor.
Dwm::BZ2Writable pure virtual class definition.
uint8_t TypeOfService() const
Returns the type-of-service.
Definition: DwmBZ2IO.hh:67
Ipv4PacketHeader()
Constructor. The new object will own the underlying memory.
This class is a pure virtual class, defining an interface for classes that can read their contents fr...
Definition: DwmGZReadable.hh:57
uint8_t Protocol() const
Returns the protocol field.
void Set(const struct ip &ip)
Copy the contents of ip into the object.
Dwm::Ipv4Address class definition.
Ipv4PacketHeader & operator=(const Ipv4PacketHeader &ipHeader)
operator =
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.
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 HeaderLength() const
Returns the IP header length.
uint8_t TimeToLive() const
Returns the time-to-live field.
int BZWrite(BZFILE *bzf) const
Writes the header to a BZFILE.
std::ostream & PrintXML(std::ostream &os, const std::string &pre="") const
Prints the header is pseudo-XML.
void SetChecksum()
Computes and stores the IP header checksum.
Encapsulates an IPv4 packet header.
Definition: DwmIpv4PacketHeader.hh:65
uint16_t FragmentOffset() const
Returns the fragment offset field in host byte order.