memset(&ftp->pasvaddr, 0, n);
sa = (struct sockaddr *) &ftp->pasvaddr;
-#if HAVE_IPV6
if (getpeername(ftp->fd, sa, &n) < 0) {
return 0;
}
+
+#if HAVE_IPV6
if (sa->sa_family == AF_INET6) {
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) sa;
char *endptr, delimiter;
ipbox.c[n] = (unsigned char) b[n];
}
sin = (struct sockaddr_in *) sa;
- sin->sin_family = AF_INET;
- sin->sin_addr = ipbox.ia[0];
+ if (ftp->usepasvaddress) {
+ sin->sin_addr = ipbox.ia[0];
+ }
sin->sin_port = ipbox.s[2];
ftp->pasv = 2;
#define FTP_DEFAULT_TIMEOUT 90
#define FTP_DEFAULT_AUTOSEEK 1
+#define FTP_DEFAULT_USEPASVADDRESS 1
#define PHP_FTP_FAILED 0
#define PHP_FTP_FINISHED 1
#define PHP_FTP_MOREDATA 2
php_sockaddr_storage pasvaddr; /* passive mode address */
long timeout_sec; /* User configurable timeout (seconds) */
int autoseek; /* User configurable autoseek flag */
+ int usepasvaddress; /* Use the address returned by the pasv command */
int nb; /* "nonblocking" transfer in progress */
databuf_t *data; /* Data connection for "nonblocking" transfers */
REGISTER_LONG_CONSTANT("FTP_AUTORESUME", PHP_FTP_AUTORESUME, CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("FTP_TIMEOUT_SEC", PHP_FTP_OPT_TIMEOUT_SEC, CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("FTP_AUTOSEEK", PHP_FTP_OPT_AUTOSEEK, CONST_PERSISTENT | CONST_CS);
+ REGISTER_LONG_CONSTANT("FTP_USEPASVADDRESS", PHP_FTP_OPT_USEPASVADDRESS, CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("FTP_FAILED", PHP_FTP_FAILED, CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("FTP_FINISHED", PHP_FTP_FINISHED, CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("FTP_MOREDATA", PHP_FTP_MOREDATA, CONST_PERSISTENT | CONST_CS);
/* autoseek for resuming */
ftp->autoseek = FTP_DEFAULT_AUTOSEEK;
+ ftp->usepasvaddress = FTP_DEFAULT_USEPASVADDRESS;
#if HAVE_OPENSSL_EXT
/* disable ssl */
ftp->use_ssl = 0;
/* autoseek for resuming */
ftp->autoseek = FTP_DEFAULT_AUTOSEEK;
+ ftp->usepasvaddress = FTP_DEFAULT_USEPASVADDRESS;
/* enable ssl */
ftp->use_ssl = 1;
ftp->autoseek = Z_LVAL_P(z_value);
RETURN_TRUE;
break;
+ case PHP_FTP_OPT_USEPASVADDRESS:
+ if (Z_TYPE_P(z_value) != IS_BOOL) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Option USEPASVADDRESS expects value of type boolean, %s given",
+ zend_zval_type_name(z_value));
+ RETURN_FALSE;
+ }
+ ftp->usepasvaddress = Z_LVAL_P(z_value);
+ RETURN_TRUE;
+ break;
default:
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown option '%ld'", option);
RETURN_FALSE;
case PHP_FTP_OPT_AUTOSEEK:
RETURN_BOOL(ftp->autoseek);
break;
+ case PHP_FTP_OPT_USEPASVADDRESS:
+ RETURN_BOOL(ftp->usepasvaddress);
+ break;
default:
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown option '%ld'", option);
RETURN_FALSE;