1 /* IODNSLookup.h - IOMultiplexer v2
2 * Copyright (C) 2014 Philipp Kreil (pk910)
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef _IODNSLookup_h
18 #define _IODNSLookup_h
20 #include "IODNSAddress.struct.h"
22 #ifndef _IOHandler_internals
23 #include "IOHandler.h"
27 extern struct IODNSEngine dnsengine_cares;
28 extern struct IODNSEngine dnsengine_default;
31 extern struct _IODNSQuery *iodnsquery_first;
32 extern struct _IODNSQuery *iodnsquery_last;
35 #ifdef IODNS_USE_THREADS
36 #ifndef HAVE_PTHREAD_H
37 #undef IODNS_USE_THREADS
40 #ifdef IODNS_USE_THREADS
42 #ifdef PTHREAD_MUTEX_RECURSIVE_NP
43 #define PTHREAD_MUTEX_RECURSIVE_VAL PTHREAD_MUTEX_RECURSIVE_NP
45 #define PTHREAD_MUTEX_RECURSIVE_VAL PTHREAD_MUTEX_RECURSIVE
47 #define IOTHREAD_MUTEX_INIT(var) { \
48 pthread_mutexattr_t mutex_attr; \
49 pthread_mutexattr_init(&mutex_attr);\
50 pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE_VAL);\
51 pthread_mutex_init(&var, &mutex_attr); \
53 #define IOSYNCHRONIZE(var) pthread_mutex_lock(&var)
54 #define IODESYNCHRONIZE(var) pthread_mutex_unlock(&var)
56 #define IOTHREAD_MUTEX_INIT(var)
57 #define IOSYNCHRONIZE(var)
58 #define IODESYNCHRONIZE(var)
61 #define IODNSFLAG_RUNNING 0x01
62 #define IODNSFLAG_PROCESSING 0x02
63 #define IODNSFLAG_PARENT_PUBLIC 0x04
64 #define IODNSFLAG_PARENT_SOCKET 0x08
71 unsigned int flags : 8;
72 unsigned int type : 8;
74 struct IODNSAddress addr;
78 struct IODNSResult *result;
82 struct _IODNSQuery *next, *prev;
89 void (*add)(struct _IODNSQuery *query);
90 void (*remove)(struct _IODNSQuery *query);
96 struct _IODNSQuery *_create_dnsquery();
97 void _start_dnsquery(struct _IODNSQuery *query);
98 void _stop_dnsquery(struct _IODNSQuery *query);
100 /* call only from engines! */
102 void _free_dnsquery(struct _IODNSQuery *query);
103 void iodns_event_callback(struct _IODNSQuery *query, enum IODNSEventType state);
112 #define IODNS_CALLBACK(NAME) void NAME(struct IODNSEvent *event)
113 typedef IODNS_CALLBACK(iodns_callback);
115 enum IODNSEventType {
120 #define IODNS_RECORD_A 0x01
121 #define IODNS_RECORD_AAAA 0x02
122 #define IODNS_RECORD_PTR 0x04
124 #define IODNS_FORWARD 0x03
125 #define IODNS_REVERSE 0x04
130 iodns_callback *callback;
135 unsigned int type : 8;
137 struct IODNSAddress addr;
140 struct IODNSResult *next;
144 enum IODNSEventType type;
145 struct IODNSQuery *query;
146 struct IODNSResult *result;
149 struct IODNSQuery *iodns_getaddrinfo(char *hostname, int records, iodns_callback *callback);
150 struct IODNSQuery *iodns_getnameinfo(const struct sockaddr *addr, size_t addrlen, iodns_callback *callback);
151 void iodns_abort(struct IODNSQuery *query);
153 void iodns_free_result(struct IODNSResult *result);