patch-src_supl_c 1.5 KB

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