diff options
| author | Andrei Zmievski <andrei@php.net> | 2000-03-04 17:28:16 +0000 |
|---|---|---|
| committer | Andrei Zmievski <andrei@php.net> | 2000-03-04 17:28:16 +0000 |
| commit | 0e18779e8b864d5b9638387ba784a61ff7d80118 (patch) | |
| tree | 5d1dcb7fe59411b00c4bbfbb89b1358d0b3bc481 /ext/standard/basic_functions.c | |
| parent | 5610800a7b2f9a1ba9bf91fbd9b9ae8277127afd (diff) | |
| download | php-git-0e18779e8b864d5b9638387ba784a61ff7d80118.tar.gz | |
@Added ip2long() and long2ip() courtesy of Faisal Nasim <faisal@nasim.org>
Diffstat (limited to 'ext/standard/basic_functions.c')
| -rw-r--r-- | ext/standard/basic_functions.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index d42d427526..4c756d47bd 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -30,6 +30,7 @@ #include <time.h> #include <stdio.h> #include <netdb.h> +#include <arpa/inet.h> #if HAVE_UNISTD_H #include <unistd.h> #endif @@ -234,6 +235,8 @@ function_entry basic_functions[] = { PHP_FE(dechex, NULL) PHP_FE(base_convert, NULL) PHP_FE(number_format, NULL) + PHP_FE(ip2long, NULL) + PHP_FE(long2ip, NULL) PHP_FE(getenv, NULL) #ifdef HAVE_PUTENV @@ -481,6 +484,42 @@ PHP_RSHUTDOWN_FUNCTION(basic) return SUCCESS; } + +PHP_FUNCTION(ip2long) +{ + zval **str; + + if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &str) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_string_ex(str); + + if ((*str)->type != IS_STRING) { + RETURN_FALSE; + } + + RETURN_LONG ( inet_addr ( ( *str ) -> value.str.val ) ); +} + + +PHP_FUNCTION(long2ip) +{ + zval **num; + struct in_addr myaddr; + + if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &num) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long_ex(num); + myaddr.s_addr = (*num) -> value.lval; + + RETURN_STRING ( inet_ntoa ( myaddr ) , 1 ); +} + + + /******************** * System Functions * ********************/ |
