From: Tomasz Bursztyka Date: Mon, 4 Jul 2011 11:34:56 +0000 (+0300) Subject: gresolv: Queries address family scope restriction X-Git-Tag: 2.0_alpha~1345 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=37bc8c858415df26772f6123a9a2f8b2827dd3d5;p=framework%2Fconnectivity%2Fconnman.git gresolv: Queries address family scope restriction Adding the capability to restrict DNS queries to a specific address family through gresolv_set_address_family(). By default, AF_UNSPEC is applied. --- diff --git a/gweb/gresolv.c b/gweb/gresolv.c index a334d84..d857e01 100644 --- a/gweb/gresolv.c +++ b/gweb/gresolv.c @@ -99,6 +99,8 @@ struct resolv_nameserver { struct _GResolv { gint ref_count; + int result_family; + guint next_lookup_id; GQueue *lookup_queue; GQueue *query_queue; @@ -791,6 +793,8 @@ GResolv *g_resolv_new(int index) resolv->ref_count = 1; + resolv->result_family = AF_UNSPEC; + resolv->next_lookup_id = 1; resolv->query_queue = g_queue_new(); @@ -974,16 +978,24 @@ guint g_resolv_lookup_hostname(GResolv *resolv, const char *hostname, lookup->result_data = user_data; lookup->id = resolv->next_lookup_id++; - if (add_query(lookup, hostname, ns_t_a)) { - g_free(lookup); - return -EIO; + if (resolv->result_family != AF_INET6) { + if (add_query(lookup, hostname, ns_t_a)) { + g_free(lookup); + return -EIO; + } } - if (add_query(lookup, hostname, ns_t_aaaa)) { - destroy_query(lookup->ipv4_query); - g_queue_remove(resolv->query_queue, lookup->ipv4_query); - g_free(lookup); - return -EIO; + if (resolv->result_family != AF_INET) { + if (add_query(lookup, hostname, ns_t_aaaa)) { + if (resolv->result_family != AF_INET6) { + destroy_query(lookup->ipv4_query); + g_queue_remove(resolv->query_queue, + lookup->ipv4_query); + } + + g_free(lookup); + return -EIO; + } } g_queue_push_tail(resolv->lookup_queue, lookup); @@ -1005,3 +1017,16 @@ gboolean g_resolv_cancel_lookup(GResolv *resolv, guint id) return TRUE; } + +gboolean g_resolv_set_address_family(GResolv *resolv, int family) +{ + if (resolv == NULL) + return FALSE; + + if (family != AF_UNSPEC && family != AF_INET && family != AF_INET6) + return FALSE; + + resolv->result_family = family; + + return TRUE; +} diff --git a/gweb/gresolv.h b/gweb/gresolv.h index 1bcaf44..fa6a55e 100644 --- a/gweb/gresolv.h +++ b/gweb/gresolv.h @@ -67,6 +67,8 @@ guint g_resolv_lookup_hostname(GResolv *resolv, const char *hostname, gboolean g_resolv_cancel_lookup(GResolv *resolv, guint id); +gboolean g_resolv_set_address_family(GResolv *resolv, int family); + #ifdef __cplusplus } #endif