struct sockaddr **addr, socklen_t *addrlen
TSRMLS_DC)
{
- php_sockaddr_storage sa;
- socklen_t sl = sizeof(sa);
int ret;
int want_addr = textaddr || addr;
if (want_addr) {
+ php_sockaddr_storage sa;
+ socklen_t sl = sizeof(sa);
ret = recvfrom(sock->socket, buf, buflen, flags, (struct sockaddr*)&sa, &sl);
ret = (ret == SOCK_CONN_ERR) ? -1 : ret;
- php_network_populate_name_from_sockaddr((struct sockaddr*)&sa, sl,
- textaddr, textaddrlen, addr, addrlen TSRMLS_CC);
+ if (sl) {
+ php_network_populate_name_from_sockaddr((struct sockaddr*)&sa, sl,
+ textaddr, textaddrlen, addr, addrlen TSRMLS_CC);
+ } else {
+ if (textaddr) {
+ *textaddr = estrndup("", 0);
+ *textaddrlen = 0;
+ }
+ if (addr) {
+ *addr = NULL;
+ *addrlen = 0;
+ }
+ }
} else {
ret = recv(sock->socket, buf, buflen, flags);
ret = (ret == SOCK_CONN_ERR) ? -1 : ret;
ret = recv(sock->socket, &buf, sizeof(buf), MSG_PEEK);
err = php_socket_errno();
if (0 == ret || /* the counterpart did properly shutdown*/
- 0 > ret && err != EWOULDBLOCK && err != EAGAIN) { /* there was an unrecoverable error */
+ (0 > ret && err != EWOULDBLOCK && err != EAGAIN)) { /* there was an unrecoverable error */
alive = 0;
}
}