[IOMultiplexerV2] Added iodns_print_address: inet_ntop eqivalent function for struct...
[NextIRCd.git] / src / IOHandler / IODNSLookup.c
index f458bf5ca033bf89e4f0eb4d264c8209a8539f3f..732cc0efedaef4434cd281d56c2a346c14fce113 100644 (file)
 #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 <string.h>
 
 struct _IODNSQuery *iodnsquery_first = NULL;
@@ -211,6 +228,23 @@ void iodns_abort(struct IODNSQuery *descriptor) {
        _stop_dnsquery(query);
 }
 
+int iodns_print_address(struct IODNSAddress *addr, int ipv6, const char *buffer, int length) {
+       int af;
+       void *addr;
+       if(ipv6) {
+               af = AF_INET6;
+               addr = (void *)(&((struct sockaddr_in6 *)sockaddr->address)->sin6_addr);
+       } else {
+               af = AF_INET;
+               addr = (void *)(&((struct sockaddr_in *)sockaddr->address)->sin_addr);
+       }
+       buffer = 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) {