Skip to content

Remove HAVE_INET_PTON #13410

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

Merged
merged 11 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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: 0 additions & 2 deletions Zend/Optimizer/zend_func_infos.h
Original file line number Diff line number Diff line change
Expand Up @@ -517,9 +517,7 @@ static const func_info_t func_infos[] = {
F1("sha1", MAY_BE_STRING),
F1("sha1_file", MAY_BE_STRING|MAY_BE_FALSE),
F1("inet_ntop", MAY_BE_STRING|MAY_BE_FALSE),
#if defined(HAVE_INET_PTON)
F1("inet_pton", MAY_BE_STRING|MAY_BE_FALSE),
#endif
F1("metaphone", MAY_BE_STRING),
F1("headers_list", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
F1("htmlspecialchars", MAY_BE_STRING),
Expand Down
10 changes: 7 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,6 @@ getgrnam_r \
getpwuid_r \
getwd \
glob \
inet_pton \
localtime_r \
lchown \
memcntl \
Expand Down Expand Up @@ -640,8 +639,13 @@ memrchr \
mempcpy \
)

AC_CHECK_FUNC(inet_ntop,[],[
AC_MSG_ERROR([Cannot find inet_ntop which is required])
AC_CHECK_FUNC([inet_ntop],[],[
AC_MSG_ERROR([Cannot find inet_ntop which is required.])
]
)

AC_CHECK_FUNC([inet_pton],[],[
AC_MSG_ERROR([Cannot find inet_pton which is required.])
]
)

Expand Down
2 changes: 1 addition & 1 deletion ext/openssl/xp_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
#define PHP_X509_NAME_ENTRY_TO_UTF8(ne, i, out) \
ASN1_STRING_to_UTF8(&out, X509_NAME_ENTRY_get_data(X509_NAME_get_entry(ne, i)))

#if defined(HAVE_IPV6) && defined(HAVE_INET_PTON)
#if defined(HAVE_IPV6)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#if defined(HAVE_IPV6)
#ifdef HAVE_IPV6

/* Used for IPv6 Address peer verification */
#define EXPAND_IPV6_ADDRESS(_str, _bytes) \
do { \
Expand Down
4 changes: 0 additions & 4 deletions ext/sockets/sockaddr_conv.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,7 @@ int php_set_inet_addr(struct sockaddr_in *sin, char *string, php_socket *php_soc
struct in_addr tmp;
struct hostent *host_entry;

#ifdef HAVE_INET_PTON
if (inet_pton(AF_INET, string, &tmp)) {
#else
if (inet_aton(string, &tmp)) {
#endif
sin->sin_addr.s_addr = tmp.s_addr;
} else {
if (strlen(string) > MAXFQDNLEN || ! (host_entry = php_network_gethostbyname(string))) {
Expand Down
21 changes: 0 additions & 21 deletions ext/standard/basic_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,6 @@ PHP_FUNCTION(inet_ntop)
}
/* }}} */

#ifdef HAVE_INET_PTON
/* {{{ Converts a human readable IP address to a packed binary string */
PHP_FUNCTION(inet_pton)
{
Expand Down Expand Up @@ -588,42 +587,22 @@ PHP_FUNCTION(inet_pton)
RETURN_STRINGL(buffer, af == AF_INET ? 4 : 16);
}
/* }}} */
#endif /* HAVE_INET_PTON */

/* {{{ Converts a string containing an (IPv4) Internet Protocol dotted address into a proper address */
PHP_FUNCTION(ip2long)
{
char *addr;
size_t addr_len;
#ifdef HAVE_INET_PTON
struct in_addr ip;
#else
zend_ulong ip;
#endif

ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STRING(addr, addr_len)
ZEND_PARSE_PARAMETERS_END();

#ifdef HAVE_INET_PTON
if (addr_len == 0 || inet_pton(AF_INET, addr, &ip) != 1) {
RETURN_FALSE;
}
RETURN_LONG(ntohl(ip.s_addr));
#else
if (addr_len == 0 || (ip = inet_addr(addr)) == INADDR_NONE) {
/* The only special case when we should return -1 ourselves,
* because inet_addr() considers it wrong. We return 0xFFFFFFFF and
* not -1 or ~0 because of 32/64bit issues. */
if (addr_len == sizeof("255.255.255.255") - 1 &&
!memcmp(addr, "255.255.255.255", sizeof("255.255.255.255") - 1)
) {
RETURN_LONG(0xFFFFFFFF);
}
RETURN_FALSE;
}
RETURN_LONG(ntohl(ip));
#endif
}
/* }}} */

Expand Down
2 changes: 0 additions & 2 deletions ext/standard/basic_functions.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -2238,10 +2238,8 @@ function syslog(int $priority, string $message): true {} // TODO make return typ
/** @refcount 1 */
function inet_ntop(string $ip): string|false {}

#ifdef HAVE_INET_PTON
/** @refcount 1 */
function inet_pton(string $ip): string|false {}
#endif

/* metaphone.c */

Expand Down
12 changes: 2 additions & 10 deletions ext/standard/basic_functions_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions ext/standard/dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ PHP_FUNCTION(gethostbyaddr)
hostname = php_gethostbyaddr(addr);

if (hostname == NULL) {
#if defined(HAVE_IPV6) && defined(HAVE_INET_PTON)
#if defined(HAVE_IPV6)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#if defined(HAVE_IPV6)
#ifdef HAVE_IPV6

php_error_docref(NULL, E_WARNING, "Address is not a valid IPv4 or IPv6 address");
#else
php_error_docref(NULL, E_WARNING, "Address is not in a.b.c.d form");
Expand All @@ -172,7 +172,7 @@ PHP_FUNCTION(gethostbyaddr)
/* {{{ php_gethostbyaddr */
static zend_string *php_gethostbyaddr(char *ip)
{
#if defined(HAVE_IPV6) && defined(HAVE_INET_PTON)
#if defined(HAVE_IPV6)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#if defined(HAVE_IPV6)
#ifdef HAVE_IPV6

struct sockaddr_in sa4;
struct sockaddr_in6 sa6;
char out[NI_MAXHOST];
Expand Down
6 changes: 4 additions & 2 deletions ext/standard/tests/network/ip2long_variation2.phpt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
--TEST--
Test ip2long() function : usage variation 2, 32 bit
--SKIPIF--
<?php if(PHP_INT_SIZE != 4) {die('skip 32 bit only');} ?>
<?php if (strtolower(substr(PHP_OS, 0, 3)) == 'aix') {die('skip not for AIX');} ?>
<?php
if(PHP_INT_SIZE != 4) { die('skip 32 bit only'); }
if(strtolower(substr(PHP_OS, 0, 3)) == 'aix') { die('skip not for AIX'); }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: space after if

?>
--FILE--
<?php
$ips = array(
Expand Down
5 changes: 0 additions & 5 deletions main/fastcgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -681,12 +681,7 @@ int fcgi_listen(const char *path, int backlog)
if (!*host || !strncmp(host, "*", sizeof("*")-1)) {
sa.sa_inet.sin_addr.s_addr = htonl(INADDR_ANY);
} else {
#ifdef HAVE_INET_PTON
if (!inet_pton(AF_INET, host, &sa.sa_inet.sin_addr)) {
#else
sa.sa_inet.sin_addr.s_addr = inet_addr(host);
if (sa.sa_inet.sin_addr.s_addr == INADDR_NONE) {
#endif
struct hostent *hep;

if(strlen(host) > MAXFQDNLEN) {
Expand Down
18 changes: 3 additions & 15 deletions main/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,7 @@ PHPAPI int php_network_getaddresses(const char *host, int socktype, struct socka

freeaddrinfo(res);
#else
#ifdef HAVE_INET_PTON
if (!inet_pton(AF_INET, host, &in)) {
#else
if (!inet_aton(host, &in)) {
#endif
if(strlen(host) > MAXFQDNLEN) {
host_info = NULL;
errno = E2BIG;
Expand Down Expand Up @@ -545,7 +541,7 @@ PHPAPI int php_network_parse_network_address_with_port(const char *addr, zend_lo

/* first, try interpreting the address as a numeric address */

#if HAVE_IPV6 && HAVE_INET_PTON
#if HAVE_IPV6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#if HAVE_IPV6
#ifdef HAVE_IPV6

think it should always test definition

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I have a long-standing (very outdated PR (#5526) now) to try to enable -Wundef to check these sorts of issues at compile time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need help with this PR, @Girgias ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can take it over, I was hitting some issue with YACC generating something that I couldn't check.

if (inet_pton(AF_INET6, tmp, &in6->sin6_addr) > 0) {
in6->sin6_port = htons(port);
in6->sin6_family = AF_INET6;
Expand All @@ -554,11 +550,7 @@ PHPAPI int php_network_parse_network_address_with_port(const char *addr, zend_lo
goto out;
}
#endif
#ifdef HAVE_INET_PTON
if (inet_pton(AF_INET, tmp, &in4->sin_addr) > 0) {
#else
if (inet_aton(tmp, &in4->sin_addr) > 0) {
#endif
in4->sin_port = htons(port);
in4->sin_family = AF_INET;
*sl = sizeof(struct sockaddr_in);
Expand Down Expand Up @@ -852,25 +844,21 @@ php_socket_t php_network_connect_socket_to_host(const char *host, unsigned short
union {
struct sockaddr common;
struct sockaddr_in in4;
#if HAVE_IPV6 && HAVE_INET_PTON
#if HAVE_IPV6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#if HAVE_IPV6
#ifdef HAVE_IPV6

struct sockaddr_in6 in6;
#endif
} local_address;
int local_address_len = 0;

if (sa->sa_family == AF_INET) {
#ifdef HAVE_INET_PTON
if (inet_pton(AF_INET, bindto, &local_address.in4.sin_addr) == 1) {
#else
if (inet_aton(bindto, &local_address.in4.sin_addr)) {
#endif
local_address_len = sizeof(struct sockaddr_in);
local_address.in4.sin_family = sa->sa_family;
local_address.in4.sin_port = htons(bindport);
memset(&(local_address.in4.sin_zero), 0, sizeof(local_address.in4.sin_zero));
}
}
#if HAVE_IPV6 && HAVE_INET_PTON
#if HAVE_IPV6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#if HAVE_IPV6
#ifdef HAVE_IPV6

else { /* IPV6 */
if (inet_pton(AF_INET6, bindto, &local_address.in6.sin6_addr) == 1) {
local_address_len = sizeof(struct sockaddr_in6);
Expand Down
5 changes: 0 additions & 5 deletions sapi/litespeed/lsapilib.c
Original file line number Diff line number Diff line change
Expand Up @@ -2688,12 +2688,7 @@ int LSAPI_ParseSockAddr( const char * pBind, struct sockaddr * pAddr )
((struct sockaddr_in *)pAddr)->sin_addr.s_addr = htonl( INADDR_LOOPBACK );
else
{
#ifdef HAVE_INET_PTON
if (!inet_pton(AF_INET, p, &((struct sockaddr_in *)pAddr)->sin_addr))
#else
((struct sockaddr_in *)pAddr)->sin_addr.s_addr = inet_addr( p );
if ( ((struct sockaddr_in *)pAddr)->sin_addr.s_addr == INADDR_BROADCAST)
#endif
{
doAddrInfo = 1;
}
Expand Down
3 changes: 0 additions & 3 deletions win32/build/config.w32.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,6 @@
/* Win32 support proc_open */
#define PHP_CAN_SUPPORT_PROC_OPEN 1

/* inet_pton() */
#define HAVE_INET_PTON 1

/* vs.net 2005 has a 64-bit time_t. This will likely break
* 3rdParty libs that were built with older compilers; switch
* back to 32-bit */
Expand Down