]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-common: Don't modify a const argument
authorMartin Schwenke <martin@meltin.net>
Fri, 17 Aug 2018 03:46:50 +0000 (13:46 +1000)
committerAmitay Isaacs <amitay@samba.org>
Thu, 30 Aug 2018 02:48:58 +0000 (04:48 +0200)
The current code might be slightly more efficient but
intentionally (although temporarily) modifying a const argument just
seems wrong.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/common/system_socket.c

index 41037ce1ec62e1147ee5b1962b712e0df90ee021..4617be48bd724a4fbc1acc38089f1df83ff3e94e 100644 (file)
@@ -631,8 +631,7 @@ int ctdb_sys_send_tcp(const ctdb_sock_addr *dest,
        int ret;
        int s;
        uint32_t one = 1;
-       uint16_t tmpport;
-       ctdb_sock_addr *tmpdest;
+       struct sockaddr_in6 tmpdest = { 0 };
        int saved_errno;
 
        switch (src->ip.sin_family) {
@@ -700,21 +699,20 @@ int ctdb_sys_send_tcp(const ctdb_sock_addr *dest,
                        return -1;
 
                }
-               /* sendto() don't like if the port is set and the socket is
-                  in raw mode.
-               */
-               tmpdest = discard_const(dest);
-               tmpport = tmpdest->ip6.sin6_port;
+               /*
+                * sendto() on an IPv6 raw socket requires the port to
+                * be either 0 or a protocol value
+                */
+               tmpdest = dest->ip6;
+               tmpdest.sin6_port = 0;
 
-               tmpdest->ip6.sin6_port = 0;
                ret = sendto(s,
                             buf,
                             len,
                             0,
-                            (const struct sockaddr *)&dest->ip6,
-                            sizeof(dest->ip6));
+                            (const struct sockaddr *)&tmpdest,
+                            sizeof(tmpdest));
                saved_errno = errno;
-               tmpdest->ip6.sin6_port = tmpport;
                close(s);
 
                if (ret != len) {