#37690 [NEW]: Add feature to bind to ip for ftp_connect()

From: Date: Sat, 03 Jun 2006 22:59:12 +0000
Subject: #37690 [NEW]: Add feature to bind to ip for ftp_connect()
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-98009@lists.php.net to get a copy of this message
From: jasper dot e at gmail dot com Operating system: Fedora Core 2 PHP version: 5.1.4 PHP Bug Type: Feature/Change Request Bug description: Add feature to bind to ip for ftp_connect() Description: ------------ The current ftp_connect function does not have the feature to bind the outgoing connections to a specific local IP. Yet this functionality is quite easily added. With my very very very basic cpp knowledge I managed to add this feature to the code. Imho it'd be a good idea to add something like this but properly coded to the ftp_ featureset :) A quick'n dirty changeset which converts ftp_connect(host,port,timeout) to ftp_connect(host,bindip,port) diff -urN php-5.1.4/ext/ftp/ftp.c php-5.1.4-ftpbind/ext/ftp/ftp.c --- php-5.1.4/ext/ftp/ftp.c 2006-04-03 11:14:33.000000000 +0200 +++ php-5.1.4-ftpbind/ext/ftp/ftp.c 2006-06-03 15:04:58.718141536 +0200 @@ -121,7 +121,7 @@ /* {{{ ftp_open */ ftpbuf_t* -ftp_open(const char *host, short port, long timeout_sec TSRMLS_DC) +ftp_open(const char *host, const char *bindhost, short port, long timeout_sec TSRMLS_DC) { ftpbuf_t *ftp; socklen_t size; @@ -136,7 +136,7 @@ ftp->fd = php_network_connect_socket_to_host(host, (unsigned short) (port ? port : 21), SOCK_STREAM, - 0, &tv, NULL, NULL, NULL, 0 TSRMLS_CC); + 0, &tv, NULL, NULL, bindhost, 0 TSRMLS_CC); if (ftp->fd == -1) { goto bail; } diff -urN php-5.1.4/ext/ftp/ftp.h php-5.1.4-ftpbind/ext/ftp/ftp.h --- php-5.1.4/ext/ftp/ftp.h 2006-01-01 13:50:06.000000000 +0100 +++ php-5.1.4-ftpbind/ext/ftp/ftp.h 2006-06-03 15:04:58.718141536 +0200 @@ -93,7 +93,7 @@ /* open a FTP connection, returns ftpbuf (NULL on error) * port is the ftp port in network byte order, or 0 for the default */ -ftpbuf_t* ftp_open(const char *host, short port, long timeout_sec TSRMLS_DC); +ftpbuf_t* ftp_open(const char *host, const char *bindhost, short port, long timeout_sec TSRMLS_DC); /* quits from the ftp session (it still needs to be closed) * return true on success, false on error diff -urN php-5.1.4/ext/ftp/php_ftp.c php-5.1.4-ftpbind/ext/ftp/php_ftp.c --- php-5.1.4/ext/ftp/php_ftp.c 2006-01-01 13:50:06.000000000 +0100 +++ php-5.1.4-ftpbind/ext/ftp/php_ftp.c 2006-06-03 15:04:58.718141536 +0200 @@ -147,17 +147,19 @@ } -/* {{{ proto resource ftp_connect(string host [, int port [, int timeout]]) +/* {{{ proto resource ftp_connect(string host [, string bindhost [, int port [, int timeout]]]) Opens a FTP stream */ PHP_FUNCTION(ftp_connect) { ftpbuf_t *ftp; char *host; + char *bindhost; int host_len; + int bindhost_len; long port = 0; long timeout_sec = FTP_DEFAULT_TIMEOUT; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ll", &host, &host_len, &port, &timeout_sec) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s|ll", &host, &host_len, &bindhost, &bindhost_len, &port, &timeout_sec) == FAILURE) { return; -- Edit bug report at http://bugs.php.net/?id=37690&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=37690&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=37690&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=37690&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=37690&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=37690&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=37690&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=37690&r=needscript Try newer version: http://bugs.php.net/fix.php?id=37690&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=37690&r=support Expected behavior: http://bugs.php.net/fix.php?id=37690&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=37690&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=37690&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=37690&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=37690&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=37690&r=dst IIS Stability: http://bugs.php.net/fix.php?id=37690&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=37690&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=37690&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=37690&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=37690&r=mysqlcfg

« previous php.bugs (#98009) next »