Try to fix ctype issues by always calling these functions as
[rsync/rsync.git] / socket.c
index c4420ba..bb7acc0 100644 (file)
--- a/socket.c
+++ b/socket.c
 #include "rsync.h"
 
 
-/* Establish a proxy connection on an open socket to a web roxy by
- * using the CONNECT method. */
+/**
+ * Establish a proxy connection on an open socket to a web proxy by
+ * using the HTTP CONNECT method.
+ **/
 static int establish_proxy_connection(int fd, char *host, int port)
 {
        char buffer[1024];
@@ -68,7 +70,7 @@ static int establish_proxy_connection(int fd, char *host, int port)
                        buffer);
                return -1;
        }
-       for (cp = &buffer[5]; isdigit(*cp) || (*cp == '.'); cp++)
+       for (cp = &buffer[5]; isdigit(* (unsigned char *) cp) || (*cp == '.'); cp++)
                ;
        while (*cp == ' ')
                cp++;
@@ -122,12 +124,14 @@ int try_bind_local(int s,
        for (r = bres_all; r; r = r->ai_next) {
                if (bind(s, r->ai_addr, r->ai_addrlen) == -1)
                        continue;
+               freeaddrinfo(bres_all);
                return s;
        }
 
        /* no error message; there might be some problem that allows
         * creation of the socket but not binding, perhaps if the
         * machine has no ipv6 address of this name. */
+       freeaddrinfo(bres_all);
        return -1;
 }
 
@@ -182,6 +186,10 @@ int open_socket_out(char *host, int port, const char *bind_address,
                *cp++ = '\0';
                strcpy(portbuf, cp);
                h = buffer;
+               if (verbose >= 2) {
+                       rprintf(FINFO, "connection via http proxy %s port %s\n",
+                               h, portbuf);
+               }
        } else {
                snprintf(portbuf, sizeof(portbuf), "%d", port);
                h = host;
@@ -325,7 +333,8 @@ static int open_socket_in(int type, int port, const char *bind_address,
                        close(s);
                        continue;
                }
-               
+
+               freeaddrinfo(all_ai);
                return s;
        }
 
@@ -436,6 +445,7 @@ void start_accept_loop(int port, int (*fn)(int ))
                         * accept again. */
                        sleep(2);
                } else {
+                       /* Parent doesn't need this fd anymore. */
                        close(fd);
                }
        }
@@ -486,9 +496,9 @@ struct
 
        
 
-/****************************************************************************
-set user socket options
-****************************************************************************/
+/**
+ * Set user socket options
+ **/
 void set_socket_options(int fd, char *options)
 {
        char *tok;
@@ -546,9 +556,9 @@ void set_socket_options(int fd, char *options)
        free(options);
 }
 
-/****************************************************************************
-become a daemon, discarding the controlling terminal
-****************************************************************************/
+/**
+ * Become a daemon, discarding the controlling terminal
+ **/
 void become_daemon(void)
 {
        int i;
@@ -578,14 +588,15 @@ void become_daemon(void)
 }
 
 
-/*******************************************************************
-this is like socketpair but uses tcp. It is used by the Samba
-regression test code
-The function guarantees that nobody else can attach to the socket,
-or if they do that this function fails and the socket gets closed
-returns 0 on success, -1 on failure
-the resulting file descriptors are symmetrical
- ******************************************************************/
+/**
+ * This is like socketpair but uses tcp. It is used by the Samba
+ * regression test code.
+ * 
+ * The function guarantees that nobody else can attach to the socket,
+ * or if they do that this function fails and the socket gets closed
+ * returns 0 on success, -1 on failure the resulting file descriptors
+ * are symmetrical.
+ **/
 static int socketpair_tcp(int fd[2])
 {
        int listener;