[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/release-0.2.2] Fix connect() failures in get_interface_address6()



commit 865ea5d26361802d53c586d27f249e5c2e924538
Author: Sebastian Hahn <sebastian@xxxxxxxxxxxxxx>
Date:   Sat Mar 5 14:46:32 2011 +0100

    Fix connect() failures in get_interface_address6()
    
    The third argument for connect should be dependent on the address
    family. Issue spotted by piebeer who also wrote the patch.
---
 changes/bug2660      |    3 +++
 src/common/address.c |   12 +++++-------
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/changes/bug2660 b/changes/bug2660
new file mode 100644
index 0000000..fe22956
--- /dev/null
+++ b/changes/bug2660
@@ -0,0 +1,3 @@
+  o Minor bugfixes:
+    - Fix connect() failures on some platforms (BSD, OS X). Bugfix on
+      0.2.0.3-alpha; fixes bug 2660. Patch by piebeer.
diff --git a/src/common/address.c b/src/common/address.c
index 0e57528..90beae0 100644
--- a/src/common/address.c
+++ b/src/common/address.c
@@ -1025,13 +1025,12 @@ get_interface_address6(int severity, sa_family_t family, tor_addr_t *addr)
 {
   int sock=-1, r=-1;
   struct sockaddr_storage my_addr, target_addr;
-  socklen_t my_addr_len;
+  socklen_t addr_len;
 
   tor_assert(addr);
 
   memset(addr, 0, sizeof(tor_addr_t));
   memset(&target_addr, 0, sizeof(target_addr));
-  my_addr_len = (socklen_t)sizeof(my_addr);
   /* Use the "discard" service port */
   ((struct sockaddr_in*)&target_addr)->sin_port = 9;
   /* Don't worry: no packets are sent. We just need to use a real address
@@ -1039,13 +1038,13 @@ get_interface_address6(int severity, sa_family_t family, tor_addr_t *addr)
   if (family == AF_INET6) {
     struct sockaddr_in6 *sin6 = (struct sockaddr_in6*)&target_addr;
     sock = tor_open_socket(PF_INET6,SOCK_DGRAM,IPPROTO_UDP);
-    my_addr_len = (socklen_t)sizeof(struct sockaddr_in6);
+    addr_len = (socklen_t)sizeof(struct sockaddr_in6);
     sin6->sin6_family = AF_INET6;
     S6_ADDR16(sin6->sin6_addr)[0] = htons(0x2002); /* 2002:: */
   } else if (family == AF_INET) {
     struct sockaddr_in *sin = (struct sockaddr_in*)&target_addr;
     sock = tor_open_socket(PF_INET,SOCK_DGRAM,IPPROTO_UDP);
-    my_addr_len = (socklen_t)sizeof(struct sockaddr_in);
+    addr_len = (socklen_t)sizeof(struct sockaddr_in);
     sin->sin_family = AF_INET;
     sin->sin_addr.s_addr = htonl(0x12000001); /* 18.0.0.1 */
   } else {
@@ -1058,14 +1057,13 @@ get_interface_address6(int severity, sa_family_t family, tor_addr_t *addr)
     goto err;
   }
 
-  if (connect(sock,(struct sockaddr *)&target_addr,
-              (socklen_t)sizeof(target_addr))<0) {
+  if (connect(sock,(struct sockaddr *)&target_addr, addr_len) < 0) {
     int e = tor_socket_errno(sock);
     log_fn(severity, LD_NET, "connect() failed: %s", tor_socket_strerror(e));
     goto err;
   }
 
-  if (getsockname(sock,(struct sockaddr*)&my_addr, &my_addr_len)) {
+  if (getsockname(sock,(struct sockaddr*)&my_addr, &addr_len)) {
     int e = tor_socket_errno(sock);
     log_fn(severity, LD_NET, "getsockname() to determine interface failed: %s",
            tor_socket_strerror(e));



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits