dns.h
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, int port, const LogSink& logInstance );
00111
00117 static int getSocket( const LogSink& logInstance );
00118
00124 static void closeSocket( int fd, const LogSink& logInstance );
00125
00126 private:
00127 #ifdef HAVE_GETADDRINFO
00128
00137 static void resolve( struct addrinfo** res, const std::string& service, const std::string& proto,
00138 const std::string& domain, const LogSink& logInstance );
00139
00147 static void resolve( struct addrinfo** res, const std::string& domain, const LogSink& logInstance )
00148 { resolve( res, "xmpp-client", "tcp", domain, logInstance ); }
00149
00156 static int connect( struct addrinfo* res, const LogSink& logInstance );
00157 #endif
00158
00165 static int getSocket( int af, int socktype, int proto, const LogSink& logInstance );
00166
00167 static HostMap defaultHostMap( const std::string& domain, const LogSink& logInstance );
00168 static void cleanup( const LogSink& logInstance );
00169
00170 struct buffer
00171 {
00172 unsigned char buf[NS_PACKETSZ];
00173 int len;
00174 };
00175 };
00176
00177 }
00178
00179 #endif // DNS_H__