|
Michal Luscon |
23333d8 |
--- ./src/ftp.cc 2013-12-09 02:20:54.000000000 +0100
|
|
Michal Luscon |
23333d8 |
+++ ./src/ftp.cc 2013-12-30 13:08:20.216408559 +0100
|
|
Michal Luscon |
23333d8 |
@@ -2786,6 +2786,7 @@
|
|
Michal Luscon |
23333d8 |
}
|
|
Michal Luscon |
23333d8 |
|
|
Michal Luscon |
23333d8 |
ftpState->listenForDataChannel(temp, ftpState->entry->url());
|
|
Michal Luscon |
23333d8 |
+ ftpState->data.listenConn = temp;
|
|
Michal Luscon |
23333d8 |
}
|
|
Michal Luscon |
23333d8 |
|
|
Michal Luscon |
23333d8 |
/// \ingroup ServerProtocolFTPInternal
|
|
Michal Luscon |
23333d8 |
@@ -2822,13 +2823,18 @@
|
|
Michal Luscon |
23333d8 |
// pull out the internal IP address bytes to send in PORT command...
|
|
Michal Luscon |
23333d8 |
// source them from the listen_conn->local
|
|
Michal Luscon |
23333d8 |
|
|
Michal Luscon |
23333d8 |
+ struct sockaddr_in addr;
|
|
Michal Luscon |
23333d8 |
+ socklen_t addrlen = sizeof(addr);
|
|
Michal Luscon |
23333d8 |
+ getsockname(ftpState->data.listenConn->fd, (struct sockaddr *) &addr, &addrlen);
|
|
Michal Luscon |
23333d8 |
+ unsigned char port_high = ntohs(addr.sin_port) >> 8;
|
|
Michal Luscon |
23333d8 |
+ unsigned char port_low = ntohs(addr.sin_port) & 0xff;
|
|
Michal Luscon |
23333d8 |
+
|
|
Michal Luscon |
23333d8 |
struct addrinfo *AI = NULL;
|
|
Michal Luscon |
23333d8 |
ftpState->data.listenConn->local.getAddrInfo(AI, AF_INET);
|
|
Michal Luscon |
23333d8 |
unsigned char *addrptr = (unsigned char *) &((struct sockaddr_in*)AI->ai_addr)->sin_addr;
|
|
Michal Luscon |
23333d8 |
- unsigned char *portptr = (unsigned char *) &((struct sockaddr_in*)AI->ai_addr)->sin_port;
|
|
Michal Luscon |
23333d8 |
snprintf(cbuf, CTRL_BUFLEN, "PORT %d,%d,%d,%d,%d,%d\r\n",
|
|
Michal Luscon |
23333d8 |
addrptr[0], addrptr[1], addrptr[2], addrptr[3],
|
|
Michal Luscon |
23333d8 |
- portptr[0], portptr[1]);
|
|
Michal Luscon |
23333d8 |
+ port_high, port_low);
|
|
Michal Luscon |
23333d8 |
ftpState->writeCommand(cbuf);
|
|
Michal Luscon |
23333d8 |
ftpState->state = SENT_PORT;
|
|
Michal Luscon |
23333d8 |
|
|
Michal Luscon |
23333d8 |
@@ -2877,15 +2883,27 @@
|
|
Michal Luscon |
23333d8 |
ftpFail(ftpState);
|
|
Michal Luscon |
1efb17f |
return;
|
|
Michal Luscon |
1efb17f |
}
|
|
Michal Luscon |
23333d8 |
+
|
|
Michal Luscon |
23333d8 |
+ unsigned int port;
|
|
Michal Luscon |
23333d8 |
+ struct sockaddr_storage addr;
|
|
Michal Luscon |
23333d8 |
+ socklen_t addrlen = sizeof(addr);
|
|
Michal Luscon |
23333d8 |
+ getsockname(ftpState->data.listenConn->fd, (struct sockaddr *) &addr, &addrlen);
|
|
Michal Luscon |
23333d8 |
+ if (addr.ss_family == AF_INET) {
|
|
Michal Luscon |
23333d8 |
+ struct sockaddr_in *addr4 = (struct sockaddr_in*) &addr;
|
|
Michal Luscon |
23333d8 |
+ port = ntohs( addr4->sin_port );
|
|
Michal Luscon |
23333d8 |
+ } else {
|
|
Michal Luscon |
23333d8 |
+ struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *) &addr;
|
|
Michal Luscon |
23333d8 |
+ port = ntohs( addr6->sin6_port );
|
|
Michal Luscon |
23333d8 |
+ }
|
|
Michal Luscon |
23333d8 |
|
|
Michal Luscon |
23333d8 |
char buf[MAX_IPSTRLEN];
|
|
Michal Luscon |
23333d8 |
|
|
Michal Luscon |
23333d8 |
/* RFC 2428 defines EPRT as IPv6 equivalent to IPv4 PORT command. */
|
|
Michal Luscon |
23333d8 |
/* Which can be used by EITHER protocol. */
|
|
Michal Luscon |
23333d8 |
- snprintf(cbuf, CTRL_BUFLEN, "EPRT |%d|%s|%d|\r\n",
|
|
Michal Luscon |
23333d8 |
+ snprintf(cbuf, CTRL_BUFLEN, "EPRT |%d|%s|%u|\r\n",
|
|
Michal Luscon |
23333d8 |
( ftpState->data.listenConn->local.isIPv6() ? 2 : 1 ),
|
|
Michal Luscon |
23333d8 |
ftpState->data.listenConn->local.toStr(buf,MAX_IPSTRLEN),
|
|
Michal Luscon |
23333d8 |
- ftpState->data.listenConn->local.port() );
|
|
Michal Luscon |
23333d8 |
+ port );
|
|
Michal Luscon |
23333d8 |
|
|
Michal Luscon |
23333d8 |
ftpState->writeCommand(cbuf);
|
|
Michal Luscon |
23333d8 |
ftpState->state = SENT_EPRT;
|