summaryrefslogtreecommitdiff
path: root/gweb
diff options
context:
space:
mode:
authorTomasz Bursztyka <tomasz.bursztyka@linux.intel.com>2011-07-04 14:34:56 +0300
committerSamuel Ortiz <sameo@linux.intel.com>2011-07-06 17:54:47 +0200
commit37bc8c858415df26772f6123a9a2f8b2827dd3d5 (patch)
tree8a97a42ccd9ee6493e0c7d5df4b73b1affcffc74 /gweb
parent725d7ab070ad314bedb704b64f87ea28d0e64d70 (diff)
downloadconnman-37bc8c858415df26772f6123a9a2f8b2827dd3d5.tar.gz
connman-37bc8c858415df26772f6123a9a2f8b2827dd3d5.tar.bz2
connman-37bc8c858415df26772f6123a9a2f8b2827dd3d5.zip
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.
Diffstat (limited to 'gweb')
-rw-r--r--gweb/gresolv.c41
-rw-r--r--gweb/gresolv.h2
2 files changed, 35 insertions, 8 deletions
diff --git a/gweb/gresolv.c b/gweb/gresolv.c
index a334d844..d857e01d 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 1bcaf44a..fa6a55e3 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