Skip to content

readjust few inet_ntop usage across ipv4/ipv6 cases. #18531

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion ext/sockets/multicast.c
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ zend_result php_add4_to_if_index(struct in_addr *addr, php_socket *php_sock, uns
}

{
char addr_str[17] = {0};
char addr_str[INET_ADDRSTRLEN] = {0};
inet_ntop(AF_INET, addr, addr_str, sizeof(addr_str));
php_error_docref(NULL, E_WARNING,
"The interface with IP address %s was not found", addr_str);
Expand Down
6 changes: 3 additions & 3 deletions ext/sockets/sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ PHP_FUNCTION(socket_getsockname)
#endif
case AF_INET:
sin = (struct sockaddr_in *) sa;
addr_string = inet_ntop(AF_INET, &sin->sin_addr, addrbuf, sizeof(addrbuf));
addr_string = inet_ntop(AF_INET, &sin->sin_addr, addrbuf, INET_ADDRSTRLEN);
ZEND_TRY_ASSIGN_REF_STRING(addr, addr_string);

if (objint != NULL) {
Expand Down Expand Up @@ -1116,7 +1116,7 @@ PHP_FUNCTION(socket_getpeername)
#endif
case AF_INET:
sin = (struct sockaddr_in *) sa;
addr_string = inet_ntop(AF_INET, &sin->sin_addr, addrbuf, sizeof(addrbuf));
addr_string = inet_ntop(AF_INET, &sin->sin_addr, addrbuf, INET_ADDRSTRLEN);
ZEND_TRY_ASSIGN_REF_STRING(arg2, addr_string);

if (arg3 != NULL) {
Expand Down Expand Up @@ -1574,7 +1574,7 @@ PHP_FUNCTION(socket_recvfrom)
ZSTR_LEN(recv_buf) = retval;
ZSTR_VAL(recv_buf)[ZSTR_LEN(recv_buf)] = '\0';

address = inet_ntop(AF_INET, &sin.sin_addr, addrbuf, sizeof(addrbuf));
address = inet_ntop(AF_INET, &sin.sin_addr, addrbuf, INET_ADDRSTRLEN);

ZEND_TRY_ASSIGN_REF_NEW_STR(arg2, recv_buf);
ZEND_TRY_ASSIGN_REF_STRING(arg5, address ? address : "0.0.0.0");
Expand Down
6 changes: 3 additions & 3 deletions main/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -657,13 +657,13 @@ PHPAPI void php_network_populate_name_from_sockaddr(
}

if (textaddr) {
char abuf[256];
char abuf[INET6_ADDRSTRLEN];
const char *buf = NULL;

switch (sa->sa_family) {
case AF_INET:
/* generally not thread safe, but it *is* thread safe under win32 */
buf = inet_ntop(AF_INET, &((struct sockaddr_in*)sa)->sin_addr, (char *)&abuf, sizeof(abuf));
buf = inet_ntop(AF_INET, &((struct sockaddr_in*)sa)->sin_addr, abuf, INET_ADDRSTRLEN);
if (buf) {
*textaddr = strpprintf(0, "%s:%d",
buf, ntohs(((struct sockaddr_in*)sa)->sin_port));
Expand All @@ -673,7 +673,7 @@ PHPAPI void php_network_populate_name_from_sockaddr(

#ifdef HAVE_IPV6
case AF_INET6:
buf = (char*)inet_ntop(sa->sa_family, &((struct sockaddr_in6*)sa)->sin6_addr, (char *)&abuf, sizeof(abuf));
buf = inet_ntop(sa->sa_family, &((struct sockaddr_in6*)sa)->sin6_addr, abuf, sizeof(abuf));
if (buf) {
*textaddr = strpprintf(0, "[%s]:%d",
buf, ntohs(((struct sockaddr_in6*)sa)->sin6_port));
Expand Down