DwmDns-0.1.0
DwmDnsRRDataLOC.hh
Go to the documentation of this file.
1 //===========================================================================
2 // @(#) $DwmPath: dwm/DwmDns/tags/DwmDns-0.1.0/classes/include/DwmDnsRRDataLOC.hh 10138 $
3 // @(#) $Id: DwmDnsRRDataLOC.hh 10138 2018-01-28 07:39:44Z dwm $
4 //===========================================================================
5 // Copyright (c) Daniel W. McRobb 2000, 2016, 2018
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 _DWMDNSRRDATALOC_HH_
43 #define _DWMDNSRRDATALOC_HH_
44 
45 #include <cstdint>
46 #include <iostream>
47 
48 #include "DwmDnsRRData.hh"
49 
50 namespace Dwm {
51 
52  namespace Dns {
53 
54  //------------------------------------------------------------------------
57  //------------------------------------------------------------------------
58  class RRDataLOC
59  : public RRData
60  {
61  public:
62  static const uint16_t k_rrtype = 29;
63 
64  //----------------------------------------------------------------------
66  //----------------------------------------------------------------------
67  RRDataLOC();
68 
69  //----------------------------------------------------------------------
71  //----------------------------------------------------------------------
72  RRDataLOC(uint8_t version, uint8_t size,
73  uint8_t horizontalPrecision, uint8_t verticalPrecision,
74  uint32_t iatitude, uint32_t longitude, uint32_t altitude);
75 
76  bool operator == (const RRDataLOC & loc) const;
77 
78  //----------------------------------------------------------------------
80 
86  //----------------------------------------------------------------------
87  uint8_t Version() const;
88 
89  //----------------------------------------------------------------------
91 
97  //----------------------------------------------------------------------
98  uint8_t Version(uint8_t version);
99 
100  //----------------------------------------------------------------------
102 
119  //----------------------------------------------------------------------
120  uint8_t Size() const;
121 
122  //----------------------------------------------------------------------
124 
141  //----------------------------------------------------------------------
142  uint8_t Size(uint8_t size);
143 
144  //----------------------------------------------------------------------
146 
154  //----------------------------------------------------------------------
155  uint8_t HorizontalPrecision() const;
156 
157  //----------------------------------------------------------------------
159 
167  //----------------------------------------------------------------------
168  uint8_t HorizontalPrecision(uint8_t horizontalPrecision);
169 
170  //----------------------------------------------------------------------
172 
181  //----------------------------------------------------------------------
182  uint8_t VerticalPrecision() const;
183 
184  //----------------------------------------------------------------------
186 
196  //----------------------------------------------------------------------
197  uint8_t VerticalPrecision(uint8_t verticalPrecision);
198 
199  //----------------------------------------------------------------------
201 
208  //----------------------------------------------------------------------
209  uint32_t Latitude() const;
210 
211  //----------------------------------------------------------------------
213 
220  //----------------------------------------------------------------------
221  uint32_t Latitude(uint32_t latitude);
222 
223  //----------------------------------------------------------------------
225 
233  //----------------------------------------------------------------------
234  uint32_t Longitude() const;
235 
236  //----------------------------------------------------------------------
238 
246  //----------------------------------------------------------------------
247  uint32_t Longitude(uint32_t longitude);
248 
249  //----------------------------------------------------------------------
251 
268  //----------------------------------------------------------------------
269  uint32_t Altitude() const;
270 
271  //----------------------------------------------------------------------
273 
290  //----------------------------------------------------------------------
291  uint32_t Altitude(uint32_t altitude);
292 
293  //----------------------------------------------------------------------
299  //----------------------------------------------------------------------
300  uint8_t *Encode(uint8_t *pkt, uint8_t *ptr, uint16_t pktlen,
301  LabelPositions & lps) const;
302 
303  //----------------------------------------------------------------------
309  //----------------------------------------------------------------------
310  const uint8_t *Decode(const uint8_t *pkt, const uint8_t *ptr,
311  uint16_t pktlen, uint16_t rdlen);
312 
313  //----------------------------------------------------------------------
316  //----------------------------------------------------------------------
317  friend std::ostream & operator << (std::ostream & os,
318  const RRDataLOC & loc);
319 
320  private:
321  typedef struct __attribute__((packed)) {
322  uint8_t version;
323  uint8_t size;
324  uint8_t horizontalPrecision;
325  uint8_t verticalPrecision;
326  uint32_t latitude;
327  uint32_t longitude;
328  uint32_t altitude;
329  } data_t;
330 
331  data_t _data;
332 
333  static data_t ToNetworkByteOrder(const data_t *data);
334  static data_t ToHostByteOrder(const data_t *data);
335  };
336 
337  } // namespace Dns
338 
339 } // namespace Dwm
340 
341 #endif // _DWMDNSRRDATALOC_HH_
uint32_t Longitude() const
Returns the longitude field.
uint32_t Latitude() const
Returns the latitude field.
uint8_t Size() const
Returns the size field.
friend std::ostream & operator<<(std::ostream &os, const RRDataLOC &loc)
Print the LOC resource record data to an ostream in human readable form.
uint8_t HorizontalPrecision() const
Returns the horizontal precision field.
uint8_t VerticalPrecision() const
Returns the vertical precision field.
uint32_t Altitude() const
Returns the altitude field.
Definition: DwmDnsEtcHosts.hh:60
Encapsulates LOC resource record data.
Definition: DwmDnsRRDataLOC.hh:58
uint8_t * Encode(uint8_t *pkt, uint8_t *ptr, uint16_t pktlen, LabelPositions &lps) const
Encodes the LOC resource record data into buffer @ pkt of length pktlen, starting at ptr...
RRDataLOC()
Constructor.
Dwm::Dns::RRData class definition.
const uint8_t * Decode(const uint8_t *pkt, const uint8_t *ptr, uint16_t pktlen, uint16_t rdlen)
Decodes the LOC resource record data from buffer pkt of length pktlen, starting at ptr...
A helper class used when performing label sequence compression.
Definition: DwmDnsLabelPositions.hh:57
Abstract (pure virtual) base for resource record data classes.
Definition: DwmDnsRRData.hh:71
uint8_t Version() const
Returns the version field.