From 7c039a46d5faf90e26408e073cedca510efc1eac Mon Sep 17 00:00:00 2001 From: Ito Hiroyuki Date: Wed, 15 Dec 2010 10:50:24 +0000 Subject: [w3m-dev 04424] http://www.j10n.org/files/w3m-cvs-1.1040-misc.patch --- ftp.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'ftp.c') diff --git a/ftp.c b/ftp.c index 19c27a5..0002abd 100644 --- a/ftp.c +++ b/ftp.c @@ -1,4 +1,4 @@ -/* $Id: ftp.c,v 1.41 2010/08/11 09:31:33 htrb Exp $ */ +/* $Id: ftp.c,v 1.42 2010/12/15 10:50:24 htrb Exp $ */ #include #ifndef __MINGW32_VERSION #include @@ -131,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; +#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), @@ -145,7 +163,7 @@ ftp_login(FTP ftp) else Strcat_m_charp(tmp, "[", inet_ntoa(sockname.sin_addr), "]", NULL); - +#endif ftp->pass = tmp->ptr; } } -- cgit v1.2.3