ORBit2 r2042 - in trunk/linc2: . src



Author: tml
Date: Mon Jan 21 22:09:24 2008
New Revision: 2042
URL: http://svn.gnome.org/viewvc/ORBit2?rev=2042&view=rev

Log:
2008-01-21  Tor Lillqvist  <tml novell com>

	Rework form of addresses used on Windows. Seems to fix the
	problems reported in bug #363648. See that bug for extensive even
	if occasionally misleading discussion.

	* src/linc-protocols.c [Win32]: Change the default value of the
	use_local_host variable to LINK_NET_ID_IS_IPADDR. This seems to in
	general be more useful than FQDNs especially for end-user machines
	with DNS randomness issues.

	Add some d_printf() calls to print debugging information when DNS
	lookups are being done. To see them, recompile with
	CONNECTION_DEBUG defined in src/linc-debug.h and set the
	LINK_CONNECTION_DEBUG environment variable.

	(get_netid) [Win32]: Return the numeric "127.0.0.1" in the
	LINK_NET_ID_IS_LOCAL case.

	(link_protocol_get_sockinfo_ipv4) [Win32]: always return the
	numeric IP address instead of doing any gethostbyaddr() etc
	lookups.



Modified:
   trunk/linc2/ChangeLog
   trunk/linc2/src/linc-protocols.c

Modified: trunk/linc2/src/linc-protocols.c
==============================================================================
--- trunk/linc2/src/linc-protocols.c	(original)
+++ trunk/linc2/src/linc-protocols.c	Mon Jan 21 22:09:24 2008
@@ -30,7 +30,11 @@
 #undef LOCAL_DEBUG
 
 static char *link_tmpdir = NULL;
+#ifdef G_OS_WIN32
+static LinkNetIdType use_local_host = LINK_NET_ID_IS_IPADDR;
+#else
 static LinkNetIdType use_local_host = LINK_NET_ID_IS_FQDN;
+#endif
 static const char *fixed_host_net_id = NULL;
 
 /*
@@ -146,8 +150,13 @@
 	  char *buf, 
 	  size_t len)
 {
-	if (LINK_NET_ID_IS_LOCAL == which)
+	if (LINK_NET_ID_IS_LOCAL == which) {
+#ifndef G_OS_WIN32
 		return strncpy(buf, "localhost", len);
+#else
+		return strncpy(buf, "127.0.0.1", len);
+#endif
+	}
 
 	if ((LINK_NET_ID_IS_IPADDR == which)
 	    || (LINK_NET_ID_IS_CUSTOM == which)) {
@@ -235,8 +244,10 @@
 		for (i = 0; i < nbytes / sizeof (INTERFACE_INFO); i++) {
 			if ((interfaces[i].iiFlags & IFF_UP) &&
 			    !(interfaces[i].iiFlags & IFF_LOOPBACK) &&
-			    interfaces[i].iiAddress.Address.sa_family == AF_INET)
+			    interfaces[i].iiAddress.Address.sa_family == AF_INET) {
+				d_printf("%s:%s:%d: returning %s\n", __FILE__, __FUNCTION__, __LINE__, inet_ntoa(interfaces[i].iiAddress.AddressIn.sin_addr));
 				return strncpy(buf, inet_ntoa(interfaces[i].iiAddress.AddressIn.sin_addr), len);
+			}
 		}
 
 		/* Next look for a loopback IPv4 address */
@@ -253,6 +264,7 @@
 	}
 
 	if ((LINK_NET_ID_IS_SHORT_HOSTNAME == which) || (LINK_NET_ID_IS_FQDN == which)) {
+                d_printf("%s:%s:%d:gethostname()\n", __FILE__, __FUNCTION__, __LINE__);
 		if (gethostname(buf, len))
 			goto out;
 #ifndef G_OS_WIN32
@@ -284,6 +296,7 @@
 		struct hostent *he;
 
 		/* gethostbyname() is MT-safe on Windows, btw */
+                d_printf("%s:%s:%d:gethostbyname(%s)\n", __FILE__, __FUNCTION__, __LINE__, buf);
 		he = gethostbyname(buf);
 
 		if (!he)
@@ -460,6 +473,7 @@
 #else   /*HAVE_GETADDRINFO*/	
 	if (!local_hostent) {
 		LINK_RESOLV_SET_IPV6;
+                d_printf("%s:%s:%d:gethostbyname(%s)\n", __FILE__, __FUNCTION__, __LINE__, link_get_local_hostname ());
 		local_hostent = gethostbyname (link_get_local_hostname ());
 	}
 
@@ -574,6 +588,7 @@
 			res_init();
 #endif
 		
+                d_printf("%s:%s:%d:gethostbyname(%s)\n", __FILE__, __FUNCTION__, __LINE__, hostname);
 		host = gethostbyname (hostname);
 		if (!host) {
 		  g_free (saddr);
@@ -671,6 +686,7 @@
 #endif
 
 	LINK_RESOLV_SET_IPV6;
+        d_printf("%s:%s:%d:gethostbyname(%s)\n", __FILE__, __FUNCTION__, __LINE__, hostname);
 	host = gethostbyname (hostname);
 	if (!host || host->h_addrtype != AF_INET6) {
 		g_free (saddr);
@@ -851,29 +867,15 @@
 
 	g_assert (proto && saddr && saddr->sa_family == AF_INET);
 
-	if (sa_in->sin_addr.s_addr != INADDR_ANY) {
+#ifdef G_OS_WIN32
+	hname = inet_ntoa(sa_in->sin_addr);
+#else
+	if (ntohl (sa_in->sin_addr.s_addr) != INADDR_ANY) {
 		host = gethostbyaddr ((char *)&sa_in->sin_addr, 
                                       sizeof (struct in_addr), AF_INET);
 		if (!host)
 			return FALSE;
 		hname = host->h_name;
-	}
-#ifdef G_OS_WIN32
-	/* Make sure looking up that name works */
-	if (strcmp (hname, "localhost") == 0)
-		hname = "127.0.0.1"; /* Don't take any risk */
-	else {
-		char *hname_copy = g_strdup (hname);
-		host = gethostbyname (hname_copy);
-		
-		g_free (hname_copy);
-		if (host == NULL) {
-			/* Nope, use IP address then */
-			hname = inet_ntoa (sa_in->sin_addr);
-		} else {
-			hname = host->h_name;
-		}
-	}
 #endif
 	return link_protocol_get_sockinfo_ipv46 (hname, sa_in->sin_port, 
 						 hostname, portnum);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]