diff libpurple/protocols/bonjour/jabber.c @ 32369:d6cc1ff0d9b7

Append interface ID only to local interfaces for IPv6 Bonjour. This should fix unsuccessful connection attempts both for two IPv6 hosts with a non-link-local address next to the link-local one or without. committer: Ethan Blanton <elb@pidgin.im>
author linus.luessing@web.de
date Wed, 30 Nov 2011 00:58:50 +0000
parents e1d31abb245c
children 0734b9c8c345 c0c60e110c82
line wrap: on
line diff
--- a/libpurple/protocols/bonjour/jabber.c	Tue Nov 29 03:58:50 2011 +0000
+++ b/libpurple/protocols/bonjour/jabber.c	Wed Nov 30 00:58:50 2011 +0000
@@ -665,9 +665,13 @@
 
 	/* Look for the buddy that has opened the conversation and fill information */
 #ifdef HAVE_INET_NTOP
-	if (their_addr.ss_family == AF_INET6)
+	if (their_addr.ss_family == AF_INET6) {
 		address_text = inet_ntop(their_addr.ss_family, &((struct sockaddr_in6 *)&their_addr)->sin6_addr,
 			addrstr, sizeof(addrstr));
+
+		append_iface_if_linklocal(addrstr,
+			((struct sockaddr_in6 *)&their_addr)->sin6_scope_id);
+	}
 	else
 		address_text = inet_ntop(their_addr.ss_family, &((struct sockaddr_in *)&their_addr)->sin_addr,
 			addrstr, sizeof(addrstr));
@@ -1442,3 +1446,19 @@
 
 	return ips;
 }
+
+void
+append_iface_if_linklocal(char *ip, uint32_t interface) {
+	struct in6_addr in6_addr;
+	int len_remain = INET6_ADDRSTRLEN - strlen(ip);
+
+	if (len_remain <= 1)
+		return;
+
+	if (inet_pton(AF_INET6, ip, &in6_addr) != 1 ||
+	    !IN6_IS_ADDR_LINKLOCAL(&in6_addr))
+		return;
+
+	snprintf(ip + strlen(ip), len_remain, "%%%d",
+		 interface);
+}