00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef DNS_H__
00015 #define DNS_H__
00016
00017 #include "macros.h"
00018 #include "logsink.h"
00019
00020 #ifdef __MINGW32__
00021 # include <windows.h>
00022 # include <windns.h>
00023 #endif
00024
00025 #ifdef HAVE_ARPA_NAMESER_H
00026 # include <arpa/nameser.h>
00027 #endif
00028
00029 #ifdef __APPLE__
00030 # include <arpa/nameser_compat.h>
00031 #endif
00032
00033 #ifndef NS_MAXDNAME
00034 # define NS_MAXDNAME 1025
00035 #endif
00036
00037 #ifndef NS_PACKETSZ
00038 # define NS_PACKETSZ 512
00039 #endif
00040
00041 #ifdef HAVE_GETADDRINFO
00042 # include <sys/types.h>
00043 # include <sys/socket.h>
00044 # include <netdb.h>
00045 #endif
00046
00047 #include <string>
00048 #include <map>
00049
00050 namespace gloox
00051 {
00052
00061 class GLOOX_API DNS
00062 {
00063 public:
00064
00068 typedef std::map<std::string, int> HostMap;
00069
00079 static HostMap resolve( const std::string& service, const std::string& proto,
00080 const std::string& domain, const LogSink& logInstance );
00081
00090 static HostMap resolve( const std::string& domain, const LogSink& logInstance )
00091 { return resolve( "xmpp-client", "tcp", domain, logInstance ); }
00092
00100 static int connect( const std::string& host, const LogSink& logInstance );
00101
00110 static int connect( const std::string& host, unsigned short port, const LogSink& logInstance );
00111
00116 static int getSocket();
00117
00122 static void closeSocket( int fd );
00123
00124 private:
00131 static int getSocket( int af, int socktype, int proto );
00132
00133 static HostMap defaultHostMap( const std::string& domain, const LogSink& logInstance );
00134 static void cleanup();
00135
00136 struct buffer
00137 {
00138 unsigned char buf[NS_PACKETSZ];
00139 int len;
00140 };
00141 typedef unsigned char name[NS_MAXDNAME];
00142 };
00143
00144 }
00145
00146 #endif // DNS_H__