]> granicus.if.org Git - php/commitdiff
@Added ip2long() and long2ip() courtesy of Faisal Nasim <faisal@nasim.org>
authorAndrei Zmievski <andrei@php.net>
Sat, 4 Mar 2000 17:28:16 +0000 (17:28 +0000)
committerAndrei Zmievski <andrei@php.net>
Sat, 4 Mar 2000 17:28:16 +0000 (17:28 +0000)
ext/standard/basic_functions.c
ext/standard/basic_functions.h

index d42d427526378dfa169fa5f73571521b95cdf6ac..4c756d47bd0589efa3968f4bd8512e7a2abf2e6e 100644 (file)
@@ -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 *
  ********************/
index 9f4ed101a6b66e2e875aa3bd676d09b61d4ff73c..d046978c81bc9c2f833b4c9ecc232966331bcb16 100644 (file)
@@ -55,6 +55,8 @@ PHP_FUNCTION(usleep);
 PHP_FUNCTION(flush);
 PHP_FUNCTION(gettype);
 PHP_FUNCTION(settype);
+PHP_FUNCTION(ip2long);
+PHP_FUNCTION(long2ip);
 
 /* system functions */
 PHP_FUNCTION(getenv);