net_socket: getpeername now only works on connected socket
Per POSIX.1-2008, getpeername() shall fails if the socket is not connected. Fixes #15081 Change-Id: Iafaed09df26f47b10efc2ceed6dfa2852857d39a Reviewed-on: https://review.haiku-os.org/c/haiku/+/2549 Reviewed-by: Jérôme Duval <jerome.duval@gmail.com> Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
This commit is contained in:
parent
27ecd4761c
commit
5c63c64bfd
@ -1059,10 +1059,11 @@ socket_connect(net_socket* socket, const struct sockaddr* address,
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
socket_getpeername(net_socket* socket, struct sockaddr* address,
|
socket_getpeername(net_socket* _socket, struct sockaddr* address,
|
||||||
socklen_t* _addressLength)
|
socklen_t* _addressLength)
|
||||||
{
|
{
|
||||||
if (socket->peer.ss_len == 0)
|
net_socket_private* socket = (net_socket_private*)_socket;
|
||||||
|
if (!socket->is_connected || socket->peer.ss_len == 0)
|
||||||
return ENOTCONN;
|
return ENOTCONN;
|
||||||
|
|
||||||
memcpy(address, &socket->peer, min_c(*_addressLength, socket->peer.ss_len));
|
memcpy(address, &socket->peer, min_c(*_addressLength, socket->peer.ss_len));
|
||||||
|
Loading…
Reference in New Issue
Block a user