changeset 30582:014a58e994da

Use DNSServiceGetAddrInfo() from dns_sd.h to resolve the IP for remote bonjour users on Win32 instead of the libpurple resolving API. This way, we make sure we're using the same interface as we received the presence notification on. There is also some debug message improvement and using constants instead of magic numbers in this commit.
author Daniel Atallah <daniel.atallah@gmail.com>
date Mon, 04 Oct 2010 00:35:26 +0000
parents cc05402eb2ba
children 9c8b28dc6656
files libpurple/protocols/bonjour/dns_sd_proxy.c libpurple/protocols/bonjour/dns_sd_proxy.h libpurple/protocols/bonjour/mdns_win32.c
diffstat 3 files changed, 231 insertions(+), 212 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/bonjour/dns_sd_proxy.c	Sat Oct 02 23:04:49 2010 +0000
+++ b/libpurple/protocols/bonjour/dns_sd_proxy.c	Mon Oct 04 00:35:26 2010 +0000
@@ -1,181 +1,191 @@
-/*
- *
- * Purple is the legal property of its developers, whose names are too numerous
- * to list here.  Please refer to the COPYRIGHT file distributed with this
- * source distribution.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 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
- * GNU Library General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301, USA.
- */
-
-#include "win32dep.h"
-#include "dns_sd_proxy.h"
-
-#ifndef LINK_DNS_SD_DIRECTLY
-static DNSServiceErrorType (DNSSD_API* _DNSServiceAddRecord)(DNSServiceRef sdRef, DNSRecordRef *RecordRef, DNSServiceFlags flags,
-		uint16_t rrtype, uint16_t rdlen, const void *rdata, uint32_t ttl);
-static DNSServiceErrorType (DNSSD_API* _DNSServiceBrowse)(DNSServiceRef *sdRef, DNSServiceFlags flags, uint32_t interfaceIndex,
-	const char *regtype, const char *domain, DNSServiceBrowseReply callBack, void *context);
-static int (DNSSD_API* _DNSServiceConstructFullName)(char *fullName, const char *service, const char *regtype, const char *domain);
-static DNSServiceErrorType (DNSSD_API* _DNSServiceProcessResult)(DNSServiceRef sdRef);
-static DNSServiceErrorType (DNSSD_API* _DNSServiceQueryRecord)(DNSServiceRef *sdRef, DNSServiceFlags flags, uint32_t interfaceIndex,
-	const char *fullname, uint16_t rrtype, uint16_t rrclass, DNSServiceQueryRecordReply callBack, void *context);
-static void (DNSSD_API* _DNSServiceRefDeallocate)(DNSServiceRef sdRef);
-static int (DNSSD_API* _DNSServiceRefSockFD)(DNSServiceRef sdRef);
-static DNSServiceErrorType (DNSSD_API* _DNSServiceRegister)(DNSServiceRef *sdRef, DNSServiceFlags flags, uint32_t interfaceIndex,
-	const char *name, const char *regtype, const char *domain, const char *host, uint16_t port, uint16_t txtLen,
-	const void *txtRecord, DNSServiceRegisterReply callBack, void *context);
-static DNSServiceErrorType (DNSSD_API* _DNSServiceResolve)(DNSServiceRef *sdRef, DNSServiceFlags flags, uint32_t interfaceIndex, const char *name,
-	const char *regtype, const char *domain, DNSServiceResolveReply callBack, void *context);
-static DNSServiceErrorType (DNSSD_API* _DNSServiceRemoveRecord)(DNSServiceRef sdRef, DNSRecordRef RecordRef, DNSServiceFlags flags);
-static DNSServiceErrorType (DNSSD_API* _DNSServiceUpdateRecord)(DNSServiceRef sdRef, DNSRecordRef RecordRef, DNSServiceFlags flags,
-	uint16_t rdlen, const void *rdata, uint32_t ttl);
-static void (DNSSD_API* _TXTRecordCreate)(TXTRecordRef *txtRecord, uint16_t bufferLen, void *buffer);
-static void (DNSSD_API* _TXTRecordDeallocate)(TXTRecordRef *txtRecord);
-static const void * (DNSSD_API* _TXTRecordGetBytesPtr)(const TXTRecordRef *txtRecord);
-static int16_t (DNSSD_API* _TXTRecordGetLength)(const TXTRecordRef *txtRecord);
-static const void * (DNSSD_API* _TXTRecordGetValuePtr)(uint16_t txtLen, const void *txtRecord, const char *key, uint8_t *valueLen);
-static DNSServiceErrorType (DNSSD_API* _TXTRecordSetValue)(TXTRecordRef *txtRecord, const char *key, uint8_t valueSize, const void *value);
-#endif
-
-gboolean dns_sd_available(void) {
-#ifndef LINK_DNS_SD_DIRECTLY
-	static gboolean initialized = FALSE;
-	static gboolean loaded = FALSE;
-
-	if (!initialized) {
-		initialized = TRUE;
-		if ((_DNSServiceAddRecord = (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceAddRecord"))
-				&& (_DNSServiceBrowse = (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceBrowse"))
-				&& (_DNSServiceConstructFullName = (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceConstructFullName"))
-				&& (_DNSServiceProcessResult = (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceProcessResult"))
-				&& (_DNSServiceQueryRecord = (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceQueryRecord"))
-				&& (_DNSServiceRefDeallocate = (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceRefDeallocate"))
-				&& (_DNSServiceRefSockFD = (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceRefSockFD"))
-				&& (_DNSServiceRegister = (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceRegister"))
-				&& (_DNSServiceResolve = (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceResolve"))
-				&& (_DNSServiceRemoveRecord = (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceRemoveRecord"))
-				&& (_DNSServiceUpdateRecord = (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceUpdateRecord"))
-				&& (_TXTRecordCreate = (void *) wpurple_find_and_loadproc("dnssd.dll", "TXTRecordCreate"))
-				&& (_TXTRecordDeallocate = (void *) wpurple_find_and_loadproc("dnssd.dll", "TXTRecordDeallocate"))
-				&& (_TXTRecordGetBytesPtr = (void *) wpurple_find_and_loadproc("dnssd.dll", "TXTRecordGetBytesPtr"))
-				&& (_TXTRecordGetLength = (void *) wpurple_find_and_loadproc("dnssd.dll", "TXTRecordGetLength"))
-				&& (_TXTRecordGetValuePtr = (void *) wpurple_find_and_loadproc("dnssd.dll", "TXTRecordGetValuePtr"))
-				&& (_TXTRecordSetValue = (void *) wpurple_find_and_loadproc("dnssd.dll", "TXTRecordSetValue"))) {
-			loaded = TRUE;
-		}
-	}
-	return loaded;
-#else
-	return TRUE;
-#endif
-}
-
-#ifndef LINK_DNS_SD_DIRECTLY
-
-DNSServiceErrorType _wpurple_DNSServiceAddRecord(DNSServiceRef sdRef, DNSRecordRef *RecordRef, DNSServiceFlags flags,
-		uint16_t rrtype, uint16_t rdlen, const void *rdata, uint32_t ttl) {
-	g_return_val_if_fail(_DNSServiceAddRecord != NULL, kDNSServiceErr_Unknown);
-	return (_DNSServiceAddRecord)(sdRef, RecordRef, flags, rrtype, rdlen, rdata, ttl);
-}
-
-DNSServiceErrorType _wpurple_DNSServiceBrowse(DNSServiceRef *sdRef, DNSServiceFlags flags, uint32_t interfaceIndex,
-		const char *regtype, const char *domain, DNSServiceBrowseReply callBack, void *context) {
-	g_return_val_if_fail(_DNSServiceBrowse != NULL, kDNSServiceErr_Unknown);
-	return (_DNSServiceBrowse)(sdRef, flags, interfaceIndex, regtype, domain, callBack, context);
-}
-
-int _wpurple_DNSServiceConstructFullName(char *fullName, const char *service, const char *regtype, const char *domain) {
-	g_return_val_if_fail(_DNSServiceConstructFullName != NULL, 0);
-	return (_DNSServiceConstructFullName)(fullName, service, regtype, domain);
-}
-
-DNSServiceErrorType _wpurple_DNSServiceProcessResult(DNSServiceRef sdRef) {
-	g_return_val_if_fail(_DNSServiceProcessResult != NULL, kDNSServiceErr_Unknown);
-	return (_DNSServiceProcessResult)(sdRef);
-}
-
-
-DNSServiceErrorType _wpurple_DNSServiceQueryRecord(DNSServiceRef *sdRef, DNSServiceFlags flags, uint32_t interfaceIndex,
-		const char *fullname, uint16_t rrtype, uint16_t rrclass, DNSServiceQueryRecordReply callBack, void *context) {
-	g_return_val_if_fail(_DNSServiceQueryRecord != NULL, kDNSServiceErr_Unknown);
-	return (_DNSServiceQueryRecord)(sdRef, flags, interfaceIndex, fullname, rrtype, rrclass, callBack, context);
-}
-
-void _wpurple_DNSServiceRefDeallocate(DNSServiceRef sdRef) {
-	g_return_if_fail(_DNSServiceRefDeallocate != NULL);
-	(_DNSServiceRefDeallocate)(sdRef);
-}
-
-int _wpurple_DNSServiceRefSockFD(DNSServiceRef sdRef) {
-	g_return_val_if_fail(_DNSServiceRefSockFD != NULL, -1);
-	return (_DNSServiceRefSockFD)(sdRef);
-}
-
-DNSServiceErrorType _wpurple_DNSServiceRegister(DNSServiceRef *sdRef, DNSServiceFlags flags, uint32_t interfaceIndex,
-		const char *name, const char *regtype, const char *domain, const char *host, uint16_t port, uint16_t txtLen,
-		const void *txtRecord, DNSServiceRegisterReply callBack, void *context) {
-	g_return_val_if_fail(_DNSServiceRegister != NULL, kDNSServiceErr_Unknown);
-	return (_DNSServiceRegister)(sdRef, flags, interfaceIndex, name, regtype, domain, host, port, txtLen, txtRecord, callBack, context);
-}
-
-DNSServiceErrorType _wpurple_DNSServiceResolve(DNSServiceRef *sdRef, DNSServiceFlags flags, uint32_t interfaceIndex, const char *name,
-		const char *regtype, const char *domain, DNSServiceResolveReply callBack, void *context) {
-	g_return_val_if_fail(_DNSServiceResolve != NULL, kDNSServiceErr_Unknown);
-	return (_DNSServiceResolve)(sdRef, flags, interfaceIndex, name, regtype, domain, callBack, context);
-}
-
-DNSServiceErrorType _wpurple_DNSServiceRemoveRecord(DNSServiceRef sdRef, DNSRecordRef RecordRef, DNSServiceFlags flags) {
-	g_return_val_if_fail(_DNSServiceRemoveRecord != NULL, kDNSServiceErr_Unknown);
-	return (_DNSServiceRemoveRecord)(sdRef, RecordRef, flags);
-}
-
-DNSServiceErrorType _wpurple_DNSServiceUpdateRecord(DNSServiceRef sdRef, DNSRecordRef RecordRef, DNSServiceFlags flags,
-		uint16_t rdlen, const void *rdata, uint32_t ttl) {
-	g_return_val_if_fail(_DNSServiceUpdateRecord != NULL, kDNSServiceErr_Unknown);
-	return (_DNSServiceUpdateRecord)(sdRef, RecordRef, flags, rdlen, rdata, ttl);
-}
-
-void _wpurple_TXTRecordCreate(TXTRecordRef *txtRecord, uint16_t bufferLen, void *buffer) {
-	g_return_if_fail(_TXTRecordCreate != NULL);
-	(_TXTRecordCreate)(txtRecord, bufferLen, buffer);
-}
-
-void _wpurple_TXTRecordDeallocate(TXTRecordRef *txtRecord) {
-	g_return_if_fail(_TXTRecordDeallocate != NULL);
-	(_TXTRecordDeallocate)(txtRecord);
-}
-
-const void * _wpurple_TXTRecordGetBytesPtr(const TXTRecordRef *txtRecord) {
-	g_return_val_if_fail(_TXTRecordGetBytesPtr != NULL, NULL);
-	return (_TXTRecordGetBytesPtr)(txtRecord);
-}
-
-uint16_t _wpurple_TXTRecordGetLength(const TXTRecordRef *txtRecord) {
-	g_return_val_if_fail(_TXTRecordGetLength != NULL, 0);
-	return (_TXTRecordGetLength)(txtRecord);
-}
-
-const void * _wpurple_TXTRecordGetValuePtr(uint16_t txtLen, const void *txtRecord, const char *key, uint8_t *valueLen) {
-	g_return_val_if_fail(_TXTRecordGetValuePtr != NULL, NULL);
-	return (_TXTRecordGetValuePtr)(txtLen, txtRecord, key, valueLen);
-}
-
-DNSServiceErrorType _wpurple_TXTRecordSetValue(TXTRecordRef *txtRecord, const char *key, uint8_t valueSize, const void *value) {
-	g_return_val_if_fail(_TXTRecordSetValue != NULL, kDNSServiceErr_Unknown);
-	return (_TXTRecordSetValue)(txtRecord, key, valueSize, value);
-}
-
-#endif /*LINK_DNS_SD_DIRECTLY*/
-
+/*
+ *
+ * Purple is the legal property of its developers, whose names are too numerous
+ * to list here.  Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 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
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301, USA.
+ */
+
+#include "win32dep.h"
+#include "dns_sd_proxy.h"
+
+#ifndef LINK_DNS_SD_DIRECTLY
+static DNSServiceErrorType (DNSSD_API* _DNSServiceAddRecord)(DNSServiceRef sdRef, DNSRecordRef *RecordRef, DNSServiceFlags flags,
+		uint16_t rrtype, uint16_t rdlen, const void *rdata, uint32_t ttl);
+static DNSServiceErrorType (DNSSD_API* _DNSServiceBrowse)(DNSServiceRef *sdRef, DNSServiceFlags flags, uint32_t interfaceIndex,
+	const char *regtype, const char *domain, DNSServiceBrowseReply callBack, void *context);
+static int (DNSSD_API* _DNSServiceConstructFullName)(char *fullName, const char *service, const char *regtype, const char *domain);
+static DNSServiceErrorType (DNSSD_API* _DNSServiceGetAddrInfo)(DNSServiceRef *sdRef, DNSServiceFlags flags, uint32_t interfaceIndex,
+	DNSServiceProtocol protocol, const char *hostname, DNSServiceGetAddrInfoReply callBack, void *context);
+static DNSServiceErrorType (DNSSD_API* _DNSServiceProcessResult)(DNSServiceRef sdRef);
+static DNSServiceErrorType (DNSSD_API* _DNSServiceQueryRecord)(DNSServiceRef *sdRef, DNSServiceFlags flags, uint32_t interfaceIndex,
+	const char *fullname, uint16_t rrtype, uint16_t rrclass, DNSServiceQueryRecordReply callBack, void *context);
+static void (DNSSD_API* _DNSServiceRefDeallocate)(DNSServiceRef sdRef);
+static int (DNSSD_API* _DNSServiceRefSockFD)(DNSServiceRef sdRef);
+static DNSServiceErrorType (DNSSD_API* _DNSServiceRegister)(DNSServiceRef *sdRef, DNSServiceFlags flags, uint32_t interfaceIndex,
+	const char *name, const char *regtype, const char *domain, const char *host, uint16_t port, uint16_t txtLen,
+	const void *txtRecord, DNSServiceRegisterReply callBack, void *context);
+static DNSServiceErrorType (DNSSD_API* _DNSServiceResolve)(DNSServiceRef *sdRef, DNSServiceFlags flags, uint32_t interfaceIndex, const char *name,
+	const char *regtype, const char *domain, DNSServiceResolveReply callBack, void *context);
+static DNSServiceErrorType (DNSSD_API* _DNSServiceRemoveRecord)(DNSServiceRef sdRef, DNSRecordRef RecordRef, DNSServiceFlags flags);
+static DNSServiceErrorType (DNSSD_API* _DNSServiceUpdateRecord)(DNSServiceRef sdRef, DNSRecordRef RecordRef, DNSServiceFlags flags,
+	uint16_t rdlen, const void *rdata, uint32_t ttl);
+static void (DNSSD_API* _TXTRecordCreate)(TXTRecordRef *txtRecord, uint16_t bufferLen, void *buffer);
+static void (DNSSD_API* _TXTRecordDeallocate)(TXTRecordRef *txtRecord);
+static const void * (DNSSD_API* _TXTRecordGetBytesPtr)(const TXTRecordRef *txtRecord);
+static int16_t (DNSSD_API* _TXTRecordGetLength)(const TXTRecordRef *txtRecord);
+static const void * (DNSSD_API* _TXTRecordGetValuePtr)(uint16_t txtLen, const void *txtRecord, const char *key, uint8_t *valueLen);
+static DNSServiceErrorType (DNSSD_API* _TXTRecordSetValue)(TXTRecordRef *txtRecord, const char *key, uint8_t valueSize, const void *value);
+
+#endif
+
+gboolean dns_sd_available(void) {
+#ifndef LINK_DNS_SD_DIRECTLY
+	static gboolean initialized = FALSE;
+	static gboolean loaded = FALSE;
+
+	if (!initialized) {
+		initialized = TRUE;
+		if ((_DNSServiceAddRecord = (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceAddRecord"))
+				&& (_DNSServiceBrowse = (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceBrowse"))
+				&& (_DNSServiceConstructFullName = (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceConstructFullName"))
+				&& (_DNSServiceGetAddrInfo = (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceGetAddrInfo"))
+				&& (_DNSServiceProcessResult = (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceProcessResult"))
+				&& (_DNSServiceQueryRecord = (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceQueryRecord"))
+				&& (_DNSServiceRefDeallocate = (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceRefDeallocate"))
+				&& (_DNSServiceRefSockFD = (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceRefSockFD"))
+				&& (_DNSServiceRegister = (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceRegister"))
+				&& (_DNSServiceResolve = (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceResolve"))
+				&& (_DNSServiceRemoveRecord = (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceRemoveRecord"))
+				&& (_DNSServiceUpdateRecord = (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceUpdateRecord"))
+				&& (_TXTRecordCreate = (void *) wpurple_find_and_loadproc("dnssd.dll", "TXTRecordCreate"))
+				&& (_TXTRecordDeallocate = (void *) wpurple_find_and_loadproc("dnssd.dll", "TXTRecordDeallocate"))
+				&& (_TXTRecordGetBytesPtr = (void *) wpurple_find_and_loadproc("dnssd.dll", "TXTRecordGetBytesPtr"))
+				&& (_TXTRecordGetLength = (void *) wpurple_find_and_loadproc("dnssd.dll", "TXTRecordGetLength"))
+				&& (_TXTRecordGetValuePtr = (void *) wpurple_find_and_loadproc("dnssd.dll", "TXTRecordGetValuePtr"))
+				&& (_TXTRecordSetValue = (void *) wpurple_find_and_loadproc("dnssd.dll", "TXTRecordSetValue"))) {
+			loaded = TRUE;
+		}
+	}
+	return loaded;
+#else
+	return TRUE;
+#endif
+}
+
+#ifndef LINK_DNS_SD_DIRECTLY
+
+DNSServiceErrorType _wpurple_DNSServiceAddRecord(DNSServiceRef sdRef, DNSRecordRef *RecordRef, DNSServiceFlags flags,
+		uint16_t rrtype, uint16_t rdlen, const void *rdata, uint32_t ttl) {
+	g_return_val_if_fail(_DNSServiceAddRecord != NULL, kDNSServiceErr_Unknown);
+	return (_DNSServiceAddRecord)(sdRef, RecordRef, flags, rrtype, rdlen, rdata, ttl);
+}
+
+DNSServiceErrorType _wpurple_DNSServiceBrowse(DNSServiceRef *sdRef, DNSServiceFlags flags, uint32_t interfaceIndex,
+		const char *regtype, const char *domain, DNSServiceBrowseReply callBack, void *context) {
+	g_return_val_if_fail(_DNSServiceBrowse != NULL, kDNSServiceErr_Unknown);
+	return (_DNSServiceBrowse)(sdRef, flags, interfaceIndex, regtype, domain, callBack, context);
+}
+
+int _wpurple_DNSServiceConstructFullName(char *fullName, const char *service, const char *regtype, const char *domain) {
+	g_return_val_if_fail(_DNSServiceConstructFullName != NULL, 0);
+	return (_DNSServiceConstructFullName)(fullName, service, regtype, domain);
+}
+
+DNSServiceErrorType _wpurple_DNSServiceGetAddrInfo(DNSServiceRef *sdRef, DNSServiceFlags flags, uint32_t interfaceIndex,
+		DNSServiceProtocol protocol, const char *hostname, DNSServiceGetAddrInfoReply callBack, void *context) {
+	g_return_val_if_fail(_DNSServiceGetAddrInfo != NULL, 0);
+	return (_DNSServiceGetAddrInfo)(sdRef, flags, interfaceIndex, protocol, hostname, callBack, context);
+}
+
+DNSServiceErrorType _wpurple_DNSServiceProcessResult(DNSServiceRef sdRef) {
+	g_return_val_if_fail(_DNSServiceProcessResult != NULL, kDNSServiceErr_Unknown);
+	return (_DNSServiceProcessResult)(sdRef);
+}
+
+
+DNSServiceErrorType _wpurple_DNSServiceQueryRecord(DNSServiceRef *sdRef, DNSServiceFlags flags, uint32_t interfaceIndex,
+		const char *fullname, uint16_t rrtype, uint16_t rrclass, DNSServiceQueryRecordReply callBack, void *context) {
+	g_return_val_if_fail(_DNSServiceQueryRecord != NULL, kDNSServiceErr_Unknown);
+	return (_DNSServiceQueryRecord)(sdRef, flags, interfaceIndex, fullname, rrtype, rrclass, callBack, context);
+}
+
+void _wpurple_DNSServiceRefDeallocate(DNSServiceRef sdRef) {
+	g_return_if_fail(_DNSServiceRefDeallocate != NULL);
+	(_DNSServiceRefDeallocate)(sdRef);
+}
+
+int _wpurple_DNSServiceRefSockFD(DNSServiceRef sdRef) {
+	g_return_val_if_fail(_DNSServiceRefSockFD != NULL, -1);
+	return (_DNSServiceRefSockFD)(sdRef);
+}
+
+DNSServiceErrorType _wpurple_DNSServiceRegister(DNSServiceRef *sdRef, DNSServiceFlags flags, uint32_t interfaceIndex,
+		const char *name, const char *regtype, const char *domain, const char *host, uint16_t port, uint16_t txtLen,
+		const void *txtRecord, DNSServiceRegisterReply callBack, void *context) {
+	g_return_val_if_fail(_DNSServiceRegister != NULL, kDNSServiceErr_Unknown);
+	return (_DNSServiceRegister)(sdRef, flags, interfaceIndex, name, regtype, domain, host, port, txtLen, txtRecord, callBack, context);
+}
+
+DNSServiceErrorType _wpurple_DNSServiceResolve(DNSServiceRef *sdRef, DNSServiceFlags flags, uint32_t interfaceIndex, const char *name,
+		const char *regtype, const char *domain, DNSServiceResolveReply callBack, void *context) {
+	g_return_val_if_fail(_DNSServiceResolve != NULL, kDNSServiceErr_Unknown);
+	return (_DNSServiceResolve)(sdRef, flags, interfaceIndex, name, regtype, domain, callBack, context);
+}
+
+DNSServiceErrorType _wpurple_DNSServiceRemoveRecord(DNSServiceRef sdRef, DNSRecordRef RecordRef, DNSServiceFlags flags) {
+	g_return_val_if_fail(_DNSServiceRemoveRecord != NULL, kDNSServiceErr_Unknown);
+	return (_DNSServiceRemoveRecord)(sdRef, RecordRef, flags);
+}
+
+DNSServiceErrorType _wpurple_DNSServiceUpdateRecord(DNSServiceRef sdRef, DNSRecordRef RecordRef, DNSServiceFlags flags,
+		uint16_t rdlen, const void *rdata, uint32_t ttl) {
+	g_return_val_if_fail(_DNSServiceUpdateRecord != NULL, kDNSServiceErr_Unknown);
+	return (_DNSServiceUpdateRecord)(sdRef, RecordRef, flags, rdlen, rdata, ttl);
+}
+
+void _wpurple_TXTRecordCreate(TXTRecordRef *txtRecord, uint16_t bufferLen, void *buffer) {
+	g_return_if_fail(_TXTRecordCreate != NULL);
+	(_TXTRecordCreate)(txtRecord, bufferLen, buffer);
+}
+
+void _wpurple_TXTRecordDeallocate(TXTRecordRef *txtRecord) {
+	g_return_if_fail(_TXTRecordDeallocate != NULL);
+	(_TXTRecordDeallocate)(txtRecord);
+}
+
+const void * _wpurple_TXTRecordGetBytesPtr(const TXTRecordRef *txtRecord) {
+	g_return_val_if_fail(_TXTRecordGetBytesPtr != NULL, NULL);
+	return (_TXTRecordGetBytesPtr)(txtRecord);
+}
+
+uint16_t _wpurple_TXTRecordGetLength(const TXTRecordRef *txtRecord) {
+	g_return_val_if_fail(_TXTRecordGetLength != NULL, 0);
+	return (_TXTRecordGetLength)(txtRecord);
+}
+
+const void * _wpurple_TXTRecordGetValuePtr(uint16_t txtLen, const void *txtRecord, const char *key, uint8_t *valueLen) {
+	g_return_val_if_fail(_TXTRecordGetValuePtr != NULL, NULL);
+	return (_TXTRecordGetValuePtr)(txtLen, txtRecord, key, valueLen);
+}
+
+DNSServiceErrorType _wpurple_TXTRecordSetValue(TXTRecordRef *txtRecord, const char *key, uint8_t valueSize, const void *value) {
+	g_return_val_if_fail(_TXTRecordSetValue != NULL, kDNSServiceErr_Unknown);
+	return (_TXTRecordSetValue)(txtRecord, key, valueSize, value);
+}
+
+#endif /*LINK_DNS_SD_DIRECTLY*/
+
--- a/libpurple/protocols/bonjour/dns_sd_proxy.h	Sat Oct 02 23:04:49 2010 +0000
+++ b/libpurple/protocols/bonjour/dns_sd_proxy.h	Mon Oct 04 00:35:26 2010 +0000
@@ -51,6 +51,11 @@
 #define DNSServiceConstructFullName(fullName, service, regtype, domain) \
 	_wpurple_DNSServiceConstructFullName(fullName, service, regtype, domain)
 
+DNSServiceErrorType _wpurple_DNSServiceGetAddrInfo(DNSServiceRef *sdRef, DNSServiceFlags flags, uint32_t interfaceIndex,
+	DNSServiceProtocol protocol, const char *hostname, DNSServiceGetAddrInfoReply callBack, void *context);
+#define DNSServiceGetAddrInfo(sdRef, flags, interfaceIndex, protocol, hostname, callBack, context) \
+	_wpurple_DNSServiceGetAddrInfo(sdRef, flags, interfaceIndex, protocol, hostname, callBack, context)
+
 DNSServiceErrorType _wpurple_DNSServiceProcessResult(DNSServiceRef sdRef);
 #define DNSServiceProcessResult(sdRef) \
 	_wpurple_DNSServiceProcessResult(sdRef);
--- a/libpurple/protocols/bonjour/mdns_win32.c	Sat Oct 02 23:04:49 2010 +0000
+++ b/libpurple/protocols/bonjour/mdns_win32.c	Mon Oct 04 00:35:26 2010 +0000
@@ -25,7 +25,6 @@
 #include "buddy.h"
 #include "mdns_interface.h"
 #include "dns_sd_proxy.h"
-#include "dnsquery.h"
 #include "mdns_common.h"
 
 static GSList *pending_buddies = NULL;
@@ -65,7 +64,6 @@
 	BonjourBuddy *bb;
 	Win32SvcResolverData *res_data;
 	gchar *full_service_name;
-	PurpleDnsQueryData *dns_query;
 } ResolveCallbackArgs;
 
 
@@ -135,7 +133,7 @@
 {
 
 	if (errorCode != kDNSServiceErr_NoError) {
-		purple_debug_error("bonjour", "record query - callback error.\n");
+		purple_debug_error("bonjour", "record query - callback error (%d).\n", errorCode);
 		/* TODO: Probably should remove the buddy when this happens */
 	} else if (flags & kDNSServiceFlagsAdd) {
 		if (rrtype == kDNSServiceType_TXT) {
@@ -161,14 +159,22 @@
 	}
 }
 
-static void
-_mdns_resolve_host_callback(GSList *hosts, gpointer data, const char *error_message)
+static void DNSSD_API
+_mdns_resolve_host_callback(DNSServiceRef sdRef, DNSServiceFlags flags,
+	uint32_t interfaceIndex, DNSServiceErrorType errorCode,
+	const char *hostname, const struct sockaddr *address,
+	uint32_t ttl, void *context)
 {
-	ResolveCallbackArgs *args = (ResolveCallbackArgs*) data;
+	ResolveCallbackArgs *args = (ResolveCallbackArgs*) context;
 	Win32BuddyImplData *idata = args->bb->mdns_impl_data;
 	gboolean delete_buddy = FALSE;
 	PurpleBuddy *pb = NULL;
 
+	purple_input_remove(args->resolver_query->input_handler);
+	DNSServiceRefDeallocate(args->resolver_query->sdRef);
+	g_free(args->resolver_query);
+	args->resolver_query = NULL;
+
 	if ((pb = purple_find_buddy(args->account, args->res_data->name))) {
 		if (pb->proto_data != args->bb) {
 			purple_debug_error("bonjour", "Found purple buddy for %s not matching bonjour buddy record.",
@@ -181,12 +187,10 @@
 		goto cleanup;
 	}
 
-	if (!hosts || !hosts->data) {
-		purple_debug_error("bonjour", "host resolution - callback error.\n");
+	if (errorCode != kDNSServiceErr_NoError) {
+		purple_debug_error("bonjour", "host resolution - callback error (%d).\n", errorCode);
 		delete_buddy = TRUE;
 	} else {
-		struct sockaddr_in *addr = g_slist_nth_data(hosts, 1);
-		DNSServiceErrorType errorCode;
 		DNSServiceRef txt_query_sr;
 
 		/* finally, set up the continuous txt record watcher, and add the buddy to purple */
@@ -194,7 +198,7 @@
 				kDNSServiceInterfaceIndexAny, args->full_service_name, kDNSServiceType_TXT,
 				kDNSServiceClass_IN, _mdns_record_query_callback, args->bb);
 		if (errorCode == kDNSServiceErr_NoError) {
-			const char *ip = inet_ntoa(addr->sin_addr);
+			const char *ip = inet_ntoa(((struct sockaddr_in *) address)->sin_addr);
 
 			purple_debug_info("bonjour", "Found buddy %s at %s:%d\n", args->bb->name, ip, args->bb->port_p2pj);
 
@@ -218,13 +222,6 @@
 
 	cleanup:
 
-	/* free the hosts list*/
-	while (hosts != NULL) {
-		hosts = g_slist_remove(hosts, hosts->data);
-		g_free(hosts->data);
-		hosts = g_slist_remove(hosts, hosts->data);
-	}
-
 	if (delete_buddy) {
 		idata->resolvers = g_slist_remove(idata->resolvers, args->res_data);
 		_cleanup_resolver_data(args->res_data);
@@ -259,17 +256,20 @@
 	/* remove the input fd and destroy the service ref */
 	purple_input_remove(args->resolver_query->input_handler);
 	DNSServiceRefDeallocate(args->resolver_query->sdRef);
-	g_free(args->resolver_query);
-	args->resolver_query = NULL;
 
 	if (errorCode != kDNSServiceErr_NoError)
-		purple_debug_error("bonjour", "service resolver - callback error.\n");
+		purple_debug_error("bonjour", "service resolver - callback error. (%d)\n", errorCode);
 	else {
+		DNSServiceRef getaddrinfo_sr;
 		/* set more arguments, and start the host resolver */
-
-		if ((args->dns_query =
-				purple_dnsquery_a(hosttarget, port, _mdns_resolve_host_callback, args)) != NULL) {
-
+		errorCode = DNSServiceGetAddrInfo(&getaddrinfo_sr, 0, interfaceIndex,
+			kDNSServiceProtocol_IPv4, hosttarget, _mdns_resolve_host_callback, args);
+		if (errorCode != kDNSServiceErr_NoError)
+			purple_debug_error("bonjour", "service resolver - host resolution failed.\n");
+		else {
+			args->resolver_query->sdRef = getaddrinfo_sr;
+			args->resolver_query->input_handler = purple_input_add(DNSServiceRefSockFD(getaddrinfo_sr),
+				PURPLE_INPUT_READ, _mdns_handle_event, args->resolver_query);
 			args->full_service_name = g_strdup(fullname);
 
 			/* TODO: Should this be per resolver? */
@@ -277,12 +277,14 @@
 
 			/* We don't want to hit the cleanup code */
 			return;
-		} else
-			purple_debug_error("bonjour", "service resolver - host resolution failed.\n");
+		}
 	}
 
 	/* If we get this far, clean up */
 
+	g_free(args->resolver_query);
+	args->resolver_query = NULL;
+
 	idata->resolvers = g_slist_remove(idata->resolvers, args->res_data);
 	_cleanup_resolver_data(args->res_data);
 
@@ -334,7 +336,7 @@
 							  serviceName, interfaceIndex, regtype ? regtype : "",
 							  replyDomain ? replyDomain : "");
 
-			resErrorCode = DNSServiceResolve(&resolver_sr, 0, 0, serviceName, regtype,
+			resErrorCode = DNSServiceResolve(&resolver_sr, 0, interfaceIndex, serviceName, regtype,
 					replyDomain, _mdns_service_resolve_callback, args);
 			if (resErrorCode == kDNSServiceErr_NoError) {
 				GSList *tmp = pending_buddies;
@@ -483,7 +485,8 @@
 		switch (type) {
 			case PUBLISH_START:
 				purple_debug_info("bonjour", "Registering presence on port %d\n", data->port_p2pj);
-				errorCode = DNSServiceRegister(&presence_sr, 0, 0, purple_account_get_username(data->account), LINK_LOCAL_RECORD_NAME,
+				errorCode = DNSServiceRegister(&presence_sr, kDNSServiceInterfaceIndexAny,
+					0, purple_account_get_username(data->account), LINK_LOCAL_RECORD_NAME,
 					NULL, NULL, htons(data->port_p2pj), TXTRecordGetLength(&dns_data), TXTRecordGetBytesPtr(&dns_data),
 					_mdns_service_register_callback, NULL);
 				break;
@@ -522,8 +525,9 @@
 
 	g_return_val_if_fail(idata != NULL, FALSE);
 
-	errorCode = DNSServiceBrowse(&browser_sr, 0, 0, LINK_LOCAL_RECORD_NAME, NULL,
-		_mdns_service_browse_callback, data->account);
+	errorCode = DNSServiceBrowse(&browser_sr, 0, kDNSServiceInterfaceIndexAny,
+			LINK_LOCAL_RECORD_NAME, NULL,_mdns_service_browse_callback,
+			data->account);
 	if (errorCode == kDNSServiceErr_NoError) {
 		idata->browser_query = g_new(DnsSDServiceRefHandlerData, 1);
 		idata->browser_query->sdRef = browser_sr;