@@ -597,41 +597,25 @@ void s_handle_memcached_event (evutil_socket_t fd, short what, void *arg)
597597
598598 if (!client -> on_connect_invoked ) {
599599 if (MEMC_HAS_CB (MEMC_SERVER_ON_CONNECT )) {
600- zval zremoteip , zremoteport ;
601- zval params [2 ];
600+ zend_string * zremoteaddr_str ;
601+ zval zremoteaddr ;
602+ zval params [1 ];
602603 protocol_binary_response_status retval ;
603- struct sockaddr_storage ss ;
604- socklen_t ss_len = sizeof (ss );
605-
606- ZVAL_NULL (& zremoteip );
607- ZVAL_NULL (& zremoteport );
608-
609- if (getpeername (fd , (struct sockaddr * ) & ss , & ss_len ) == 0 ) {
610- char addr_buf [0x100 ];
611-
612- switch (ss .ss_family ) {
613- case AF_INET6 :
614- ZVAL_STRING (& zremoteip , inet_ntop (ss .ss_family , & ((struct sockaddr_in6 * ) & ss )-> sin6_addr , addr_buf , sizeof (addr_buf )));
615- ZVAL_LONG (& zremoteport , ntohs (((struct sockaddr_in6 * ) & ss )-> sin6_port ));
616- break ;
617- case AF_INET :
618- ZVAL_STRING (& zremoteip , inet_ntop (ss .ss_family , & ((struct sockaddr_in * ) & ss )-> sin_addr , addr_buf , sizeof (addr_buf )));
619- ZVAL_LONG (& zremoteport , ntohs (((struct sockaddr_in * ) & ss )-> sin_port ));
620- break ;
621- }
604+
605+ ZVAL_NULL (& zremoteaddr );
606+
607+ if (SUCCESS == php_network_get_peer_name (fd , & zremoteaddr_str , NULL , NULL )) {
608+ ZVAL_STR (& zremoteaddr , zremoteaddr_str );
622609 } else {
623610 php_error_docref (NULL , E_WARNING , "getpeername failed: %s" , strerror (errno ));
624611 }
625612
626- ZVAL_COPY (& params [0 ], & zremoteip );
627- ZVAL_COPY (& params [1 ], & zremoteport );
613+ ZVAL_COPY (& params [0 ], & zremoteaddr );
628614
629- retval = s_invoke_php_callback (& MEMC_GET_CB (MEMC_SERVER_ON_CONNECT ), params , 2 );
615+ retval = s_invoke_php_callback (& MEMC_GET_CB (MEMC_SERVER_ON_CONNECT ), params , 1 );
630616
631617 zval_ptr_dtor (& params [0 ]);
632- zval_ptr_dtor (& params [1 ]);
633- zval_ptr_dtor (& zremoteip );
634- zval_ptr_dtor (& zremoteport );
618+ zval_ptr_dtor (& zremoteaddr );
635619
636620 if (retval != PROTOCOL_BINARY_RESPONSE_SUCCESS ) {
637621 memcached_protocol_client_destroy (client -> protocol_client );
0 commit comments