From: Tomasz Bursztyka Date: Fri, 25 Nov 2011 11:03:02 +0000 (+0200) Subject: gresolv: Bind socket to the right interface X-Git-Tag: 2.0_alpha~904 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=16772e3e82c641949c5016c2cc74705524c31e61;p=framework%2Fconnectivity%2Fconnman.git gresolv: Bind socket to the right interface --- diff --git a/gweb/gresolv.c b/gweb/gresolv.c index 6bfc20a..7c4c0bc 100644 --- a/gweb/gresolv.c +++ b/gweb/gresolv.c @@ -34,6 +34,7 @@ #include #include #include +#include #include "gresolv.h" @@ -760,6 +761,26 @@ static int connect_udp_channel(struct resolv_nameserver *nameserver) return -EIO; } + /* + * If nameserver points to localhost ip, their is no need to + * bind the socket on any interface. + */ + if (nameserver->resolv->index > 0 && + strncmp(nameserver->address, "127.0.0.1", 9) != 0) { + char interface[IF_NAMESIZE]; + + memset(interface, 0, IF_NAMESIZE); + if (if_indextoname(nameserver->resolv->index, + interface) != NULL) { + if (setsockopt(sk, SOL_SOCKET, SO_BINDTODEVICE, + interface, IF_NAMESIZE) < 0) { + close(sk); + freeaddrinfo(rp); + return -EIO; + } + } + } + if (connect(sk, rp->ai_addr, rp->ai_addrlen) < 0) { close(sk); freeaddrinfo(rp); @@ -879,14 +900,13 @@ gboolean g_resolv_add_nameserver(GResolv *resolv, const char *address, nameserver->address = g_strdup(address); nameserver->port = port; nameserver->flags = flags; + nameserver->resolv = resolv; if (connect_udp_channel(nameserver) < 0) { free_nameserver(nameserver); return FALSE; } - nameserver->resolv = resolv; - resolv->nameserver_list = g_list_append(resolv->nameserver_list, nameserver);