Skip to content

Commit 1c8943b

Browse files
committedOct 29, 2023
cleanup inet_ntoa usage.
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 GH-12551
1 parent 4cfc8f6 commit 1c8943b

File tree

2 files changed

+4
-22
lines changed

2 files changed

+4
-22
lines changed
 

‎NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ SOAP:
3636
. Mitigate #51561 (SoapServer with a extented class and using sessions,
3737
lost the setPersistence()). (nielsdos)
3838

39+
Sockets:
40+
. Removed the deprecated inet_ntoa call support. (David Carlier)
41+
3942
Standard:
4043
. Implement GH-12188 (Indication for the int size in phpinfo()). (timwolla)
4144
. Partly fix GH-12143 (Incorrect round() result for 0.49999999999999994).

‎ext/sockets/sockets.c

+1-22
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,7 @@ ZEND_GET_MODULE(sockets)
219219
#endif
220220

221221
#ifndef HAVE_INET_NTOP
222-
/* inet_ntop should be used instead of inet_ntoa */
223-
int inet_ntoa_lock = 0;
222+
#error inet_ntop unsupported on this platform
224223
#endif
225224

226225
static bool php_open_listen_sock(php_socket *sock, int port, int backlog) /* {{{ */
@@ -964,14 +963,7 @@ PHP_FUNCTION(socket_getsockname)
964963
#endif
965964
case AF_INET:
966965
sin = (struct sockaddr_in *) sa;
967-
#ifdef HAVE_INET_NTOP
968966
addr_string = inet_ntop(AF_INET, &sin->sin_addr, addrbuf, sizeof(addrbuf));
969-
#else
970-
while (inet_ntoa_lock == 1);
971-
inet_ntoa_lock = 1;
972-
addr_string = inet_ntoa(sin->sin_addr);
973-
inet_ntoa_lock = 0;
974-
#endif
975967
ZEND_TRY_ASSIGN_REF_STRING(addr, addr_string);
976968

977969
if (port != NULL) {
@@ -1043,14 +1035,7 @@ PHP_FUNCTION(socket_getpeername)
10431035
#endif
10441036
case AF_INET:
10451037
sin = (struct sockaddr_in *) sa;
1046-
#ifdef HAVE_INET_NTOP
10471038
addr_string = inet_ntop(AF_INET, &sin->sin_addr, addrbuf, sizeof(addrbuf));
1048-
#else
1049-
while (inet_ntoa_lock == 1);
1050-
inet_ntoa_lock = 1;
1051-
addr_string = inet_ntoa(sin->sin_addr);
1052-
inet_ntoa_lock = 0;
1053-
#endif
10541039
ZEND_TRY_ASSIGN_REF_STRING(arg2, addr_string);
10551040

10561041
if (arg3 != NULL) {
@@ -1383,9 +1368,7 @@ PHP_FUNCTION(socket_recvfrom)
13831368
#if HAVE_IPV6
13841369
struct sockaddr_in6 sin6;
13851370
#endif
1386-
#ifdef HAVE_INET_NTOP
13871371
char addrbuf[INET6_ADDRSTRLEN];
1388-
#endif
13891372
socklen_t slen;
13901373
int retval;
13911374
zend_long arg3, arg4;
@@ -1447,11 +1430,7 @@ PHP_FUNCTION(socket_recvfrom)
14471430
ZSTR_LEN(recv_buf) = retval;
14481431
ZSTR_VAL(recv_buf)[ZSTR_LEN(recv_buf)] = '\0';
14491432

1450-
#ifdef HAVE_INET_NTOP
14511433
address = inet_ntop(AF_INET, &sin.sin_addr, addrbuf, sizeof(addrbuf));
1452-
#else
1453-
address = inet_ntoa(sin.sin_addr);
1454-
#endif
14551434

14561435
ZEND_TRY_ASSIGN_REF_NEW_STR(arg2, recv_buf);
14571436
ZEND_TRY_ASSIGN_REF_STRING(arg5, address ? address : "0.0.0.0");

0 commit comments

Comments
 (0)
Please sign in to comment.