make --address work for a client connecting to a server
authorAndrew Tridgell <tridge@samba.org>
Mon, 10 Jan 2000 04:49:51 +0000 (04:49 +0000)
committerAndrew Tridgell <tridge@samba.org>
Mon, 10 Jan 2000 04:49:51 +0000 (04:49 +0000)
clientserver.c
rsync.c
rsync.yo
socket.c

index 5f03226..bb367b0 100644 (file)
@@ -36,6 +36,7 @@ int start_socket_client(char *host, char *path, int argc, char *argv[])
        char *p, *user=NULL;
        extern int remote_version;
        extern int am_sender;
+       extern struct in_addr socket_address;
 
        if (*path == '/') {
                rprintf(FERROR,"ERROR: The remote path must start with a module name\n");
@@ -52,7 +53,7 @@ int start_socket_client(char *host, char *path, int argc, char *argv[])
        if (!user) user = getenv("USER");
        if (!user) user = getenv("LOGNAME");
 
-       fd = open_socket_out(host, rsync_port);
+       fd = open_socket_out(host, rsync_port, &socket_address);
        if (fd == -1) {
                exit_cleanup(RERR_SOCKETIO);
        }
diff --git a/rsync.c b/rsync.c
index 2d267a0..a2b432a 100644 (file)
--- a/rsync.c
+++ b/rsync.c
@@ -152,7 +152,6 @@ int set_perms(char *fname,struct file_struct *file,STRUCT_STAT *st,
        int updated = 0;
        STRUCT_STAT st2;
        int change_uid, change_gid;
-       extern int am_daemon;
 
        if (dry_run) return 0;
 
index db36c69..9007cd0 100644 (file)
--- a/rsync.yo
+++ b/rsync.yo
@@ -596,10 +596,10 @@ respond to requests accordingly. See the rsyncd.conf(5) man page for more
 details. 
 
 dit(bf(--address)) By default rsync will bind to the wildcard address
-when run as a daemon with the --daemon option. The --address option
-allows you to specify a specific IP address (or hostname) to bind
-to. This makes virtual hosting possible in conjunction with the
---config option.
+when run as a daemon with the --daemon option or when connecting to a
+rsync server. The --address option allows you to specify a specific IP
+address (or hostname) to bind to. This makes virtual hosting possible
+in conjunction with the --config option.
 
 dit(bf(--config=FILE)) This specifies an alternate config file than
 the default /etc/rsyncd.conf. This is only relevant when --daemon is
index 9c86c49..9a61951 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -89,10 +89,11 @@ static int establish_proxy_connection(int fd, char *host, int port)
 /* open a socket to a tcp remote host with the specified port 
    based on code from Warren
    proxy support by Stephen Rothwell */
-int open_socket_out(char *host, int port)
+int open_socket_out(char *host, int port, struct in_addr *address)
 {
        int type = SOCK_STREAM;
        struct sockaddr_in sock_out;
+       struct sockaddr_in sock;
        int res;
        struct hostent *hp;
        char *h;
@@ -137,6 +138,13 @@ int open_socket_out(char *host, int port)
        sock_out.sin_port = htons(p);
        sock_out.sin_family = PF_INET;
 
+       if (address) {
+               sock.sin_addr = *address;
+               sock.sin_port = 0;
+               sock.sin_family = hp->h_addrtype;
+               bind(res, (struct sockaddr * ) &sock,sizeof(sock));
+       }
+
        if (connect(res,(struct sockaddr *)&sock_out,sizeof(sock_out))) {
                rprintf(FERROR,"failed to connect to %s - %s\n", h, strerror(errno));
                close(res);