@@ -220,8 +220,10 @@ zend_module_entry sockets_module_entry = {
220
220
ZEND_GET_MODULE (sockets )
221
221
#endif
222
222
223
+ #ifndef HAVE_INET_NTOP
223
224
/* inet_ntop should be used instead of inet_ntoa */
224
225
int inet_ntoa_lock = 0 ;
226
+ #endif
225
227
226
228
static int php_open_listen_sock (php_socket * sock , int port , int backlog ) /* {{{ */
227
229
{
@@ -1082,10 +1084,12 @@ PHP_FUNCTION(socket_getsockname)
1082
1084
struct sockaddr_in * sin ;
1083
1085
#if HAVE_IPV6
1084
1086
struct sockaddr_in6 * sin6 ;
1085
- char addr6 [INET6_ADDRSTRLEN + 1 ];
1087
+ #endif
1088
+ #ifdef HAVE_INET_NTOP
1089
+ char addrbuf [INET6_ADDRSTRLEN ];
1086
1090
#endif
1087
1091
struct sockaddr_un * s_un ;
1088
- char * addr_string ;
1092
+ const char * addr_string ;
1089
1093
socklen_t salen = sizeof (php_sockaddr_storage );
1090
1094
1091
1095
if (zend_parse_parameters (ZEND_NUM_ARGS (), "Oz|z" , & arg1 , socket_ce , & addr , & port ) == FAILURE ) {
@@ -1106,8 +1110,8 @@ PHP_FUNCTION(socket_getsockname)
1106
1110
#if HAVE_IPV6
1107
1111
case AF_INET6 :
1108
1112
sin6 = (struct sockaddr_in6 * ) sa ;
1109
- inet_ntop (AF_INET6 , & sin6 -> sin6_addr , addr6 , INET6_ADDRSTRLEN );
1110
- ZEND_TRY_ASSIGN_REF_STRING (addr , addr6 );
1113
+ inet_ntop (AF_INET6 , & sin6 -> sin6_addr , addrbuf , sizeof ( addrbuf ) );
1114
+ ZEND_TRY_ASSIGN_REF_STRING (addr , addrbuf );
1111
1115
1112
1116
if (port != NULL ) {
1113
1117
ZEND_TRY_ASSIGN_REF_LONG (port , htons (sin6 -> sin6_port ));
@@ -1117,11 +1121,14 @@ PHP_FUNCTION(socket_getsockname)
1117
1121
#endif
1118
1122
case AF_INET :
1119
1123
sin = (struct sockaddr_in * ) sa ;
1124
+ #ifdef HAVE_INET_NTOP
1125
+ addr_string = inet_ntop (AF_INET , & sin -> sin_addr , addrbuf , sizeof (addrbuf ));
1126
+ #else
1120
1127
while (inet_ntoa_lock == 1 );
1121
1128
inet_ntoa_lock = 1 ;
1122
1129
addr_string = inet_ntoa (sin -> sin_addr );
1123
1130
inet_ntoa_lock = 0 ;
1124
-
1131
+ #endif
1125
1132
ZEND_TRY_ASSIGN_REF_STRING (addr , addr_string );
1126
1133
1127
1134
if (port != NULL ) {
@@ -1154,10 +1161,12 @@ PHP_FUNCTION(socket_getpeername)
1154
1161
struct sockaddr_in * sin ;
1155
1162
#if HAVE_IPV6
1156
1163
struct sockaddr_in6 * sin6 ;
1157
- char addr6 [INET6_ADDRSTRLEN + 1 ];
1164
+ #endif
1165
+ #ifdef HAVE_INET_NTOP
1166
+ char addrbuf [INET6_ADDRSTRLEN ];
1158
1167
#endif
1159
1168
struct sockaddr_un * s_un ;
1160
- char * addr_string ;
1169
+ const char * addr_string ;
1161
1170
socklen_t salen = sizeof (php_sockaddr_storage );
1162
1171
1163
1172
if (zend_parse_parameters (ZEND_NUM_ARGS (), "Oz|z" , & arg1 , socket_ce , & arg2 , & arg3 ) == FAILURE ) {
@@ -1178,9 +1187,9 @@ PHP_FUNCTION(socket_getpeername)
1178
1187
#if HAVE_IPV6
1179
1188
case AF_INET6 :
1180
1189
sin6 = (struct sockaddr_in6 * ) sa ;
1181
- inet_ntop (AF_INET6 , & sin6 -> sin6_addr , addr6 , INET6_ADDRSTRLEN );
1190
+ inet_ntop (AF_INET6 , & sin6 -> sin6_addr , addrbuf , sizeof ( addrbuf ) );
1182
1191
1183
- ZEND_TRY_ASSIGN_REF_STRING (arg2 , addr6 );
1192
+ ZEND_TRY_ASSIGN_REF_STRING (arg2 , addrbuf );
1184
1193
1185
1194
if (arg3 != NULL ) {
1186
1195
ZEND_TRY_ASSIGN_REF_LONG (arg3 , htons (sin6 -> sin6_port ));
@@ -1191,11 +1200,14 @@ PHP_FUNCTION(socket_getpeername)
1191
1200
#endif
1192
1201
case AF_INET :
1193
1202
sin = (struct sockaddr_in * ) sa ;
1203
+ #ifdef HAVE_INET_NTOP
1204
+ addr_string = inet_ntop (AF_INET , & sin -> sin_addr , addrbuf , sizeof (addrbuf ));
1205
+ #else
1194
1206
while (inet_ntoa_lock == 1 );
1195
1207
inet_ntoa_lock = 1 ;
1196
1208
addr_string = inet_ntoa (sin -> sin_addr );
1197
1209
inet_ntoa_lock = 0 ;
1198
-
1210
+ #endif
1199
1211
ZEND_TRY_ASSIGN_REF_STRING (arg2 , addr_string );
1200
1212
1201
1213
if (arg3 != NULL ) {
@@ -1527,12 +1539,14 @@ PHP_FUNCTION(socket_recvfrom)
1527
1539
struct sockaddr_in sin ;
1528
1540
#if HAVE_IPV6
1529
1541
struct sockaddr_in6 sin6 ;
1530
- char addr6 [INET6_ADDRSTRLEN ];
1542
+ #endif
1543
+ #ifdef HAVE_INET_NTOP
1544
+ char addrbuf [INET6_ADDRSTRLEN ];
1531
1545
#endif
1532
1546
socklen_t slen ;
1533
1547
int retval ;
1534
1548
zend_long arg3 , arg4 ;
1535
- char * address ;
1549
+ const char * address ;
1536
1550
zend_string * recv_buf ;
1537
1551
1538
1552
if (zend_parse_parameters (ZEND_NUM_ARGS (), "Ozllz|z" , & arg1 , socket_ce , & arg2 , & arg3 , & arg4 , & arg5 , & arg6 ) == FAILURE ) {
@@ -1590,7 +1604,11 @@ PHP_FUNCTION(socket_recvfrom)
1590
1604
ZSTR_LEN (recv_buf ) = retval ;
1591
1605
ZSTR_VAL (recv_buf )[ZSTR_LEN (recv_buf )] = '\0' ;
1592
1606
1607
+ #ifdef HAVE_INET_NTOP
1608
+ address = inet_ntop (AF_INET , & sin .sin_addr , addrbuf , sizeof (addrbuf ));
1609
+ #else
1593
1610
address = inet_ntoa (sin .sin_addr );
1611
+ #endif
1594
1612
1595
1613
ZEND_TRY_ASSIGN_REF_NEW_STR (arg2 , recv_buf );
1596
1614
ZEND_TRY_ASSIGN_REF_STRING (arg5 , address ? address : "0.0.0.0" );
@@ -1617,11 +1635,11 @@ PHP_FUNCTION(socket_recvfrom)
1617
1635
ZSTR_LEN (recv_buf ) = retval ;
1618
1636
ZSTR_VAL (recv_buf )[ZSTR_LEN (recv_buf )] = '\0' ;
1619
1637
1620
- memset (addr6 , 0 , INET6_ADDRSTRLEN );
1621
- inet_ntop (AF_INET6 , & sin6 .sin6_addr , addr6 , INET6_ADDRSTRLEN );
1638
+ memset (addrbuf , 0 , INET6_ADDRSTRLEN );
1639
+ inet_ntop (AF_INET6 , & sin6 .sin6_addr , addrbuf , sizeof ( addrbuf ) );
1622
1640
1623
1641
ZEND_TRY_ASSIGN_REF_NEW_STR (arg2 , recv_buf );
1624
- ZEND_TRY_ASSIGN_REF_STRING (arg5 , addr6 [0 ] ? addr6 : "::" );
1642
+ ZEND_TRY_ASSIGN_REF_STRING (arg5 , addrbuf [0 ] ? addrbuf : "::" );
1625
1643
ZEND_TRY_ASSIGN_REF_LONG (arg6 , ntohs (sin6 .sin6_port ));
1626
1644
break ;
1627
1645
#endif
0 commit comments