[tor-commits] [tor/master] Conform to the type signature of setsockopt(2)

nickm at torproject.org nickm at torproject.org
Thu Dec 17 13:36:38 UTC 2015


commit 2d2312d98986d65af47d35a89e176b5cf9953533
Author: cypherpunks <cypherpunks at torproject.org>
Date:   Wed Dec 16 22:53:19 2015 +0100

    Conform to the type signature of setsockopt(2)
    
    According to the POSIX standard the option value is a pointer to void
    and the option length a socklen_t. The Windows implementation makes the
    option value be a pointer to character and the option length an int.
    
    Casting the option value to a pointer to void conforms to the POSIX
    standard while the implicit cast to a pointer to character conforms to
    the Windows implementation.
    
    The casts of the option length to the socklen_t data type conforms to
    the POSIX standard. The socklen_t data type is actually an alias of an
    int so it also conforms to the Windows implementation.
---
 src/or/connection.c       |    5 +++--
 src/or/main.c             |    6 ++++--
 src/test/test_switch_id.c |    3 ++-
 3 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/or/connection.c b/src/or/connection.c
index b4cd4cd..be59a2c 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -1139,7 +1139,8 @@ connection_listener_new(const struct sockaddr *listensockaddr,
     if (options->TransProxyType_parsed == TPT_TPROXY &&
         type == CONN_TYPE_AP_TRANS_LISTENER) {
       int one = 1;
-      if (setsockopt(s, SOL_IP, IP_TRANSPARENT, &one, sizeof(one)) < 0) {
+      if (setsockopt(s, SOL_IP, IP_TRANSPARENT, (void*)&one,
+                     (socklen_t)sizeof(one)) < 0) {
         const char *extra = "";
         int e = tor_socket_errno(s);
         if (e == EPERM)
@@ -1162,7 +1163,7 @@ connection_listener_new(const struct sockaddr *listensockaddr,
       /* We need to set IPV6_V6ONLY so that this socket can't get used for
        * IPv4 connections. */
       if (setsockopt(s,IPPROTO_IPV6, IPV6_V6ONLY,
-                     (void*)&one, sizeof(one)) < 0) {
+                     (void*)&one, (socklen_t)sizeof(one)) < 0) {
         int e = tor_socket_errno(s);
         log_warn(LD_NET, "Error setting IPV6_V6ONLY flag: %s",
                  tor_socket_strerror(e));
diff --git a/src/or/main.c b/src/or/main.c
index 455cba4..5c65d46 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -225,11 +225,13 @@ set_buffer_lengths_to_zero(tor_socket_t s)
 {
   int zero = 0;
   int r = 0;
-  if (setsockopt(s, SOL_SOCKET, SO_SNDBUF, (void*)&zero, sizeof(zero))) {
+  if (setsockopt(s, SOL_SOCKET, SO_SNDBUF, (void*)&zero,
+                 (socklen_t)sizeof(zero))) {
     log_warn(LD_NET, "Unable to clear SO_SNDBUF");
     r = -1;
   }
-  if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, (void*)&zero, sizeof(zero))) {
+  if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, (void*)&zero,
+                 (socklen_t)sizeof(zero))) {
     log_warn(LD_NET, "Unable to clear SO_RCVBUF");
     r = -1;
   }
diff --git a/src/test/test_switch_id.c b/src/test/test_switch_id.c
index 9b09367..a47858a 100644
--- a/src/test/test_switch_id.c
+++ b/src/test/test_switch_id.c
@@ -47,7 +47,8 @@ check_can_bind_low_ports(void)
     }
 
     int one = 1;
-    if (setsockopt(fd, SOL_SOCKET,SO_REUSEADDR, &one, sizeof(one))) {
+    if (setsockopt(fd, SOL_SOCKET,SO_REUSEADDR, (void*)&one,
+                   (socklen_t)sizeof(one))) {
       perror("setsockopt");
       tor_close_socket_simple(fd);
       return -1;





More information about the tor-commits mailing list