reSIProcate/rutil  9694
DnsUtil.hxx
Go to the documentation of this file.
00001 #if !defined(RESIP_DNSUTIL_HXX)
00002 #define RESIP_DNSUTIL_HXX
00003 
00004 #include <list>
00005 #include "rutil/Socket.hxx"
00006 #include "rutil/BaseException.hxx"
00007 #include "rutil/Data.hxx"
00008 
00009 #ifndef WIN32
00010 #include <netinet/in.h>
00011 #else
00012 #include <Ws2tcpip.h>
00013 #endif
00014 
00015 struct in_addr;
00016 struct in6_addr;
00017 namespace resip
00018 {
00019 
00020 class Tuple;
00021 
00028 class DnsUtil
00029 {
00030    public:
00031       class Exception : public BaseException
00032       {
00033          public:
00034             Exception(const Data& msg,
00035                       const Data& file,
00036                       const int line)
00037                : BaseException(msg, file, line) {}            
00038          protected:
00039             virtual const char* name() const { return "DnsUtil::Exception"; }
00040       };
00041 
00046       static Data getLocalHostName();
00047 
00049       static Data getLocalDomainName();
00050 
00058       static Data getLocalIpAddress(const Data& defaultInterface=Data::Empty) ;
00059 
00060       // returns pair of interface name, ip address
00064       static std::list<std::pair<Data,Data> > getInterfaces(const Data& matchingInterface=Data::Empty);
00065 
00066       // wrappers for the not so ubiquitous inet_pton, inet_ntop (e.g. WIN32)
00067 
00071       static Data inet_ntop(const struct in_addr& addr);
00072 
00076       static Data inet_ntop(const struct sockaddr& addr);
00077 
00080       static int inet_pton(const Data& printableIp, struct in_addr& dst);
00081       
00082       static bool isIpAddress(const Data& ipAddress);
00083       static bool isIpV4Address(const Data& ipAddress);
00093       static bool isIpV6Address(const Data& ipAddress);
00094 
00095 #ifdef IPPROTO_IPV6
00096 
00097 
00098 
00099       static Data inet_ntop(const struct in6_addr& addr);
00100 
00103       static int inet_pton(const Data& printableIp, struct in6_addr& dst);
00104 #endif
00105 
00106       //pass-throughs when supported, actual implemenation in the WIN32 case
00107 
00119       static const char * inet_ntop(int af, const void* src, char* dst, size_t size);      
00120 
00121 #ifdef __APPLE__
00122       static const Data UInt8ToStr[256];
00123 #endif // __APPLE__
00124 
00135       static int inet_pton(int af, const char * src, void * dst);
00136       
00137 
00138       // so string (case) comparison will work
00139       // or something
00147       static Data canonicalizeIpV6Address(const Data& ipV6Address);
00148 
00150       static std::list<Data> lookupARecords(const Data& host);
00151 
00152 };
00153 
00154 }
00155 
00156 
00157 #endif
00158 /* ====================================================================
00159  * The Vovida Software License, Version 1.0 
00160  * 
00161  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00162  * 
00163  * Redistribution and use in source and binary forms, with or without
00164  * modification, are permitted provided that the following conditions
00165  * are met:
00166  * 
00167  * 1. Redistributions of source code must retain the above copyright
00168  *    notice, this list of conditions and the following disclaimer.
00169  * 
00170  * 2. Redistributions in binary form must reproduce the above copyright
00171  *    notice, this list of conditions and the following disclaimer in
00172  *    the documentation and/or other materials provided with the
00173  *    distribution.
00174  * 
00175  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00176  *    and "Vovida Open Communication Application Library (VOCAL)" must
00177  *    not be used to endorse or promote products derived from this
00178  *    software without prior written permission. For written
00179  *    permission, please contact vocal@vovida.org.
00180  *
00181  * 4. Products derived from this software may not be called "VOCAL", nor
00182  *    may "VOCAL" appear in their name, without prior written
00183  *    permission of Vovida Networks, Inc.
00184  * 
00185  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00186  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00187  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00188  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00189  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00190  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00191  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00192  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00193  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00194  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00195  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00196  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00197  * DAMAGE.
00198  * 
00199  * ====================================================================
00200  * 
00201  * This software consists of voluntary contributions made by Vovida
00202  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00203  * Inc.  For more information on Vovida Networks, Inc., please see
00204  * <http://www.vovida.org/>.
00205  *
00206  */