- Provide Windows querying for DNS_SRV records
Signed-off-by: Adam Stokes <astokes(a)fedoraproject.org>
---
src/lib/CMakeLists.txt | 9 +++++----
src/lib/dnssrv_windows.c | 36 +++++++++++++++++++++++++++++++++++-
2 files changed, 40 insertions(+), 5 deletions(-)
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
index cf37cf3..be2d8f6 100644
--- a/src/lib/CMakeLists.txt
+++ b/src/lib/CMakeLists.txt
@@ -8,7 +8,7 @@ include_directories(${pcre_INCLUDE_DIRS})
add_library (mcommon SHARED utilities.c mainloop.c dnssrv_${VARIANT}.c)
set_target_properties(mcommon PROPERTIES SOVERSION 1.0.0)
-target_link_libraries(mcommon ${SIGAR} ${glib_LIBRARIES} resolv)
+target_link_libraries(mcommon ${SIGAR} ${glib_LIBRARIES})
add_library (mhost SHARED host.c host_${VARIANT}.c)
set_target_properties(mhost PROPERTIES SOVERSION 1.0.0)
@@ -28,12 +28,13 @@ target_link_libraries(mpostboot ${pcre_LIBRARIES} mcommon
${glib_LIBRARIES})
if(WIN32)
foreach (lib ${LIBS})
- target_link_libraries(${lib} wsock32)
- install(TARGETS ${lib} DESTINATION sbin)
+ target_link_libraries(${lib} wsock32 dnsapi)
+ install(TARGETS ${lib} DESTINATION sbin)
endforeach (lib ${LIBS})
else(WIN32)
foreach (lib ${LIBS})
- install(TARGETS ${lib} DESTINATION lib${LIB_SUFFIX})
+ target_link_libraries(${lib} resolv)
+ install(TARGETS ${lib} DESTINATION lib${LIB_SUFFIX})
endforeach (lib ${LIBS})
endif(WIN32)
diff --git a/src/lib/dnssrv_windows.c b/src/lib/dnssrv_windows.c
index 32b00ee..776caf8 100644
--- a/src/lib/dnssrv_windows.c
+++ b/src/lib/dnssrv_windows.c
@@ -18,6 +18,18 @@
#include "matahari/dnssrv.h"
+#include <windows.h>
+#include <winsock.h>
+#include <windns.h>
+
+// mingw doesn't include these
+#ifndef DNS_TYPE_SRV
+# define DNS_TYPE_SRV 33
+#endif
+
+#ifndef NS_MAXDNAME
+# define NS_MAXDNAME 1025
+#endif
/**
* Domain lookup providing a Matahari broker
*
@@ -31,5 +43,27 @@
int
mh_srv_lookup(const char *query, char *target, size_t len)
{
- return -1;
+ PDNS_RECORD rr, record;
+ WCHAR wstr[len];
+
+
+ MultiByteToWideChar(CP_UTF8, 0, query, len, wstr, len);
+ if (DnsQuery(wstr, DNS_TYPE_SRV,
+ DNS_QUERY_STANDARD, NULL,
+ &rr, NULL) == ERROR_SUCCESS) {
+
+ record = rr;
+ do {
+ if (record->wType == DNS_TYPE_SRV) {
+ WideCharToMultiByte(CP_UTF8, 0, wstr, len, target, len, NULL, NULL);
+ target[len] = '\0';
+ }
+ record = record->pNext;
+ }
+ while (rr != NULL);
+ DnsRecordListFree(rr, DnsFreeRecordList);
+ return 0;
+ } else {
+ return -1;
+ }
}
--
1.7.6