ORBit2 r2098 - in trunk/linc2: . src



Author: tml
Date: Thu Oct  2 13:02:24 2008
New Revision: 2098
URL: http://svn.gnome.org/viewvc/ORBit2?rev=2098&view=rev

Log:
2008-10-02  Tor Lillqvist  <tml novell com>

	* src/linc-protocols.c (link_protocol_is_local_ipv46): Do simple
	checks for loopback addresses first before doing any
	gethostbyname(). Avoids superfluous potential DNS 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	Thu Oct  2 13:02:24 2008
@@ -468,6 +468,33 @@
 #endif
 	return FALSE;
 #else   /*HAVE_GETADDRINFO*/	
+
+	/* Do simple check for INADDR_LOOPBACK first */
+	if (saddr->sa_family == AF_INET &&
+	    ((struct sockaddr_in *)saddr)->sin_addr.s_addr == htonl (INADDR_LOOPBACK)) {
+#ifdef LOCAL_DEBUG
+		/* I don't understand why g_warning() is used here,
+		 * but as the existing code does this if LOCAL_DEBUG
+		 * is defined and we are going to return TRUE, keep
+		 * doing it like that then... Not that I know if
+		 * anybody is using the LOCAL_DEBUG possibility?
+		 */
+		g_warning ("local ipv4 address");
+#endif
+		return TRUE;
+	}
+
+#ifdef AF_INET6
+	/* Then simple check for IPv6 loopback address */
+	if (saddr->sa_family == AF_INET6 &&
+	    IN6_IS_ADDR_LOOPBACK (saddr)) {
+#ifdef LOCAL_DEBUG
+		g_warning ("local ipv6 address");
+#endif
+		return TRUE;
+	}
+#endif
+
 	if (!local_hostent) {
 		LINK_RESOLV_SET_IPV6;
                 d_printf("%s:%s:%d:gethostbyname(%s)\n", __FILE__, __FUNCTION__, __LINE__, link_get_local_hostname ());



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