Skip to content

Commit

Permalink
cleanup inet_ntoa usage.
Browse files Browse the repository at this point in the history
starting with the socket extension. PHP 8 requires windows vista/2008
minimum, even more exotic systems like solaris or haiku supports
inet_ntop, so there is no need to keep supporting this old interface.

Close phpGH-12551
  • Loading branch information
devnexen committed Oct 29, 2023
1 parent 4cfc8f6 commit 1c8943b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 22 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ SOAP:
. Mitigate #51561 (SoapServer with a extented class and using sessions,
lost the setPersistence()). (nielsdos)

Sockets:
. Removed the deprecated inet_ntoa call support. (David Carlier)

Standard:
. Implement GH-12188 (Indication for the int size in phpinfo()). (timwolla)
. Partly fix GH-12143 (Incorrect round() result for 0.49999999999999994).
Expand Down
23 changes: 1 addition & 22 deletions ext/sockets/sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,7 @@ ZEND_GET_MODULE(sockets)
#endif

#ifndef HAVE_INET_NTOP
/* inet_ntop should be used instead of inet_ntoa */
int inet_ntoa_lock = 0;
#error inet_ntop unsupported on this platform
#endif

static bool php_open_listen_sock(php_socket *sock, int port, int backlog) /* {{{ */
Expand Down Expand Up @@ -964,14 +963,7 @@ PHP_FUNCTION(socket_getsockname)
#endif
case AF_INET:
sin = (struct sockaddr_in *) sa;
#ifdef HAVE_INET_NTOP
addr_string = inet_ntop(AF_INET, &sin->sin_addr, addrbuf, sizeof(addrbuf));
#else
while (inet_ntoa_lock == 1);
inet_ntoa_lock = 1;
addr_string = inet_ntoa(sin->sin_addr);
inet_ntoa_lock = 0;
#endif
ZEND_TRY_ASSIGN_REF_STRING(addr, addr_string);

if (port != NULL) {
Expand Down Expand Up @@ -1043,14 +1035,7 @@ PHP_FUNCTION(socket_getpeername)
#endif
case AF_INET:
sin = (struct sockaddr_in *) sa;
#ifdef HAVE_INET_NTOP
addr_string = inet_ntop(AF_INET, &sin->sin_addr, addrbuf, sizeof(addrbuf));
#else
while (inet_ntoa_lock == 1);
inet_ntoa_lock = 1;
addr_string = inet_ntoa(sin->sin_addr);
inet_ntoa_lock = 0;
#endif
ZEND_TRY_ASSIGN_REF_STRING(arg2, addr_string);

if (arg3 != NULL) {
Expand Down Expand Up @@ -1383,9 +1368,7 @@ PHP_FUNCTION(socket_recvfrom)
#if HAVE_IPV6
struct sockaddr_in6 sin6;
#endif
#ifdef HAVE_INET_NTOP
char addrbuf[INET6_ADDRSTRLEN];
#endif
socklen_t slen;
int retval;
zend_long arg3, arg4;
Expand Down Expand Up @@ -1447,11 +1430,7 @@ PHP_FUNCTION(socket_recvfrom)
ZSTR_LEN(recv_buf) = retval;
ZSTR_VAL(recv_buf)[ZSTR_LEN(recv_buf)] = '\0';

#ifdef HAVE_INET_NTOP
address = inet_ntop(AF_INET, &sin.sin_addr, addrbuf, sizeof(addrbuf));
#else
address = inet_ntoa(sin.sin_addr);
#endif

ZEND_TRY_ASSIGN_REF_NEW_STR(arg2, recv_buf);
ZEND_TRY_ASSIGN_REF_STRING(arg5, address ? address : "0.0.0.0");
Expand Down

0 comments on commit 1c8943b

Please sign in to comment.