summaryrefslogtreecommitdiff
path: root/gweb
diff options
context:
space:
mode:
authorTomasz Bursztyka <tomasz.bursztyka@linux.intel.com>2011-11-25 13:03:02 +0200
committerSamuel Ortiz <sameo@linux.intel.com>2011-11-28 15:55:09 +0100
commit16772e3e82c641949c5016c2cc74705524c31e61 (patch)
treeabb42a7a81abfe5e64566bcc42ed9c07280e9736 /gweb
parent53f59e21154d6082a1ee1864a9dab86b5ef7f4ab (diff)
downloadconnman-16772e3e82c641949c5016c2cc74705524c31e61.tar.gz
connman-16772e3e82c641949c5016c2cc74705524c31e61.tar.bz2
connman-16772e3e82c641949c5016c2cc74705524c31e61.zip
gresolv: Bind socket to the right interface
Diffstat (limited to 'gweb')
-rw-r--r--gweb/gresolv.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/gweb/gresolv.c b/gweb/gresolv.c
index 6bfc20a4..7c4c0bcf 100644
--- a/gweb/gresolv.c
+++ b/gweb/gresolv.c
@@ -34,6 +34,7 @@
#include <netdb.h>
#include <arpa/inet.h>
#include <arpa/nameser.h>
+#include <net/if.h>
#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);