From 5397d09e585a1938fb64bc9c5cd5daed1959eb90 Mon Sep 17 00:00:00 2001 From: Tatsuya Kinoshita Date: Wed, 4 May 2011 16:41:45 +0900 Subject: Adding upstream version 0.5.3 --- ftp.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'ftp.c') diff --git a/ftp.c b/ftp.c index e3f8c2e..0002abd 100644 --- a/ftp.c +++ b/ftp.c @@ -1,4 +1,4 @@ -/* $Id: ftp.c,v 1.39 2007/05/31 01:19:50 inu Exp $ */ +/* $Id: ftp.c,v 1.42 2010/12/15 10:50:24 htrb Exp $ */ #include #ifndef __MINGW32_VERSION #include @@ -25,6 +25,10 @@ #include #endif /* __MINGW32_VERSION */ +#ifndef HAVE_SOCKLEN_T +typedef int socklen_t; +#endif + typedef struct _FTP { char *host; int port; @@ -127,12 +131,30 @@ ftp_login(FTP ftp) size_t n = strlen(ftp->pass); if (n > 0 && ftp->pass[n - 1] == '@') { +#ifdef INET6 + struct sockaddr_storage sockname; +#else struct sockaddr_in sockname; - int socknamelen = sizeof(sockname); +#endif + socklen_t socknamelen = sizeof(sockname); if (!getsockname(sock, (struct sockaddr *)&sockname, &socknamelen)) { struct hostent *sockent; Str tmp = Strnew_charp(ftp->pass); +#ifdef INET6 + char hostbuf[NI_MAXHOST]; + + if (getnameinfo((struct sockaddr *)&sockname, socknamelen, + hostbuf, sizeof hostbuf, NULL, 0, NI_NAMEREQD) + == 0) + Strcat_charp(tmp, hostbuf); + else if (getnameinfo((struct sockaddr *)&sockname, socknamelen, + hostbuf, sizeof hostbuf, NULL, 0, NI_NUMERICHOST) + == 0) + Strcat_m_charp(tmp, "[", hostbuf, "]", NULL); + else + Strcat_charp(tmp, "unknown"); +#else if ((sockent = gethostbyaddr((char *)&sockname.sin_addr, sizeof(sockname.sin_addr), @@ -141,7 +163,7 @@ ftp_login(FTP ftp) else Strcat_m_charp(tmp, "[", inet_ntoa(sockname.sin_addr), "]", NULL); - +#endif ftp->pass = tmp->ptr; } } @@ -192,7 +214,8 @@ ftp_pasv(FTP ftp) int family; #ifdef INET6 struct sockaddr_storage sockaddr; - int sockaddrlen, port; + int port; + socklen_t sockaddrlen; unsigned char d1, d2, d3, d4; char abuf[INET6_ADDRSTRLEN]; #endif -- cgit v1.2.3