@@ -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
{
@@ -1072,10 +1074,12 @@ PHP_FUNCTION(socket_getsockname)
1072
1074
struct sockaddr_in * sin ;
1073
1075
#if HAVE_IPV6
1074
1076
struct sockaddr_in6 * sin6 ;
1075
- char addr6 [INET6_ADDRSTRLEN + 1 ];
1077
+ #endif
1078
+ #ifdef HAVE_INET_NTOP
1079
+ char addrbuf [INET6_ADDRSTRLEN ];
1076
1080
#endif
1077
1081
struct sockaddr_un * s_un ;
1078
- char * addr_string ;
1082
+ const char * addr_string ;
1079
1083
socklen_t salen = sizeof (php_sockaddr_storage );
1080
1084
1081
1085
if (zend_parse_parameters (ZEND_NUM_ARGS (), "Oz|z" , & arg1 , socket_ce , & addr , & port ) == FAILURE ) {
@@ -1096,8 +1100,8 @@ PHP_FUNCTION(socket_getsockname)
1096
1100
#if HAVE_IPV6
1097
1101
case AF_INET6 :
1098
1102
sin6 = (struct sockaddr_in6 * ) sa ;
1099
- inet_ntop (AF_INET6 , & sin6 -> sin6_addr , addr6 , INET6_ADDRSTRLEN );
1100
- ZEND_TRY_ASSIGN_REF_STRING (addr , addr6 );
1103
+ inet_ntop (AF_INET6 , & sin6 -> sin6_addr , addrbuf , sizeof ( addrbuf ) );
1104
+ ZEND_TRY_ASSIGN_REF_STRING (addr , addrbuf );
1101
1105
1102
1106
if (port != NULL ) {
1103
1107
ZEND_TRY_ASSIGN_REF_LONG (port , htons (sin6 -> sin6_port ));
@@ -1107,11 +1111,14 @@ PHP_FUNCTION(socket_getsockname)
1107
1111
#endif
1108
1112
case AF_INET :
1109
1113
sin = (struct sockaddr_in * ) sa ;
1114
+ #ifdef HAVE_INET_NTOP
1115
+ addr_string = inet_ntop (AF_INET , & sin -> sin_addr , addrbuf , sizeof (addrbuf ));
1116
+ #else
1110
1117
while (inet_ntoa_lock == 1 );
1111
1118
inet_ntoa_lock = 1 ;
1112
1119
addr_string = inet_ntoa (sin -> sin_addr );
1113
1120
inet_ntoa_lock = 0 ;
1114
-
1121
+ #endif
1115
1122
ZEND_TRY_ASSIGN_REF_STRING (addr , addr_string );
1116
1123
1117
1124
if (port != NULL ) {
@@ -1144,10 +1151,12 @@ PHP_FUNCTION(socket_getpeername)
1144
1151
struct sockaddr_in * sin ;
1145
1152
#if HAVE_IPV6
1146
1153
struct sockaddr_in6 * sin6 ;
1147
- char addr6 [INET6_ADDRSTRLEN + 1 ];
1154
+ #endif
1155
+ #ifdef HAVE_INET_NTOP
1156
+ char addrbuf [INET6_ADDRSTRLEN ];
1148
1157
#endif
1149
1158
struct sockaddr_un * s_un ;
1150
- char * addr_string ;
1159
+ const char * addr_string ;
1151
1160
socklen_t salen = sizeof (php_sockaddr_storage );
1152
1161
1153
1162
if (zend_parse_parameters (ZEND_NUM_ARGS (), "Oz|z" , & arg1 , socket_ce , & arg2 , & arg3 ) == FAILURE ) {
@@ -1168,9 +1177,9 @@ PHP_FUNCTION(socket_getpeername)
1168
1177
#if HAVE_IPV6
1169
1178
case AF_INET6 :
1170
1179
sin6 = (struct sockaddr_in6 * ) sa ;
1171
- inet_ntop (AF_INET6 , & sin6 -> sin6_addr , addr6 , INET6_ADDRSTRLEN );
1180
+ inet_ntop (AF_INET6 , & sin6 -> sin6_addr , addrbuf , sizeof ( addrbuf ) );
1172
1181
1173
- ZEND_TRY_ASSIGN_REF_STRING (arg2 , addr6 );
1182
+ ZEND_TRY_ASSIGN_REF_STRING (arg2 , addrbuf );
1174
1183
1175
1184
if (arg3 != NULL ) {
1176
1185
ZEND_TRY_ASSIGN_REF_LONG (arg3 , htons (sin6 -> sin6_port ));
@@ -1181,11 +1190,14 @@ PHP_FUNCTION(socket_getpeername)
1181
1190
#endif
1182
1191
case AF_INET :
1183
1192
sin = (struct sockaddr_in * ) sa ;
1193
+ #ifdef HAVE_INET_NTOP
1194
+ addr_string = inet_ntop (AF_INET , & sin -> sin_addr , addrbuf , sizeof (addrbuf ));
1195
+ #else
1184
1196
while (inet_ntoa_lock == 1 );
1185
1197
inet_ntoa_lock = 1 ;
1186
1198
addr_string = inet_ntoa (sin -> sin_addr );
1187
1199
inet_ntoa_lock = 0 ;
1188
-
1200
+ #endif
1189
1201
ZEND_TRY_ASSIGN_REF_STRING (arg2 , addr_string );
1190
1202
1191
1203
if (arg3 != NULL ) {
@@ -1517,12 +1529,14 @@ PHP_FUNCTION(socket_recvfrom)
1517
1529
struct sockaddr_in sin ;
1518
1530
#if HAVE_IPV6
1519
1531
struct sockaddr_in6 sin6 ;
1520
- char addr6 [INET6_ADDRSTRLEN ];
1532
+ #endif
1533
+ #ifdef HAVE_INET_NTOP
1534
+ char addrbuf [INET6_ADDRSTRLEN ];
1521
1535
#endif
1522
1536
socklen_t slen ;
1523
1537
int retval ;
1524
1538
zend_long arg3 , arg4 ;
1525
- char * address ;
1539
+ const char * address ;
1526
1540
zend_string * recv_buf ;
1527
1541
1528
1542
if (zend_parse_parameters (ZEND_NUM_ARGS (), "Ozllz|z" , & arg1 , socket_ce , & arg2 , & arg3 , & arg4 , & arg5 , & arg6 ) == FAILURE ) {
@@ -1580,7 +1594,11 @@ PHP_FUNCTION(socket_recvfrom)
1580
1594
ZSTR_LEN (recv_buf ) = retval ;
1581
1595
ZSTR_VAL (recv_buf )[ZSTR_LEN (recv_buf )] = '\0' ;
1582
1596
1597
+ #ifdef HAVE_INET_NTOP
1598
+ address = inet_ntop (AF_INET , & sin .sin_addr , addrbuf , sizeof (addrbuf ));
1599
+ #else
1583
1600
address = inet_ntoa (sin .sin_addr );
1601
+ #endif
1584
1602
1585
1603
ZEND_TRY_ASSIGN_REF_NEW_STR (arg2 , recv_buf );
1586
1604
ZEND_TRY_ASSIGN_REF_STRING (arg5 , address ? address : "0.0.0.0" );
@@ -1607,11 +1625,11 @@ PHP_FUNCTION(socket_recvfrom)
1607
1625
ZSTR_LEN (recv_buf ) = retval ;
1608
1626
ZSTR_VAL (recv_buf )[ZSTR_LEN (recv_buf )] = '\0' ;
1609
1627
1610
- memset (addr6 , 0 , INET6_ADDRSTRLEN );
1611
- inet_ntop (AF_INET6 , & sin6 .sin6_addr , addr6 , INET6_ADDRSTRLEN );
1628
+ memset (addrbuf , 0 , INET6_ADDRSTRLEN );
1629
+ inet_ntop (AF_INET6 , & sin6 .sin6_addr , addrbuf , sizeof ( addrbuf ) );
1612
1630
1613
1631
ZEND_TRY_ASSIGN_REF_NEW_STR (arg2 , recv_buf );
1614
- ZEND_TRY_ASSIGN_REF_STRING (arg5 , addr6 [0 ] ? addr6 : "::" );
1632
+ ZEND_TRY_ASSIGN_REF_STRING (arg5 , addrbuf [0 ] ? addrbuf : "::" );
1615
1633
ZEND_TRY_ASSIGN_REF_LONG (arg6 , ntohs (sin6 .sin6_port ));
1616
1634
break ;
1617
1635
#endif
0 commit comments