summaryrefslogtreecommitdiff
path: root/package/supl/patches/patch-src_supl_c
blob: 26ab45b185ec5e53424649d9e508ca981aa9b163 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
	- implement bind to device functionality
--- trunk.orig/src/supl.c	2011-10-27 20:41:19.000000000 +0200
+++ trunk/src/supl.c	2013-04-24 18:56:17.742529773 +0200
@@ -41,7 +41,7 @@ static struct supl_debug_s {
 } debug;
 #endif
 
-static int server_connect(char *server);
+static int server_connect(char *server, char *iface);
 static int pdu_make_ulp_start(supl_ctx_t *ctx, supl_ulp_t *pdu);
 static int pdu_make_ulp_pos_init(supl_ctx_t *ctx, supl_ulp_t *pdu);
 static int pdu_make_ulp_rrlp_ack(supl_ctx_t *ctx, supl_ulp_t *pdu, PDU_t *rrlp);
@@ -236,7 +236,7 @@ int EXPORT supl_server_connect(supl_ctx_
   if (!ctx->ssl) return E_SUPL_CONNECT;
 
   if (server) {
-    ctx->fd = server_connect(server);
+    ctx->fd = server_connect(server, ctx->iface);
     if (ctx->fd == -1) return E_SUPL_CONNECT;
   }
 
@@ -266,7 +266,7 @@ void EXPORT supl_close(supl_ctx_t *ctx)
 }
 
 
-static int server_connect(char *server) {
+static int server_connect(char *server, char *iface) {
   int fd = -1;
   struct addrinfo *ailist, *aip;
   struct addrinfo hint;
@@ -283,6 +283,15 @@ static int server_connect(char *server)
     if ((fd = socket(aip->ai_family, SOCK_STREAM, 0)) < 0) {
       err = errno;
     }
+
+    if (strlen(iface)) {
+      struct ifreq ifr;
+      strncpy(ifr.ifr_name, iface, IFNAMSIZ);
+      ifr.ifr_name[IFNAMSIZ - 1] = 0;
+      if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr)))
+	      fprintf(stderr, "Error: binding to device %s failed\n", iface);
+    }
+
     if (connect(fd, aip->ai_addr, aip->ai_addrlen) != 0) {
       return -1;
     }