cvs: /php4/ext/standard basic_functions.c basic_functions.h
| From: | Andrei Zmievski | Date: | Sat, 04 Mar 2000 17:28:46 +0000 |
| Subject: | cvs: /php4/ext/standard basic_functions.c basic_functions.h | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-11516@lists.php.net to get a copy of this message | ||
andrei Sat Mar 4 09:28:46 2000 EDT
Modified files:
/php4/ext/standard basic_functions.c basic_functions.h
Log:
@Added ip2long() and long2ip() courtesy of Faisal Nasim <faisal@nasim.org>
Index: php4/ext/standard/basic_functions.c
diff -u php4/ext/standard/basic_functions.c:1.169 php4/ext/standard/basic_functions.c:1.170
--- php4/ext/standard/basic_functions.c:1.169 Fri Mar 3 18:59:14 2000
+++ php4/ext/standard/basic_functions.c Sat Mar 4 09:28:16 2000
@@ -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 @@
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
@@ -480,6 +483,42 @@
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: php4/ext/standard/basic_functions.h
diff -u php4/ext/standard/basic_functions.h:1.48 php4/ext/standard/basic_functions.h:1.49
--- php4/ext/standard/basic_functions.h:1.48 Fri Mar 3 18:59:14 2000
+++ php4/ext/standard/basic_functions.h Sat Mar 4 09:28:16 2000
@@ -29,7 +29,7 @@
*/
-/* $Id: basic_functions.h,v 1.48 2000/03/04 02:59:14 zeev Exp $ */
+/* $Id: basic_functions.h,v 1.49 2000/03/04 17:28:16 andrei Exp $ */
#ifndef _BASIC_FUNCTIONS_H
#define _BASIC_FUNCTIONS_H
@@ -55,6 +55,8 @@
PHP_FUNCTION(flush);
PHP_FUNCTION(gettype);
PHP_FUNCTION(settype);
+PHP_FUNCTION(ip2long);
+PHP_FUNCTION(long2ip);
/* system functions */
PHP_FUNCTION(getenv);