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 <netinet/in.h>
30 #include <sys/socket.h>
31 #include <utils/misc/string_compare.h>
32 
33 #include <cstddef>
34 #include <ctime>
35 #include <string>
36 #include <utility>
37 
38 namespace fawkes {
39 
40 class AvahiThread;
41 class NetworkNameResolverThread;
42 class HostInfo;
43 
45 {
47 
48 public:
49  NetworkNameResolver(AvahiThread *avahi_thread = NULL);
51 
52  bool resolve_name(const char *name, struct sockaddr **addr, socklen_t *addrlen);
53  bool resolve_name_blocking(const char *name, struct sockaddr **addr, socklen_t *addrlen);
54  bool resolve_address(struct sockaddr *addr, socklen_t addr_len, std::string &name);
55 
56  void flush_cache();
57  void set_cache_timeout(unsigned int sec);
58  unsigned int cache_timeout();
59 
60  const char *hostname();
61  const char *short_hostname();
62 
63 private:
64  void name_resolved(std::string name, struct sockaddr *addr, socklen_t addrlen);
65  void addr_resolved(struct sockaddr *addr, socklen_t addrlen, std::string name, bool namefound);
66  void name_resolution_failed(std::string name);
67  void address_resolution_failed(struct sockaddr *addr, socklen_t addrlen);
68 
69 private:
70  NetworkNameResolverThread *resolver_thread;
71  HostInfo * host_info_;
72  unsigned int cache_timeout_;
73 
76 
79 };
80 
81 } // end namespace fawkes
82 
83 #endif
fawkes::NetworkNameResolver::resolve_name
bool resolve_name(const char *name, struct sockaddr **addr, socklen_t *addrlen)
Resolve name.
Definition: resolver.cpp:169
fawkes::NetworkNameResolver::short_hostname
const char * short_hostname()
Get short hostname.
Definition: resolver.cpp:354
fawkes::NetworkNameResolver
Network name and address resolver.
Definition: resolver.h:45
fawkes::NetworkNameResolver::hostname
const char * hostname()
Get long hostname.
Definition: resolver.cpp:345
fawkes::NetworkNameResolverThread
Worker thread for NetworkNameResolver.
Definition: resolver_thread.h:55
fawkes::NetworkNameResolver::~NetworkNameResolver
~NetworkNameResolver()
Destructor.
Definition: resolver.cpp:100
fawkes::AvahiThread
Avahi main thread.
Definition: avahi_thread.h:55
fawkes
Fawkes library namespace.
fawkes::NetworkNameResolver::flush_cache
void flush_cache()
Flush cache.
Definition: resolver.cpp:134
fawkes::NetworkNameResolver::NetworkNameResolver
NetworkNameResolver(AvahiThread *avahi_thread=NULL)
Constructor.
Definition: resolver.cpp:85
fawkes::HostInfo
Host information.
Definition: hostinfo.h:32
fawkes::LockHashMap
Hash map with a lock.
Definition: lock_hashmap.h:57
fawkes::NetworkNameResolver::set_cache_timeout
void set_cache_timeout(unsigned int sec)
Set cache timeout.
Definition: resolver.cpp:116
fawkes::NetworkNameResolver::cache_timeout
unsigned int cache_timeout()
Get cache timeout.
Definition: resolver.cpp:125
fawkes::NetworkNameResolver::resolve_address
bool resolve_address(struct sockaddr *addr, socklen_t addr_len, std::string &name)
Resolve address.
Definition: resolver.cpp:234
fawkes::NetworkNameResolver::resolve_name_blocking
bool resolve_name_blocking(const char *name, struct sockaddr **addr, socklen_t *addrlen)
Resolve name and wait for the result.
Definition: resolver.cpp:203