changeset 31746:8dbe2f531a89

dnsquery: Behold, automagic conversion of a string IP address into a sockaddr struct, IPv#-independent.
author Paul Aurich <paul@darkrain42.org>
date Sun, 17 Jul 2011 20:38:09 +0000
parents 451242c455ca
children 958621e23f5d
files libpurple/dnsquery.c
diffstat 1 files changed, 21 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/dnsquery.c	Sun Jul 17 20:08:13 2011 +0000
+++ b/libpurple/dnsquery.c	Sun Jul 17 20:38:09 2011 +0000
@@ -154,8 +154,27 @@
 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 @@
 
 		return TRUE;
 	}
+#endif
 
 	return FALSE;
 }