gloox  0.9.9.12
dns.h
1 /*
2  Copyright (c) 2005-2008 by Jakob Schroeter <js@camaya.net>
3  This file is part of the gloox library. http://camaya.net/gloox
4 
5  This software is distributed under a license. The full license
6  agreement can be found in the file LICENSE in this distribution.
7  This software may not be copied, modified, sold or distributed
8  other than expressed in the named license agreement.
9 
10  This software is distributed without any warranty.
11 */
12 
13 
14 #ifndef DNS_H__
15 #define DNS_H__
16 
17 #include "macros.h"
18 #include "logsink.h"
19 
20 #ifdef __MINGW32__
21 # include <windows.h>
22 # include <windns.h>
23 #endif
24 
25 #ifdef HAVE_ARPA_NAMESER_H
26 # include <arpa/nameser.h>
27 #endif
28 
29 #ifdef __APPLE__
30 # include <arpa/nameser_compat.h>
31 #endif
32 
33 #ifndef NS_MAXDNAME
34 # define NS_MAXDNAME 1025
35 #endif
36 
37 #ifndef NS_PACKETSZ
38 # define NS_PACKETSZ 512
39 #endif
40 
41 #include <string>
42 #include <map>
43 
44 namespace gloox
45 {
46 
55  class GLOOX_API DNS
56  {
57  public:
58 
62  typedef std::map<std::string, int> HostMap;
63 
73  static HostMap resolve( const std::string& service, const std::string& proto,
74  const std::string& domain, const LogSink& logInstance );
75 
84  static HostMap resolve( const std::string& domain, const LogSink& logInstance )
85  { return resolve( "xmpp-client", "tcp", domain, logInstance ); }
86 
94  static int connect( const std::string& domain, const LogSink& logInstance );
95 
104  static int connect( const std::string& domain, unsigned short port, const LogSink& logInstance );
105 
110  static int getSocket();
111 
116  static void closeSocket( int fd );
117 
118  private:
119  static HostMap defaultHostMap( const std::string& domain, const LogSink& logInstance );
120  static void cleanup();
121 
122  typedef struct buffer
123  {
124  unsigned char buf[NS_PACKETSZ];
125  int len;
126  };
127  typedef unsigned char name[NS_MAXDNAME];
128  };
129 
130 }
131 
132 #endif // DNS_H__