--- gweb/gresolv.c | 26 ++++++++++++++++++++++++++ gweb/gresolv.h | 2 ++ 2 files changed, 28 insertions(+), 0 deletions(-)
diff --git a/gweb/gresolv.c b/gweb/gresolv.c index a334d84..42a3757 100644 --- a/gweb/gresolv.c +++ b/gweb/gresolv.c @@ -62,6 +62,8 @@ struct resolv_lookup { GResolv *resolv; guint id; + int result_af; + int nr_results; struct sort_result *results; @@ -99,6 +101,8 @@ struct resolv_nameserver { struct _GResolv { gint ref_count; + int result_af; + guint next_lookup_id; GQueue *lookup_queue; GQueue *query_queue; @@ -463,11 +467,17 @@ static void sort_and_return_results(struct resolv_lookup *lookup) for (i = 0; i < lookup->nr_results; i++) { if (lookup->results[i].dst.sa.sa_family == AF_INET) { + if (lookup->result_af == AF_INET6) + continue; + if (inet_ntop(AF_INET, &lookup->results[i].dst.sin.sin_addr, buf, sizeof(buf)) == NULL) continue; } else if (lookup->results[i].dst.sa.sa_family == AF_INET6) { + if (lookup->result_af == AF_INET) + continue; + if (inet_ntop(AF_INET6, &lookup->results[i].dst.sin6.sin6_addr, buf, sizeof(buf)) == NULL) @@ -791,6 +801,8 @@ GResolv *g_resolv_new(int index) resolv->ref_count = 1; + resolv->result_af = AF_UNSPEC; + resolv->next_lookup_id = 1; resolv->query_queue = g_queue_new(); @@ -973,6 +985,7 @@ guint g_resolv_lookup_hostname(GResolv *resolv, const char *hostname, lookup->result_func = func; lookup->result_data = user_data; lookup->id = resolv->next_lookup_id++; + lookup->result_af = resolv->result_af; if (add_query(lookup, hostname, ns_t_a)) { g_free(lookup); @@ -1005,3 +1018,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_af = 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 -- 1.7.3.4 _______________________________________________ connman mailing list connman@connman.net http://lists.connman.net/listinfo/connman