[IOMultiplexer] Added asynchronous DNS Lookups
[IOMultiplexer.git] / src / IODNSHandler.h
1 /* IODNSHandler.h - IOMultiplexer
2  * Copyright (C) 2012  Philipp Kreil (pk910)
3  * 
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.
8  * 
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.
13  * 
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/>. 
16  */
17 #ifndef _IODNSHandler_h
18 #define _IODNSHandler_h
19
20
21 #define IODNS_CALLBACK(NAME) void NAME(struct IODNSEvent *event)
22 typedef IODNS_CALLBACK(iodns_callback);
23
24 enum IODNSEventType {
25     IODNSEVENT_SUCCESS,
26     IODNSEVENT_FAILED
27 };
28
29 #define IODNS_RECORD_A    0x01
30 #define IODNS_RECORD_AAAA 0x02
31 #define IODNS_RECORD_PTR  0x04
32
33 #define IODNS_FORWARD     0x03
34 #define IODNS_REVERSE     0x04
35
36 struct IODNSQuery {
37     void *query;
38     unsigned int type : 8;
39     char *hostname;
40     size_t addresslen;
41     union {
42         struct sockaddr *address;
43         struct IODNSResult *results
44     } addr;
45     iodns_callback *callback;
46     void *data;
47     
48     struct IODNSQuery *next, *prev;
49 };
50
51 struct IODNSResult {
52     unsigned int type : 8;
53     size_t addresslen;
54     struct sockaddr *address;
55     struct IODNSResult *next;
56 };
57
58 struct IODNSEvent {
59     enum IODNSEventType type;
60     struct IODNSQuery *query;
61 };
62
63 struct IODNSQuery *iodns_getaddrinfo(char *hostname, int records, iodns_callback *callback);
64 struct IODNSQuery *iodns_getnameinfo(const struct sockaddr *addr, socklen_t addrlen, iodns_callback *callback);
65 void iodns_abort(struct IODNSQuery *query);
66 void iodns_poll();
67
68 void iodns_free_result(struct IODNSResult *result);
69
70 #endif