From 4d6fdeeb29d9c78ce99f54c6f7d01e6177706cad Mon Sep 17 00:00:00 2001 From: Tomasz Bursztyka Date: Wed, 22 Jun 2011 09:28:54 +0300 Subject: [PATCH] gweb: added the capability to restrict the requests to a specific address family. --- gweb/gweb.c | 19 +++++++++++++++++++ gweb/gweb.h | 2 ++ 2 files changed, 21 insertions(+) diff --git a/gweb/gweb.c b/gweb/gweb.c index 1183cc6..536de00 100644 --- a/gweb/gweb.c +++ b/gweb/gweb.c @@ -101,6 +101,8 @@ struct _GWeb { guint next_query_id; + int family; + int index; GList *session_list; @@ -203,6 +205,8 @@ GWeb *g_web_new(int index) web->next_query_id = 1; + web->family = AF_UNSPEC; + web->index = index; web->session_list = NULL; @@ -280,6 +284,19 @@ gboolean g_web_set_proxy(GWeb *web, const char *proxy) return TRUE; } +gboolean g_web_set_address_family(GWeb *web, int family) +{ + if (web == NULL) + return FALSE; + + if (family != AF_UNSPEC && family != AF_INET && family != AF_INET6) + return FALSE; + + web->family = family; + + return TRUE; +} + gboolean g_web_add_nameserver(GWeb *web, const char *address) { if (web == NULL) @@ -1059,6 +1076,7 @@ static void resolv_result(GResolvResultStatus status, memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_flags = AI_NUMERICHOST; + hints.ai_family = session->web->family; if (session->addr != NULL) { freeaddrinfo(session->addr); @@ -1155,6 +1173,7 @@ static guint do_request(GWeb *web, const char *url, memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_flags = AI_NUMERICHOST; + hints.ai_family = session->web->family; if (session->addr != NULL) { freeaddrinfo(session->addr); diff --git a/gweb/gweb.h b/gweb/gweb.h index 3a76778..cfeceb6 100644 --- a/gweb/gweb.h +++ b/gweb/gweb.h @@ -54,6 +54,8 @@ void g_web_set_debug(GWeb *web, GWebDebugFunc func, gpointer user_data); gboolean g_web_set_proxy(GWeb *web, const char *proxy); +gboolean g_web_set_address_family(GWeb *web, int family); + gboolean g_web_add_nameserver(GWeb *web, const char *address); gboolean g_web_set_accept(GWeb *web, const char *format, ...) -- 2.7.4