comparison libpurple/dnsquery.c @ 32310:142429bcb4c8

propagate from branch 'im.pidgin.pidgin' (head bb53d1e9201138b79a1eef0d4a7cda1fc852c59f) to branch 'im.pidgin.pidgin.next.major' (head 85a38af15472bf17064bbe597f94f32ad167c4e6)
author Mark Doliner <mark@kingant.net>
date Sun, 07 Aug 2011 05:19:54 +0000
parents 8dbe2f531a89
children d3d41ba0c3b8
comparison
equal deleted inserted replaced
32309:a3b1dcf433b5 32310:142429bcb4c8
152 } 152 }
153 153
154 static gboolean 154 static gboolean
155 resolve_ip(PurpleDnsQueryData *query_data) 155 resolve_ip(PurpleDnsQueryData *query_data)
156 { 156 {
157 #if defined(HAVE_GETADDRINFO) && defined(AI_NUMERICHOST)
158 struct addrinfo hints, *res;
159 char servname[20];
160
161 g_snprintf(servname, sizeof(servname), "%d", query_data->port);
162 memset(&hints, 0, sizeof(hints));
163 hints.ai_family = AF_UNSPEC;
164 hints.ai_flags |= AI_NUMERICHOST;
165
166 if (0 == getaddrinfo(query_data->hostname, servname, &hints, &res))
167 {
168 GSList *hosts = NULL;
169 hosts = g_slist_append(hosts, GINT_TO_POINTER(res->ai_addrlen));
170 hosts = g_slist_append(hosts, g_memdup(res->ai_addr, res->ai_addrlen));
171 purple_dnsquery_resolved(query_data, hosts);
172
173 freeaddrinfo(res);
174 return TRUE;
175 }
176 #else /* defined(HAVE_GETADDRINFO) && defined(AI_NUMERICHOST) */
157 struct sockaddr_in sin; 177 struct sockaddr_in sin;
158 /* TODO: Use inet_pton for IPv6 support */
159 if (inet_aton(query_data->hostname, &sin.sin_addr)) 178 if (inet_aton(query_data->hostname, &sin.sin_addr))
160 { 179 {
161 /* 180 /*
162 * The given "hostname" is actually an IP address, so we 181 * The given "hostname" is actually an IP address, so we
163 * don't need to do anything. 182 * don't need to do anything.
169 hosts = g_slist_append(hosts, g_memdup(&sin, sizeof(sin))); 188 hosts = g_slist_append(hosts, g_memdup(&sin, sizeof(sin)));
170 purple_dnsquery_resolved(query_data, hosts); 189 purple_dnsquery_resolved(query_data, hosts);
171 190
172 return TRUE; 191 return TRUE;
173 } 192 }
193 #endif
174 194
175 return FALSE; 195 return FALSE;
176 } 196 }
177 197
178 #ifdef USE_IDN 198 #ifdef USE_IDN