1 /* main.c - IOMultiplexer
2 * Copyright (C) 2012 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/>.
20 #include "../../IOHandler/IOHandler.h"
21 #include "../../IOHandler/IODNSLookup.h"
22 #include "../../IOHandler/IOLog.h"
25 #include "arpa/inet.h"
27 #include "../../IOHandler/compat/inet.h"
29 #define TEST_DURATION 100
31 static IODNS_CALLBACK(io_callback);
32 static IOLOG_CALLBACK(io_log);
34 int main(int argc, char *argv[]) {
36 iolog_register_callback(io_log);
38 iodns_getaddrinfo("google.de", (IODNS_RECORD_A | IODNS_RECORD_AAAA), io_callback, "01");
39 iodns_getaddrinfo("pk910.de", IODNS_RECORD_AAAA, io_callback, "02");
40 iodns_getaddrinfo("nonexisting.no-tld", (IODNS_RECORD_A | IODNS_RECORD_AAAA), io_callback, "03");
41 iodns_getaddrinfo("google.com", (IODNS_RECORD_A | IODNS_RECORD_AAAA), io_callback, "04");
42 iodns_getaddrinfo("test.pk910.de", IODNS_RECORD_A, io_callback, "05");
44 struct sockaddr_in addr;
45 addr.sin_family = AF_INET;
46 inet_pton(AF_INET, "8.8.8.8", &addr.sin_addr);
47 iodns_getnameinfo((struct sockaddr *)&addr, sizeof(addr), io_callback, "06");
53 static IODNS_CALLBACK(io_callback) {
54 struct IODNSQuery *iodns = event->query;
55 char *id = iodns->data;
56 if(event->type == IODNSEVENT_SUCCESS) {
57 printf("Query %s succeeded:\n", id);
58 struct IODNSResult *result;
60 for(result = event->result; result; result = result->next) {
61 switch(result->type) {
63 inet_ntop(AF_INET, &((struct sockaddr_in *)result->result.addr.address)->sin_addr, str, INET_ADDRSTRLEN);
64 printf(" A: %s\n", str);
67 iodns_getnameinfo(result->result.addr.address, result->result.addr.addresslen, io_callback, "07");
69 case IODNS_RECORD_AAAA:
70 inet_ntop(AF_INET6, &((struct sockaddr_in6 *)result->result.addr.address)->sin6_addr, str, INET6_ADDRSTRLEN);
71 printf(" AAAA: %s\n", str);
74 iodns_getnameinfo(result->result.addr.address, result->result.addr.addresslen, io_callback, "07");
76 case IODNS_RECORD_PTR:
77 printf(" PTR: %s\n", result->result.host);
81 iodns_free_result(event->result);
83 printf("Query %s failed.\n", id);
86 static IOLOG_CALLBACK(io_log) {