* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#include "IOLog.h"
#include "IOSockets.h"
+#ifdef WIN32
+#ifdef _WIN32_WINNT
+#undef _WIN32_WINNT
+#endif
+#define _WIN32_WINNT 0x501
+#include <winsock2.h>
+#include <windows.h>
+#include <ws2tcpip.h>
+#else
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/ip.h>
+#include <arpa/inet.h>
+#include <unistd.h>
+#include <fcntl.h>
+#endif
+#include "compat/inet.h"
+
#include <string.h>
struct _IODNSQuery *iodnsquery_first = NULL;
_free_dnsquery(query);
}
+void iodns_socket_callback(struct _IOSocket *iosock, int wantread, int wantwrite) {
+ if(dnsengine && dnsengine->socket_callback)
+ dnsengine->socket_callback(iosock, wantread, wantwrite);
+}
+
void iodns_event_callback(struct _IODNSQuery *query, enum IODNSEventType state) {
if((query->flags & IODNSFLAG_PARENT_PUBLIC)) {
struct IODNSQuery *descriptor = query->parent;
/* public functions */
-struct IODNSQuery *iodns_getaddrinfo(char *hostname, int records, iodns_callback *callback) {
+struct IODNSQuery *iodns_getaddrinfo(char *hostname, int records, iodns_callback *callback, void *arg) {
if(!(records & IODNS_FORWARD) || !hostname || !callback)
return NULL;
query->parent = descriptor;
query->flags |= IODNSFLAG_PARENT_PUBLIC;
descriptor->query = query;
+ descriptor->data = arg;
query->request.host = strdup(hostname);
query->type = (records & IODNS_FORWARD);
return descriptor;
}
-struct IODNSQuery *iodns_getnameinfo(const struct sockaddr *addr, size_t addrlen, iodns_callback *callback) {
+struct IODNSQuery *iodns_getnameinfo(const struct sockaddr *addr, size_t addrlen, iodns_callback *callback, void *arg) {
if(!addr || !callback)
return NULL;
query->parent = descriptor;
query->flags |= IODNSFLAG_PARENT_PUBLIC;
descriptor->query = query;
+ descriptor->data = arg;
query->type = IODNS_RECORD_PTR;
query->request.addr.addresslen = addrlen;
_stop_dnsquery(query);
}
+int iodns_print_address(struct IODNSAddress *address, int ipv6, char *buffer, int length) {
+ int af;
+ void *addr;
+ if(ipv6) {
+ af = AF_INET6;
+ addr = (void *)(&((struct sockaddr_in6 *)address->address)->sin6_addr);
+ } else {
+ af = AF_INET;
+ addr = (void *)(&((struct sockaddr_in *)address->address)->sin_addr);
+ }
+ buffer = (char*) inet_ntop(af, addr, buffer, length);
+ if(!buffer)
+ return 0;
+ else
+ return strlen(buffer);
+}
+
void iodns_free_result(struct IODNSResult *result) {
struct IODNSResult *next;
for(;result;result = next) {