Fawkes API  Fawkes Development Version
resolver.h
1 
2 /***************************************************************************
3  * resolver.h - Fawkes network name resolver
4  *
5  * Created: Tue Nov 14 14:25:52 2006
6  * Copyright 2006-2009 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #ifndef __NETCOMM_UTILS_RESOLVER_H_
25 #define __NETCOMM_UTILS_RESOLVER_H_
26 
27 #include <core/utils/lock_hashmap.h>
28 #include <core/utils/lock_map.h>
29 #include <utils/misc/string_compare.h>
30 
31 #include <sys/socket.h>
32 #include <netinet/in.h>
33 #include <cstddef>
34 
35 #include <ctime>
36 #include <string>
37 #include <utility>
38 
39 namespace fawkes {
40 #if 0 /* just to make Emacs auto-indent happy */
41 }
42 #endif
43 
44 class AvahiThread;
45 class NetworkNameResolverThread;
46 class HostInfo;
47 
49 {
50  friend class NetworkNameResolverThread;
51 
52  public:
53  NetworkNameResolver(AvahiThread *avahi_thread = NULL);
55 
56  bool resolve_name(const char *name, struct sockaddr **addr, socklen_t *addrlen);
57  bool resolve_name_blocking(const char *name, struct sockaddr **addr, socklen_t *addrlen);
58  bool resolve_address(struct sockaddr *addr, socklen_t addr_len, std::string &name);
59 
60  void flush_cache();
61  void set_cache_timeout(unsigned int sec);
62  unsigned int cache_timeout();
63 
64  const char * hostname();
65  const char * short_hostname();
66 
67  private:
68  void name_resolved(std::string name, struct sockaddr *addr, socklen_t addrlen);
69  void addr_resolved(struct sockaddr *addr, socklen_t addrlen, std::string name, bool namefound);
70  void name_resolution_failed(std::string name);
71  void address_resolution_failed(struct sockaddr *addr, socklen_t addrlen);
72 
73  private:
74  NetworkNameResolverThread *resolver_thread;
75  HostInfo *__host_info;
76  unsigned int __cache_timeout;
77 
80 
83 };
84 
85 } // end namespace fawkes
86 
87 #endif
bool resolve_name(const char *name, struct sockaddr **addr, socklen_t *addrlen)
Resolve name.
Definition: resolver.cpp:177
const char * hostname()
Get long hostname.
Definition: resolver.cpp:361
Fawkes library namespace.
Worker thread for NetworkNameResolver.
~NetworkNameResolver()
Destructor.
Definition: resolver.cpp:105
void flush_cache()
Flush cache.
Definition: resolver.cpp:141
const char * short_hostname()
Get short hostname.
Definition: resolver.cpp:371
Host information.
Definition: hostinfo.h:31
bool resolve_address(struct sockaddr *addr, socklen_t addr_len, std::string &name)
Resolve address.
Definition: resolver.cpp:244
Avahi main thread.
Definition: avahi_thread.h:54
Network name and address resolver.
Definition: resolver.h:48
Hash map with a lock.
Definition: lock_hashmap.h:55
unsigned int cache_timeout()
Get cache timeout.
Definition: resolver.cpp:131
bool resolve_name_blocking(const char *name, struct sockaddr **addr, socklen_t *addrlen)
Resolve name and wait for the result.
Definition: resolver.cpp:213
void set_cache_timeout(unsigned int sec)
Set cache timeout.
Definition: resolver.cpp:121
NetworkNameResolver(AvahiThread *avahi_thread=NULL)
Constructor.
Definition: resolver.cpp:89