From fc13358acaedb01acb49bde822649040fdcf9fd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Sun, 14 May 2023 14:46:18 +0200 Subject: [PATCH] net_socket: getpeername: IsConnected() when parent is not set this fixes a test in libuv Change-Id: I3002f9c44794ff3f8215ebc000fefa0f90b80279 Reviewed-on: https://review.haiku-os.org/c/haiku/+/6455 Reviewed-by: waddlesplash Tested-by: Commit checker robot --- src/add-ons/kernel/network/stack/net_socket.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/add-ons/kernel/network/stack/net_socket.cpp b/src/add-ons/kernel/network/stack/net_socket.cpp index 62775b14e0..8e431113cb 100644 --- a/src/add-ons/kernel/network/stack/net_socket.cpp +++ b/src/add-ons/kernel/network/stack/net_socket.cpp @@ -1050,7 +1050,11 @@ socket_getpeername(net_socket* _socket, struct sockaddr* address, socklen_t* _addressLength) { net_socket_private* socket = (net_socket_private*)_socket; - if (!socket->is_connected || socket->peer.ss_len == 0) + BReference parent; + if (socket->parent.PrivatePointer() != NULL) + parent = socket->parent.GetReference(); + + if ((!parent.IsSet() && !socket->is_connected) || socket->peer.ss_len == 0) return ENOTCONN; memcpy(address, &socket->peer, min_c(*_addressLength, socket->peer.ss_len));