pollita Sat Aug 7 00:50:25 2004 EDT Modified files: /php-src/ext/standard basic_functions.c basic_functions.h /php-src NEWS Log: New Functions inet_pton() and inet_ntop() http://cvs.php.net/diff.php/php-src/ext/standard/basic_functions.c?r1=1.679&r2=1.680&ty=u Index: php-src/ext/standard/basic_functions.c diff -u php-src/ext/standard/basic_functions.c:1.679 php-src/ext/standard/basic_functions.c:1.680 --- php-src/ext/standard/basic_functions.c:1.679 Sat Jul 31 13:28:27 2004 +++ php-src/ext/standard/basic_functions.c Sat Aug 7 00:50:23 2004 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: basic_functions.c,v 1.679 2004/07/31 17:28:27 wez Exp $ */ +/* $Id: basic_functions.c,v 1.680 2004/08/07 04:50:23 pollita Exp $ */ #include "php.h" #include "php_streams.h" @@ -419,6 +419,12 @@ PHP_FE(base_convert, NULL) PHP_FE(number_format, NULL) PHP_FE(fmod, NULL) +#ifdef HAVE_INET_NTOP + PHP_FE(inet_ntop, NULL) +#endif +#ifdef HAVE_INET_PTON + PHP_FE(inet_pton, NULL) +#endif PHP_FE(ip2long, NULL) PHP_FE(long2ip, NULL) @@ -1272,6 +1278,79 @@ } } /* }}} */ + +#ifdef HAVE_INET_NTOP +/* {{{ proto string inet_ntop(string in_addr) + Converts a packed inet address to a human readable IP address string */ +PHP_FUNCTION(inet_ntop) +{ + char *address; + int address_len, af = AF_INET; + char buffer[40]; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &address, &address_len) == FAILURE) { + RETURN_FALSE; + } + +#ifdef HAVE_IPV6 + if (address_len == 16) { + af = AF_INET6; + } else +#endif + if (address_len != 4) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid in_addr value"); + RETURN_FALSE; + } + + if (!inet_ntop(af, address, buffer, sizeof(buffer))) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "An unknown error occured"); + RETURN_FALSE; + } + + RETURN_STRING(buffer, 1); +} +/* }}} */ +#endif /* HAVE_INET_NTOP */ + +#ifdef HAVE_INET_PTON +/* {{{ proto string inet_pton(string ip_address) + Converts a human readable IP address to a packed binary string */ +PHP_FUNCTION(inet_pton) +{ + int ret, af = AF_INET; + char *address; + int address_len; + char buffer[17]; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &address, &address_len) == FAILURE) { + RETURN_FALSE; + } + + memset(buffer, 0, sizeof(buffer)); + +#ifdef HAVE_IPV6 + if (strchr(address, ':')) { + af = AF_INET6; + } else +#endif + if (!strchr(address, '.')) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unrecognized address %s", address); + RETURN_FALSE; + } + + ret = inet_pton(af, address, buffer); + + if (ret <= 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unrecognized address %s", address); + RETURN_FALSE; + } + + RETURN_STRING(buffer, 1); +} +/* }}} */ +#endif /* HAVE_INET_PTON */ + + /* {{{ proto int ip2long(string ip_address) Converts a string containing an (IPv4) Internet Protocol dotted address into a proper address */ http://cvs.php.net/diff.php/php-src/ext/standard/basic_functions.h?r1=1.133&r2=1.134&ty=u Index: php-src/ext/standard/basic_functions.h diff -u php-src/ext/standard/basic_functions.h:1.133 php-src/ext/standard/basic_functions.h:1.134 --- php-src/ext/standard/basic_functions.h:1.133 Fri Mar 26 19:50:39 2004 +++ php-src/ext/standard/basic_functions.h Sat Aug 7 00:50:24 2004 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: basic_functions.h,v 1.133 2004/03/27 00:50:39 helly Exp $ */ +/* $Id: basic_functions.h,v 1.134 2004/08/07 04:50:24 pollita Exp $ */ #ifndef BASIC_FUNCTIONS_H #define BASIC_FUNCTIONS_H @@ -52,6 +52,12 @@ PHP_FUNCTION(time_nanosleep); #endif PHP_FUNCTION(flush); +#ifdef HAVE_INET_NTOP +PHP_FUNCTION(inet_ntop); +#endif +#ifdef HAVE_INET_PTON +PHP_FUNCTION(inet_pton); +#endif PHP_FUNCTION(ip2long); PHP_FUNCTION(long2ip); http://cvs.php.net/diff.php/php-src/NEWS?r1=1.1783&r2=1.1784&ty=u Index: php-src/NEWS diff -u php-src/NEWS:1.1783 php-src/NEWS:1.1784 --- php-src/NEWS:1.1783 Thu Aug 5 10:13:13 2004 +++ php-src/NEWS Sat Aug 7 00:50:24 2004 @@ -17,6 +17,8 @@ . stream_socket_enable_crypto() (Wez) . SimpleXMLElement->registerXPathNamespace() (Christian) . mysqli->client_info property (Georg) + . inet_pton() (Sara) + . inet_ntop() (Sara) - PHP will now respect extension dependencies when initializing. (Wez) - Added Cursor support for MySQL 5.0.x in mysqli (Georg) - Added proxy support to ftp wrapper via http. (Sara)
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php