aboutsummaryrefslogtreecommitdiffstats
path: root/ftp.c
diff options
context:
space:
mode:
authorTatsuya Kinoshita <tats@vega.ocn.ne.jp>2011-05-04 07:41:45 +0000
committerTatsuya Kinoshita <tats@vega.ocn.ne.jp>2011-05-04 07:41:45 +0000
commit5397d09e585a1938fb64bc9c5cd5daed1959eb90 (patch)
treecd2673d4ca9584c426f9291e54b7bbb508c11e76 /ftp.c
parentAdding upstream version 0.5.2 (diff)
downloadw3m-5397d09e585a1938fb64bc9c5cd5daed1959eb90.tar.gz
w3m-5397d09e585a1938fb64bc9c5cd5daed1959eb90.zip
Adding upstream version 0.5.3upstream/0.5.3
Diffstat (limited to 'ftp.c')
-rw-r--r--ftp.c31
1 files changed, 27 insertions, 4 deletions
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 <stdio.h>
#ifndef __MINGW32_VERSION
#include <pwd.h>
@@ -25,6 +25,10 @@
#include <winsock.h>
#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