# Patch for Bug #49757

- Thread: https://externals.io/message/45656
- Original archive: https://news-web.php.net/php.internals/45656
- Started by Florian Anderiasch on 2009-10-03T16:40:09+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #45656 — Florian Anderiasch — 2009-10-03T16:40:09+00:00

URL: https://externals.io/message/45656#45656

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

---

## #45662 — Ilia Alshanetsky — 2009-10-05T14:45:20+00:00

URL: https://externals.io/message/45656#45662 · In reply to: #45656

Thanks for the patch, a patch closely based on your was just applied  
to SVN.



> 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);
