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
38namespace fawkes {
39
40class AvahiThread;
41class NetworkNameResolverThread;
42class HostInfo;
43
45{
47
48public:
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
63private:
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
69private:
70 NetworkNameResolverThread *resolver_thread;
71 HostInfo * host_info_;
72 unsigned int cache_timeout_;
73
76
79};
80
81} // end namespace fawkes
82
83#endif
Avahi main thread.
Definition: avahi_thread.h:55
Host information.
Definition: hostinfo.h:32
Hash map with a lock.
Definition: lock_hashmap.h:57
Worker thread for NetworkNameResolver.
Network name and address resolver.
Definition: resolver.h:45
unsigned int cache_timeout()
Get cache timeout.
Definition: resolver.cpp:125
void set_cache_timeout(unsigned int sec)
Set cache timeout.
Definition: resolver.cpp:116
void flush_cache()
Flush cache.
Definition: resolver.cpp:134
bool resolve_address(struct sockaddr *addr, socklen_t addr_len, std::string &name)
Resolve address.
Definition: resolver.cpp:234
NetworkNameResolver(AvahiThread *avahi_thread=NULL)
Constructor.
Definition: resolver.cpp:85
bool resolve_name(const char *name, struct sockaddr **addr, socklen_t *addrlen)
Resolve name.
Definition: resolver.cpp:169
const char * hostname()
Get long hostname.
Definition: resolver.cpp:345
~NetworkNameResolver()
Destructor.
Definition: resolver.cpp:100
bool resolve_name_blocking(const char *name, struct sockaddr **addr, socklen_t *addrlen)
Resolve name and wait for the result.
Definition: resolver.cpp:203
const char * short_hostname()
Get short hostname.
Definition: resolver.cpp:354
Fawkes library namespace.