pidgin: f155ae4b: dnsquery: Behold, automagic conversion o...

darkrain42 at pidgin.im darkrain42 at pidgin.im
Sun Jul 17 16:40:42 EDT 2011


----------------------------------------------------------------------
Revision: f155ae4b4e39dfe9d9a5254dd86b603ce98d08c6
Parent:   b2ac0a617e72d6514db7f373484e3eb94ef34ad0
Author:   darkrain42 at pidgin.im
Date:     07/17/11 16:38:09
Branch:   im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/f155ae4b4e39dfe9d9a5254dd86b603ce98d08c6

Changelog: 

dnsquery: Behold, automagic conversion of a string IP address into a sockaddr struct, IPv#-independent.

Changes against parent b2ac0a617e72d6514db7f373484e3eb94ef34ad0

  patched  libpurple/dnsquery.c

-------------- next part --------------
============================================================
--- libpurple/dnsquery.c	a887e0dcb02c86d36d2710ce1487a9dac7dcc340
+++ libpurple/dnsquery.c	ec35993e4ab83e1f41e806c33efeb197196248d8
@@ -154,8 +154,27 @@ resolve_ip(PurpleDnsQueryData *query_dat
 static gboolean
 resolve_ip(PurpleDnsQueryData *query_data)
 {
+#if defined(HAVE_GETADDRINFO) && defined(AI_NUMERICHOST)
+	struct addrinfo hints, *res;
+	char servname[20];
+
+	g_snprintf(servname, sizeof(servname), "%d", query_data->port);
+	memset(&hints, 0, sizeof(hints));
+	hints.ai_family = AF_UNSPEC;
+	hints.ai_flags |= AI_NUMERICHOST;
+
+	if (0 == getaddrinfo(query_data->hostname, servname, &hints, &res))
+	{
+		GSList *hosts = NULL;
+		hosts = g_slist_append(hosts, GINT_TO_POINTER(res->ai_addrlen));
+		hosts = g_slist_append(hosts, g_memdup(res->ai_addr, res->ai_addrlen));
+		purple_dnsquery_resolved(query_data, hosts);
+
+		freeaddrinfo(res);
+		return TRUE;
+	}
+#else /* defined(HAVE_GETADDRINFO) && defined(AI_NUMERICHOST) */
 	struct sockaddr_in sin;
-	/* TODO: Use inet_pton for IPv6 support */
 	if (inet_aton(query_data->hostname, &sin.sin_addr))
 	{
 		/*
@@ -171,6 +190,7 @@ resolve_ip(PurpleDnsQueryData *query_dat
 
 		return TRUE;
 	}
+#endif
 
 	return FALSE;
 }


More information about the Commits mailing list