summaryrefslogtreecommitdiff
path: root/clientname.c
diff options
context:
space:
mode:
authorDavid Dykstra <dwd@samba.org>2002-08-02 15:05:03 +0000
committerDavid Dykstra <dwd@samba.org>2002-08-02 15:05:03 +0000
commit1e736b8ff75180a01ad26ee92696d5dde4fe2628 (patch)
tree3c53101ee35676669cae96905b305d9a0a4dc37a /clientname.c
parenta6d8c3f336deebfff152e1d3f6d646ba1dc59eea (diff)
downloadrsync-1e736b8ff75180a01ad26ee92696d5dde4fe2628.tar.gz
rsync-1e736b8ff75180a01ad26ee92696d5dde4fe2628.tar.bz2
rsync-1e736b8ff75180a01ad26ee92696d5dde4fe2628.zip
Fix client_name to work on when INET6 is enabled but using a 4-part IPv4
IP address. Tested on Linux, but only with an IPv4 ssh. Somebody who has IPv6 enabled on ssh needs to test it yet.
Diffstat (limited to 'clientname.c')
-rw-r--r--clientname.c55
1 files changed, 33 insertions, 22 deletions
diff --git a/clientname.c b/clientname.c
index caf0af6c..93ca68e1 100644
--- a/clientname.c
+++ b/clientname.c
@@ -93,6 +93,8 @@ char *client_name(int fd)
static char name_buf[100];
static char port_buf[100];
static int initialised;
+ struct sockaddr_storage *ssp;
+ socklen_t ss_len;
if (initialised) return name_buf;
@@ -101,39 +103,48 @@ char *client_name(int fd)
if (getenv("SSH_CLIENT") != NULL) {
/* Look up name of IP address given in $SSH_CLIENT */
-#ifdef INET6
- int af = AF_INET6;
- struct sockaddr_in6 sin;
-#else
- int af = AF_INET;
+ char *addr = client_addr(fd);
struct sockaddr_in sin;
-#endif
- socklen_t sin_len = sizeof sin;
-
- memset(&sin, 0, sin_len);
-
#ifdef INET6
- sin.sin6_family = af;
- inet_pton(af, client_addr(fd), &sin.sin6_addr.s6_addr);
-#else
- sin.sin_family = af;
- inet_pton(af, client_addr(fd), &sin.sin_addr.s_addr);
+ int dots = 0;
+ char *p;
+ struct sockaddr_in6 sin6;
+
+ for (p = addr; *p && (dots < 3); p++) {
+ if (*p == '.')
+ dots++;
+ }
+ if (dots > 3) {
+ /* more than 4 parts to IP address, must be ipv6 */
+ ssp = (struct sockaddr_storage *) &sin6;
+ ss_len = sizeof sin6;
+ memset(ssp, 0, ss_len);
+ inet_pton(AF_INET6, addr, &sin6.sin6_addr.s6_addr);
+ sin6.sin6_family = AF_INET6;
+ } else
#endif
+ {
+ ssp = (struct sockaddr_storage *) &sin;
+ ss_len = sizeof sin;
+ memset(ssp, 0, ss_len);
+ inet_pton(AF_INET, addr, &sin.sin_addr.s_addr);
+ sin.sin_family = AF_INET;
+ }
- if (!lookup_name(fd, (struct sockaddr_storage *)&sin, sin_len,
- name_buf, sizeof name_buf, port_buf, sizeof port_buf))
- check_name(fd, (struct sockaddr_storage *)&sin, name_buf);
} else {
struct sockaddr_storage ss;
- socklen_t ss_len = sizeof ss;
+
+ ss_len = sizeof ss;
+ ssp = &ss;
client_sockaddr(fd, &ss, &ss_len);
- if (!lookup_name(fd, &ss, ss_len, name_buf, sizeof name_buf,
- port_buf, sizeof port_buf))
- check_name(fd, &ss, name_buf);
}
+ if (!lookup_name(fd, ssp, ss_len, name_buf, sizeof name_buf,
+ port_buf, sizeof port_buf))
+ check_name(fd, ssp, name_buf);
+
return name_buf;
}