DwmDns-0.1.0
DwmDnsUtils.hh
Go to the documentation of this file.
1 //===========================================================================
2 // @(#) $DwmPath: dwm/DwmDns/tags/DwmDns-0.1.0/classes/include/DwmDnsUtils.hh 10129 $
3 // @(#) $Id: DwmDnsUtils.hh 10129 2018-01-27 04:20:26Z dwm $
4 //===========================================================================
5 // Copyright (c) Daniel W. McRobb 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 _DWMDNSUTILS_HH_
43 #define _DWMDNSUTILS_HH_
44 
45 extern "C" {
46  #include <sys/types.h>
47  #include <sys/socket.h>
48  #include <netinet/in.h>
49  #include <arpa/inet.h>
50 }
51 
52 #include <cstdint>
53 #include <string>
54 
55 //----------------------------------------------------------------------------
57 //----------------------------------------------------------------------------
58 bool operator == (const in6_addr & addr1, const in6_addr & addr2);
59 
60 //----------------------------------------------------------------------------
62 //----------------------------------------------------------------------------
63 bool operator < (const in6_addr & addr1, const in6_addr & addr2);
64 
65 //----------------------------------------------------------------------------
67 //----------------------------------------------------------------------------
68 bool operator == (const in_addr & addr1, const in_addr & addr2);
69 
70 //----------------------------------------------------------------------------
72 //----------------------------------------------------------------------------
73 bool operator < (const in_addr & addr1, const in_addr & addr2);
74 
75 
76 namespace Dwm {
77 
78  namespace Dns {
79 
80  //------------------------------------------------------------------------
86  //------------------------------------------------------------------------
87  uint8_t *EncodeCharacterString(const std::string & s, uint8_t *pkt,
88  uint8_t *ptr, uint16_t pktlen);
89 
90  //------------------------------------------------------------------------
96  //------------------------------------------------------------------------
97  const uint8_t *DecodeCharacterString(std::string & s, const uint8_t *pkt,
98  const uint8_t *ptr, uint16_t pktlen);
99 
100  //------------------------------------------------------------------------
104  //------------------------------------------------------------------------
105  bool ToArpa(const std::string & ipAddr, std::string & arpa);
106 
107  //------------------------------------------------------------------------
110  //------------------------------------------------------------------------
111  void ToArpa(const in_addr & inAddr, std::string & arpa);
112 
113  //------------------------------------------------------------------------
116  //------------------------------------------------------------------------
117  void ToArpa(const in6_addr & in6Addr, std::string & arpa);
118 
119  //------------------------------------------------------------------------
122  //------------------------------------------------------------------------
123  bool FromArpa(const std::string & arpa, std::string & ipAddr);
124 
125  } // namespace Dns
126 
127 } // namespace Dwm
128 
129 #endif // _DWMDNSUTILS_HH_
bool ToArpa(const std::string &ipAddr, std::string &arpa)
Converts the given IP address ipAddr into arpa in ARPA domain form.
bool FromArpa(const std::string &arpa, std::string &ipAddr)
Converts the given ARPA domain arpa into ipAddr.
Definition: DwmDnsEtcHosts.hh:60
uint8_t * EncodeCharacterString(const std::string &s, uint8_t *pkt, uint8_t *ptr, uint16_t pktlen)
Encodes the given string into buffer pkt of length pktlen as a DNS &#39;character string&#39; starting at ptr...
const uint8_t * DecodeCharacterString(std::string &s, const uint8_t *pkt, const uint8_t *ptr, uint16_t pktlen)
Decodes a DNS &#39;character string&#39; from buffer pkt of length pktlen into s, starting at ptr...