From e30f065766d103b47aaccbe777308e0d2381fd6e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 10 Jan 2000 04:49:51 +0000 Subject: [PATCH] make --address work for a client connecting to a server --- clientserver.c | 3 ++- rsync.c | 1 - rsync.yo | 8 ++++---- socket.c | 10 +++++++++- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/clientserver.c b/clientserver.c index 5f03226d..bb367b01 100644 --- a/clientserver.c +++ b/clientserver.c @@ -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 2d267a0f..a2b432a2 100644 --- 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; diff --git a/rsync.yo b/rsync.yo index db36c696..9007cd0d 100644 --- 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 diff --git a/socket.c b/socket.c index 9c86c498..9a619515 100644 --- 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); -- 2.34.1