Thanks for the patch, a patch closely based on your was just applied
to SVN.
On 2009-10-03, at 12:40 PM, Florian Anderiasch wrote:
Hello,
I've tried to fix http://bugs.php.net/bug.php?id=49757
As it's my first patch in c, any reviews and suggestions would be very
welcome.
Greetings,
Florian
Index: ext/standard/basic_functions.c
===================================================================
--- ext/standard/basic_functions.c (revision 289129)
+++ ext/standard/basic_functions.c (working copy)
@@ -3932,6 +3932,7 @@
int ip_len;
unsigned long n;
struct in_addr myaddr;
+ char str[INET_ADDRSTRLEN];
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &ip,
&ip_len) == FAILURE) {
return;
@@ -3940,7 +3941,14 @@
n = strtoul(ip, NULL, 0);
myaddr.s_addr = htonl(n);
- RETURN_STRING(inet_ntoa(myaddr), 1);
+
+#ifdef HAVE_INET_NTOP
+ inet_ntop(AF_INET, &myaddr, str, INET_ADDRSTRLEN);
+#else
+ str = inet_ntoa(myaddr);
+#endif
+
+ RETURN_STRING(str, 1);
}
/* }}} */
Index: ext/standard/basic_functions.h
===================================================================
--- ext/standard/basic_functions.h (revision 289129)
+++ ext/standard/basic_functions.h (working copy)
@@ -59,6 +59,7 @@
#endif
PHP_FUNCTION(ip2long);
PHP_FUNCTION(long2ip);
+#define INET_ADDRSTRLEN 16
/* system functions */
PHP_FUNCTION(getenv);
Index: ext/standard/basic_functions.c
===================================================================
--- ext/standard/basic_functions.c (revision 289129)
+++ ext/standard/basic_functions.c (working copy)
@@ -3923,6 +3923,7 @@
int ip_len;
unsigned long n;
struct in_addr myaddr;
+ char str[INET_ADDRSTRLEN];
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &ip,
&ip_len) == FAILURE) {
return;
@@ -3931,7 +3932,14 @@
n = strtoul(ip, NULL, 0);
myaddr.s_addr = htonl(n);
- RETURN_RT_STRING(inet_ntoa(myaddr), ZSTR_DUPLICATE);
+
+#ifdef HAVE_INET_NTOP
+ inet_ntop(AF_INET, &myaddr, str, INET_ADDRSTRLEN);
+#else
+ str = inet_ntoa(myaddr);
+#endif
+
+ RETURN_RT_STRING(str, ZSTR_DUPLICATE);
}
/* }}} */
Index: ext/standard/basic_functions.h
===================================================================
--- ext/standard/basic_functions.h (revision 289129)
+++ ext/standard/basic_functions.h (working copy)
@@ -59,6 +59,7 @@
#endif
PHP_FUNCTION(ip2long);
PHP_FUNCTION(long2ip);
+#define INET_ADDRSTRLEN 16
/* system functions */
PHP_FUNCTION(getenv);
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php