Skip to content

cleanup inet_ntoa usage. #12551

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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