Index: libgnomevfs/gnome-vfs-dns-sd.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-dns-sd.c,v
retrieving revision 1.19
diff -u -r1.19 gnome-vfs-dns-sd.c
--- libgnomevfs/gnome-vfs-dns-sd.c	27 Feb 2006 10:32:22 -0000	1.19
+++ libgnomevfs/gnome-vfs-dns-sd.c	11 May 2006 15:13:11 -0000
@@ -31,6 +31,7 @@
 #include <netinet/in.h>
 #include <arpa/nameser.h>
 #include <resolv.h>
+#include <netdb.h>
 #include <string.h>
 #include "gnome-vfs-dns-sd.h"
 #include <gconf/gconf-client.h>
@@ -1324,7 +1325,6 @@
 	GHashTable *hash;
 	size_t text_len;
 	char *text;
-	char host[128];
 
 	handle = user_data;
 	if (event == AVAHI_RESOLVER_FOUND) {
@@ -1337,12 +1337,25 @@
 		service.name = (char *)name;
 		service.type = (char *)type;
 		service.domain = (char *)domain;
-		
-		avahi_address_snprint (host, sizeof(host), address);
+
+		/* FIXME: Optimize? maybe add nss_support and can_resolve_local
+		 * variables to a struct that gets passed around */
+		/* avahi_nss_support only checks that the mdns modules exist,
+		 * not if they are loaded into the resolver or can resolve
+		 * local names so only return the hostname if it does resolve
+		 * with gethostbyname */
+		if (avahi_nss_support() && gethostbyname(host_name)) {
+			handle->host = g_strdup(host_name);
+		} else {
+			char a[128];
+			avahi_address_snprint(a, sizeof(a), address);
+			handle->host = g_strdup(a);
+		}
+
 		handle->callback (handle,
 				  GNOME_VFS_OK,
 				  &service,
-				  host,
+				  handle->host,
 				  port,
 				  hash,
 				  handle->text_len,
@@ -1993,13 +2006,17 @@
 			     void *user_data)
 {
 	struct sync_resolve_data *data;
-	char a[128];
 
 	data = user_data;
 	if (event == AVAHI_RESOLVER_FOUND) {
+		if (avahi_nss_support() && gethostbyname(host_name)) {
+			data->host = g_strdup(host_name);
+		} else {
+			char a[128];
+			avahi_address_snprint(a, sizeof(a), address);
+			data->host = g_strdup(a);
+		}
 		data->got_data = TRUE;
-		avahi_address_snprint (a, sizeof(a), address);
-		data->host = g_strdup (a);
 		data->port = port;
 		data->text_len = avahi_string_list_serialize (txt, NULL, 0);
 		data->text = g_malloc (data->text_len);
