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
72 unsigned int flags : 8;
73 unsigned int type : 8;
75 struct IODNSAddress addr;
79 struct IODNSResult *result;
83 struct _IODNSQuery *next, *prev;
90 void (*add)(struct _IODNSQuery *query);
91 void (*remove)(struct _IODNSQuery *query);
93 void (*socket_callback)(struct _IOSocket *iosock, int readable, int writeable);
98 struct _IODNSQuery *_create_dnsquery();
99 void _start_dnsquery(struct _IODNSQuery *query);
100 void _stop_dnsquery(struct _IODNSQuery *query);
102 /* call only from engines! */
104 void _free_dnsquery(struct _IODNSQuery *query);
105 void iodns_socket_callback(struct _IOSocket *iosock, int wantread, int wantwrite);
106 void iodns_event_callback(struct _IODNSQuery *query, enum IODNSEventType state);
114 #define IODNS_CALLBACK(NAME) void NAME(struct IODNSEvent *event)
115 typedef IODNS_CALLBACK(iodns_callback);
117 enum IODNSEventType {
122 #define IODNS_RECORD_A 0x01
123 #define IODNS_RECORD_AAAA 0x02
124 #define IODNS_RECORD_PTR 0x04
126 #define IODNS_FORWARD 0x03
127 #define IODNS_REVERSE 0x04
132 iodns_callback *callback;
137 unsigned int type : 8;
139 struct IODNSAddress addr;
142 struct IODNSResult *next;
146 enum IODNSEventType type;
147 struct IODNSQuery *query;
148 struct IODNSResult *result;
151 struct IODNSQuery *iodns_getaddrinfo(char *hostname, int records, iodns_callback *callback, void *arg);
152 struct IODNSQuery *iodns_getnameinfo(const struct sockaddr *addr, size_t addrlen, iodns_callback *callback, void *arg);
153 void iodns_abort(struct IODNSQuery *query);
155 int iodns_print_address(struct IODNSAddress *addr, int ipv6,const char *buffer, int length);
157 void iodns_free_result(struct IODNSResult *result);