diff libpurple/dnsquery.c @ 26987:cd78ea46e9bd

merge of '7c614b09b72037ebd86c03fbbeac7794a155547b' and 'af18689b86389686230fc6ce83cbba52690ce0cb'
author Paul Aurich <paul@darkrain42.org>
date Sat, 30 May 2009 00:32:50 +0000
parents c162a088489f
children 627d23bfdb05
line wrap: on
line diff
--- a/libpurple/dnsquery.c	Sat May 30 00:21:37 2009 +0000
+++ b/libpurple/dnsquery.c	Sat May 30 00:32:50 2009 +0000
@@ -32,6 +32,10 @@
 #include "prefs.h"
 #include "util.h"
 
+#ifndef _WIN32
+#include <resolv.h>
+#endif
+
 #if (defined(__APPLE__) || defined (__unix__)) && !defined(__osf__)
 #define PURPLE_DNSQUERY_USE_FORK
 #endif
@@ -256,6 +260,9 @@
 		 * library.
 		 */
 		hints.ai_socktype = SOCK_STREAM;
+#ifdef AI_ADDRCONFIG
+		hints.ai_flags |= AI_ADDRCONFIG;
+#endif /* AI_ADDRCONFIG */
 		rc = getaddrinfo(dns_params.hostname, servname, &hints, &res);
 		write_to_parent(child_out, &rc, sizeof(rc));
 		if (rc != 0) {
@@ -325,7 +332,7 @@
 		return;
 	already_done = TRUE;
 	ppid = getppid();
-	snprintf(s, sizeof(s), "/proc/%d/exe", ppid);
+	g_snprintf(s, sizeof(s), "/proc/%d/exe", ppid);
 	n = readlink(s, e, sizeof(e));
 	if(n < 0)
 		return;
@@ -568,8 +575,10 @@
 		g_snprintf(message, sizeof(message), _("Error resolving %s: %d"),
 				query_data->hostname, err);
 #endif
+		/* Re-read resolv.conf and friends in case DNS servers have changed */
+		res_init();
+
 		purple_dnsquery_failed(query_data, message);
-
 	} else if (rc > 0) {
 		/* Success! */
 		while (rc > 0) {
@@ -706,6 +715,9 @@
 	 * library.
 	 */
 	hints.ai_socktype = SOCK_STREAM;
+#ifdef AI_ADDRCONFIG
+	hints.ai_flags |= AI_ADDRCONFIG;
+#endif /* AI_ADDRCONFIG */
 	if ((rc = getaddrinfo(query_data->hostname, servname, &hints, &res)) == 0) {
 		tmp = res;
 		while(res) {