mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
following-up on GH-12551: removing inet_ntoa usage
Close GH-12554
This commit is contained in:
7
NEWS
7
NEWS
@@ -11,6 +11,9 @@ DOM:
|
||||
(nielsdos)
|
||||
. Fix cloning attribute with namespace disappearing namespace. (nielsdos)
|
||||
|
||||
FTP:
|
||||
. Removed the deprecated inet_ntoa call support. (David Carlier)
|
||||
|
||||
Intl:
|
||||
. Added IntlDateFormatter::PATTERN constant. (David Carlier)
|
||||
|
||||
@@ -36,6 +39,9 @@ SimpleXML:
|
||||
foreach). (nielsdos)
|
||||
. Fixed bug #55098 (SimpleXML iteration produces infinite loop). (nielsdos)
|
||||
|
||||
SNMP:
|
||||
. Removed the deprecated inet_ntoa call support. (David Carlier)
|
||||
|
||||
SOAP:
|
||||
. Add support for clark notation for namespaces in class map. (lxShaDoWxl)
|
||||
. Mitigate #51561 (SoapServer with a extented class and using sessions,
|
||||
@@ -52,6 +58,7 @@ Standard:
|
||||
. Increase the default BCrypt cost to 12. (timwolla)
|
||||
. Fixed bug GH-12592 (strcspn() odd behaviour with NUL bytes and empty mask).
|
||||
(nielsdos)
|
||||
. Removed the deprecated inet_ntoa call support. (David Carlier)
|
||||
|
||||
XML:
|
||||
. Added XML_OPTION_PARSE_HUGE parser option. (nielsdos)
|
||||
|
||||
@@ -609,7 +609,6 @@ getgrnam_r \
|
||||
getpwuid_r \
|
||||
getwd \
|
||||
glob \
|
||||
inet_ntoa \
|
||||
inet_ntop \
|
||||
inet_pton \
|
||||
localtime_r \
|
||||
|
||||
@@ -56,6 +56,10 @@
|
||||
#include <openssl/err.h>
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_INET_NTOP
|
||||
#error inet_ntop unsupported on this platform
|
||||
#endif
|
||||
|
||||
#include "ftp.h"
|
||||
#include "ext/standard/fsock.h"
|
||||
|
||||
@@ -1685,13 +1689,16 @@ ftp_getdata(ftpbuf_t *ftp)
|
||||
|
||||
data->listener = fd;
|
||||
|
||||
#if defined(HAVE_IPV6) && defined(HAVE_INET_NTOP)
|
||||
#if defined(HAVE_IPV6)
|
||||
if (sa->sa_family == AF_INET6) {
|
||||
/* need to use EPRT */
|
||||
char eprtarg[INET6_ADDRSTRLEN + sizeof("|x||xxxxx|")];
|
||||
char out[INET6_ADDRSTRLEN];
|
||||
int eprtarg_len;
|
||||
inet_ntop(AF_INET6, &((struct sockaddr_in6*) sa)->sin6_addr, out, sizeof(out));
|
||||
if (!inet_ntop(AF_INET6, &((struct sockaddr_in6*) sa)->sin6_addr, out, sizeof(out))) {
|
||||
goto bail;
|
||||
}
|
||||
|
||||
eprtarg_len = snprintf(eprtarg, sizeof(eprtarg), "|2|%s|%hu|", out, ntohs(((struct sockaddr_in6 *) &addr)->sin6_port));
|
||||
|
||||
if (eprtarg_len < 0) {
|
||||
|
||||
@@ -51,6 +51,10 @@
|
||||
#endif
|
||||
#include <locale.h>
|
||||
|
||||
#ifndef HAVE_INET_NTOP
|
||||
#error inet_ntop unsupported on this platform
|
||||
#endif
|
||||
|
||||
#ifndef __P
|
||||
#ifdef __GNUC__
|
||||
#define __P(args) args
|
||||
@@ -843,7 +847,7 @@ static bool netsnmp_session_init(php_snmp_session **session_p, int version, zend
|
||||
res = psal;
|
||||
while (n-- > 0) {
|
||||
pptr = session->peername;
|
||||
#if defined(HAVE_GETADDRINFO) && defined(HAVE_IPV6) && defined(HAVE_INET_NTOP)
|
||||
#if defined(HAVE_GETADDRINFO) && defined(HAVE_IPV6)
|
||||
if (force_ipv6 && (*res)->sa_family != AF_INET6) {
|
||||
res++;
|
||||
continue;
|
||||
@@ -859,12 +863,6 @@ static bool netsnmp_session_init(php_snmp_session **session_p, int version, zend
|
||||
res++;
|
||||
continue;
|
||||
}
|
||||
#else
|
||||
if ((*res)->sa_family != AF_INET) {
|
||||
res++;
|
||||
continue;
|
||||
}
|
||||
strcat(pptr, inet_ntoa(((struct sockaddr_in*)(*res))->sin_addr));
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -927,9 +927,7 @@ PHP_FUNCTION(socket_getsockname)
|
||||
#if HAVE_IPV6
|
||||
struct sockaddr_in6 *sin6;
|
||||
#endif
|
||||
#ifdef HAVE_INET_NTOP
|
||||
char addrbuf[INET6_ADDRSTRLEN];
|
||||
#endif
|
||||
struct sockaddr_un *s_un;
|
||||
const char *addr_string;
|
||||
socklen_t salen = sizeof(php_sockaddr_storage);
|
||||
@@ -997,9 +995,7 @@ PHP_FUNCTION(socket_getpeername)
|
||||
#if HAVE_IPV6
|
||||
struct sockaddr_in6 *sin6;
|
||||
#endif
|
||||
#ifdef HAVE_INET_NTOP
|
||||
char addrbuf[INET6_ADDRSTRLEN];
|
||||
#endif
|
||||
struct sockaddr_un *s_un;
|
||||
const char *addr_string;
|
||||
socklen_t salen = sizeof(php_sockaddr_storage);
|
||||
|
||||
@@ -102,6 +102,10 @@ typedef struct yy_buffer_state *YY_BUFFER_STATE;
|
||||
# define INADDR_NONE ((zend_ulong) -1)
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_INET_NTOP
|
||||
# error inet_ntop unsupported on this platform
|
||||
#endif
|
||||
|
||||
#include "zend_globals.h"
|
||||
#include "php_globals.h"
|
||||
#include "SAPI.h"
|
||||
@@ -531,7 +535,6 @@ PHP_FUNCTION(constant)
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
#ifdef HAVE_INET_NTOP
|
||||
/* {{{ Converts a packed inet address to a human readable IP address string */
|
||||
PHP_FUNCTION(inet_ntop)
|
||||
{
|
||||
@@ -560,7 +563,6 @@ PHP_FUNCTION(inet_ntop)
|
||||
RETURN_STRING(buffer);
|
||||
}
|
||||
/* }}} */
|
||||
#endif /* HAVE_INET_NTOP */
|
||||
|
||||
#ifdef HAVE_INET_PTON
|
||||
/* {{{ Converts a human readable IP address to a packed binary string */
|
||||
@@ -652,15 +654,11 @@ PHP_FUNCTION(long2ip)
|
||||
ip = (zend_ulong)sip;
|
||||
|
||||
myaddr.s_addr = htonl(ip);
|
||||
#ifdef HAVE_INET_PTON
|
||||
if (inet_ntop(AF_INET, &myaddr, str, sizeof(str))) {
|
||||
RETURN_STRING(str);
|
||||
} else {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
#else
|
||||
RETURN_STRING(inet_ntoa(myaddr));
|
||||
#endif
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
@@ -57,6 +57,10 @@ extern void __res_ndestroy(res_state statp);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_INET_NTOP
|
||||
#error inet_ntop unsupported on this platform
|
||||
#endif
|
||||
|
||||
#ifndef MAXHOSTNAMELEN
|
||||
#define MAXHOSTNAMELEN 255
|
||||
#endif
|
||||
@@ -221,6 +225,7 @@ PHP_FUNCTION(gethostbyname)
|
||||
{
|
||||
char *hostname;
|
||||
size_t hostname_len;
|
||||
zend_string *ipaddr;
|
||||
|
||||
ZEND_PARSE_PARAMETERS_START(1, 1)
|
||||
Z_PARAM_PATH(hostname, hostname_len)
|
||||
@@ -232,7 +237,12 @@ PHP_FUNCTION(gethostbyname)
|
||||
RETURN_STRINGL(hostname, hostname_len);
|
||||
}
|
||||
|
||||
RETURN_STR(php_gethostbyname(hostname));
|
||||
if (!(ipaddr = php_gethostbyname(hostname))) {
|
||||
php_error_docref(NULL, E_WARNING, "Host name to ip failed %s", hostname);
|
||||
RETURN_STRINGL(hostname, hostname_len);
|
||||
} else {
|
||||
RETURN_STR(ipaddr);
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
@@ -244,9 +254,7 @@ PHP_FUNCTION(gethostbynamel)
|
||||
struct hostent *hp;
|
||||
struct in_addr in;
|
||||
int i;
|
||||
#ifdef HAVE_INET_NTOP
|
||||
char addr4[INET_ADDRSTRLEN];
|
||||
#endif
|
||||
|
||||
ZEND_PARSE_PARAMETERS_START(1, 1)
|
||||
Z_PARAM_PATH(hostname, hostname_len)
|
||||
@@ -267,6 +275,7 @@ PHP_FUNCTION(gethostbynamel)
|
||||
|
||||
for (i = 0;; i++) {
|
||||
/* On macos h_addr_list entries may be misaligned. */
|
||||
const char *ipaddr;
|
||||
struct in_addr *h_addr_entry; /* Don't call this h_addr, it's a macro! */
|
||||
memcpy(&h_addr_entry, &hp->h_addr_list[i], sizeof(struct in_addr *));
|
||||
if (!h_addr_entry) {
|
||||
@@ -274,11 +283,13 @@ PHP_FUNCTION(gethostbynamel)
|
||||
}
|
||||
|
||||
in = *h_addr_entry;
|
||||
#ifdef HAVE_INET_NTOP
|
||||
add_next_index_string(return_value, inet_ntop(AF_INET, &in, addr4, INET_ADDRSTRLEN));
|
||||
#else
|
||||
add_next_index_string(return_value, inet_ntoa(in));
|
||||
#endif
|
||||
if (!(ipaddr = inet_ntop(AF_INET, &in, addr4, INET_ADDRSTRLEN))) {
|
||||
/* unlikely regarding (too) long hostname and protocols but checking still */
|
||||
php_error_docref(NULL, E_WARNING, "Host name to ip failed %s", hostname);
|
||||
continue;
|
||||
} else {
|
||||
add_next_index_string(return_value, ipaddr);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
@@ -289,9 +300,7 @@ static zend_string *php_gethostbyname(char *name)
|
||||
struct hostent *hp;
|
||||
struct in_addr *h_addr_0; /* Don't call this h_addr, it's a macro! */
|
||||
struct in_addr in;
|
||||
#ifdef HAVE_INET_NTOP
|
||||
char addr4[INET_ADDRSTRLEN];
|
||||
#endif
|
||||
const char *address;
|
||||
|
||||
hp = php_network_gethostbyname(name);
|
||||
@@ -307,11 +316,10 @@ static zend_string *php_gethostbyname(char *name)
|
||||
|
||||
memcpy(&in.s_addr, h_addr_0, sizeof(in.s_addr));
|
||||
|
||||
#ifdef HAVE_INET_NTOP
|
||||
address = inet_ntop(AF_INET, &in, addr4, INET_ADDRSTRLEN);
|
||||
#else
|
||||
address = inet_ntoa(in);
|
||||
#endif
|
||||
if (!(address = inet_ntop(AF_INET, &in, addr4, INET_ADDRSTRLEN))) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return zend_string_init(address, strlen(address), 0);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <windows.h>
|
||||
#include <Winbase.h >
|
||||
#include <Windns.h>
|
||||
#include <Ws2tcpip.h>
|
||||
|
||||
#include "php_dns.h"
|
||||
|
||||
@@ -174,9 +175,14 @@ static void php_parserr(PDNS_RECORD pRec, int type_to_fetch, int store, bool raw
|
||||
switch (type) {
|
||||
case DNS_TYPE_A: {
|
||||
IN_ADDR ipaddr;
|
||||
char ip[INET_ADDRSTRLEN];
|
||||
ipaddr.S_un.S_addr = (pRec->Data.A.IpAddress);
|
||||
add_assoc_string(subarray, "type", "A");
|
||||
add_assoc_string(subarray, "ip", inet_ntoa(ipaddr));
|
||||
if (!inet_ntop(AF_INET, &ipaddr, ip, INET_ADDRSTRLEN)) {
|
||||
ZVAL_UNDEF(subarray);
|
||||
} else {
|
||||
add_assoc_string(subarray, "type", "A");
|
||||
add_assoc_string(subarray, "ip", ip);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -47,13 +47,15 @@
|
||||
# include <netdb.h>
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_INET_NTOP
|
||||
#error inet_ntop unsupported on this platform
|
||||
#endif
|
||||
|
||||
PHPAPI zend_string* php_inet_ntop(const struct sockaddr *addr) {
|
||||
socklen_t addrlen = sizeof(struct sockaddr_in);
|
||||
|
||||
if (!addr) { return NULL; }
|
||||
|
||||
/* Prefer inet_ntop() as it's more task-specific and doesn't have to be demangled */
|
||||
#ifdef HAVE_INET_NTOP
|
||||
switch (addr->sa_family) {
|
||||
#ifdef AF_INET6
|
||||
case AF_INET6: {
|
||||
@@ -76,7 +78,6 @@ PHPAPI zend_string* php_inet_ntop(const struct sockaddr *addr) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Fallback on getnameinfo() */
|
||||
switch (addr->sa_family) {
|
||||
|
||||
@@ -60,6 +60,10 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_INET_NTOP
|
||||
#error inet_ntop unsupported on this platform
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_INET_ATON
|
||||
int inet_aton(const char *, struct in_addr *);
|
||||
#endif
|
||||
@@ -620,19 +624,13 @@ PHPAPI void php_network_populate_name_from_sockaddr(
|
||||
}
|
||||
|
||||
if (textaddr) {
|
||||
#ifdef HAVE_INET_NTOP
|
||||
char abuf[256];
|
||||
#endif
|
||||
const char *buf = NULL;
|
||||
|
||||
switch (sa->sa_family) {
|
||||
case AF_INET:
|
||||
/* generally not thread safe, but it *is* thread safe under win32 */
|
||||
#ifdef HAVE_INET_NTOP
|
||||
buf = inet_ntop(AF_INET, &((struct sockaddr_in*)sa)->sin_addr, (char *)&abuf, sizeof(abuf));
|
||||
#else
|
||||
buf = inet_ntoa(((struct sockaddr_in*)sa)->sin_addr);
|
||||
#endif
|
||||
if (buf) {
|
||||
*textaddr = strpprintf(0, "%s:%d",
|
||||
buf, ntohs(((struct sockaddr_in*)sa)->sin_port));
|
||||
@@ -640,7 +638,7 @@ PHPAPI void php_network_populate_name_from_sockaddr(
|
||||
|
||||
break;
|
||||
|
||||
#if HAVE_IPV6 && HAVE_INET_NTOP
|
||||
#if HAVE_IPV6
|
||||
case AF_INET6:
|
||||
buf = (char*)inet_ntop(sa->sa_family, &((struct sockaddr_in6*)sa)->sin6_addr, (char *)&abuf, sizeof(abuf));
|
||||
if (buf) {
|
||||
|
||||
Reference in New Issue
Block a user