reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
DnsUtil.hxx
Go to the documentation of this file.
1#if !defined(RESIP_DNSUTIL_HXX)
2#define RESIP_DNSUTIL_HXX
3
4#include <list>
5#include "rutil/Socket.hxx"
7#include "rutil/Data.hxx"
8
9#ifndef WIN32
10#include <netinet/in.h>
11#else
12#include <Ws2tcpip.h>
13#endif
14
15struct in_addr;
16struct in6_addr;
17namespace resip
18{
19
20class Tuple;
21
29{
30 public:
31 class Exception final : public BaseException
32 {
33 public:
34 Exception(const Data& msg,
35 const Data& file,
36 const int line)
37 : BaseException(msg, file, line) {}
38 protected:
39 const char* name() const noexcept override { return "DnsUtil::Exception"; }
40 };
41
46 static const Data& getLocalHostName();
47
49 static Data getLocalDomainName();
50
58 static Data getLocalIpAddress(const Data& defaultInterface=Data::Empty) ;
59
60 // returns pair of interface name, ip address
64 static std::list<std::pair<Data,Data> > getInterfaces(const Data& matchingInterface=Data::Empty);
65
66 // wrappers for the not so ubiquitous inet_pton, inet_ntop (e.g. WIN32)
67
71 static Data inet_ntop(const struct in_addr& addr);
72
76 static Data inet_ntop(const struct sockaddr& addr);
77
80 static int inet_pton(const Data& printableIp, struct in_addr& dst);
81
82 static bool isIpAddress(const Data& ipAddress);
83 static bool isIpV4Address(const Data& ipAddress);
93 static bool isIpV6Address(const Data& ipAddress);
94
95#ifdef IPPROTO_IPV6
99 static Data inet_ntop(const struct in6_addr& addr);
100
103 static int inet_pton(const Data& printableIp, struct in6_addr& dst);
104#endif
105
106 //pass-throughs when supported, actual implemenation in the WIN32 case
107
119 static const char * inet_ntop(int af, const void* src, char* dst, size_t size);
120
121#ifdef __APPLE__
122 static const Data UInt8ToStr[256];
123#endif // __APPLE__
124
135 static int inet_pton(int af, const char * src, void * dst);
136
137
138 // so string (case) comparison will work
139 // or something
147 static Data canonicalizeIpV6Address(const Data& ipV6Address);
148
150 static std::list<Data> lookupARecords(const Data& host);
151
152 private:
154 static Data lookupLocalHostName();
155};
156
157}
158
159
160#endif
161/* ====================================================================
162 * The Vovida Software License, Version 1.0
163 *
164 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
165 *
166 * Redistribution and use in source and binary forms, with or without
167 * modification, are permitted provided that the following conditions
168 * are met:
169 *
170 * 1. Redistributions of source code must retain the above copyright
171 * notice, this list of conditions and the following disclaimer.
172 *
173 * 2. Redistributions in binary form must reproduce the above copyright
174 * notice, this list of conditions and the following disclaimer in
175 * the documentation and/or other materials provided with the
176 * distribution.
177 *
178 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
179 * and "Vovida Open Communication Application Library (VOCAL)" must
180 * not be used to endorse or promote products derived from this
181 * software without prior written permission. For written
182 * permission, please contact vocal@vovida.org.
183 *
184 * 4. Products derived from this software may not be called "VOCAL", nor
185 * may "VOCAL" appear in their name, without prior written
186 * permission of Vovida Networks, Inc.
187 *
188 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
189 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
190 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
191 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
192 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
193 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
194 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
195 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
196 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
197 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
198 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
199 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
200 * DAMAGE.
201 *
202 * ====================================================================
203 *
204 * This software consists of voluntary contributions made by Vovida
205 * Networks, Inc. and many individuals on behalf of Vovida Networks,
206 * Inc. For more information on Vovida Networks, Inc., please see
207 * <http://www.vovida.org/>.
208 *
209 */
Handles cross-platform sockets compatibility.
The abstract base-class for all exceptions thrown by resip code.
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
static const Data Empty
Constant that represents a zero-length data.
Definition Data.hxx:882
Exception(const Data &msg, const Data &file, const int line)
Definition DnsUtil.hxx:34
const char * name() const noexcept override
Definition DnsUtil.hxx:39
Provides a collection of utility functions for manipulating DNS names and IP addresses and discoverin...
Definition DnsUtil.hxx:29
static bool isIpV6Address(const Data &ipAddress)
Definition DnsUtil.cxx:386
static Data canonicalizeIpV6Address(const Data &ipV6Address)
Converts the printable form of an IPv6 address into consistent format so that string comparisons will...
Definition DnsUtil.cxx:427
static Data getLocalDomainName()
Definition DnsUtil.cxx:187
static std::list< std::pair< Data, Data > > getInterfaces(const Data &matchingInterface=Data::Empty)
Definition DnsUtil.cxx:460
static bool isIpAddress(const Data &ipAddress)
Definition DnsUtil.cxx:453
static const Data & getLocalHostName()
Definition DnsUtil.cxx:118
static int inet_pton(const Data &printableIp, struct in_addr &dst)
Convert from the presentation format of the IPv4 address to struct in_addr.
Definition DnsUtil.cxx:275
static Data inet_ntop(const struct in_addr &addr)
Converts from the network format to presentation format.
Definition DnsUtil.cxx:240
static bool isIpV4Address(const Data &ipAddress)
Definition DnsUtil.cxx:290
static std::list< Data > lookupARecords(const Data &host)
Used to synchronously query A records - only for test code usage.
Definition DnsUtil.cxx:42
static Data getLocalIpAddress(const Data &defaultInterface=Data::Empty)
Gets the IP address of "the" local interface.
Definition DnsUtil.cxx:222
dcm! – add UnusedChecking(_enum) below;
void list()
Definition userAdmin.cxx:66