[haiku-commits] Change in haiku[master]: network/stack: Fail with EINVAL if socket is already bound.

  • From: Gerrit <review@xxxxxxxxxxxxxxxxxxx>
  • To: waddlesplash <waddlesplash@xxxxxxxxx>, haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 26 Jun 2022 15:47:04 +0000

From Trung Nguyen <trungnt282910@xxxxxxxxx>:

Trung Nguyen has uploaded this change for review. ( 
https://review.haiku-os.org/c/haiku/+/5402 ;)


Change subject: network/stack: Fail with EINVAL if socket is already bound.
......................................................................

network/stack: Fail with EINVAL if socket is already bound.

This is to comply with POSIX standard. Some applications, such as
krb5's rpc library, requires this behavior to work.

Change-Id: I3000794c2c5e21774e70dfb5a526c3f63af521bc
---
M src/add-ons/kernel/network/stack/net_socket.cpp
1 file changed, 6 insertions(+), 4 deletions(-)



  git pull ssh://git.haiku-os.org:22/haiku refs/changes/02/5402/1

diff --git a/src/add-ons/kernel/network/stack/net_socket.cpp 
b/src/add-ons/kernel/network/stack/net_socket.cpp
index 59ecb30..74e6bc4 100644
--- a/src/add-ons/kernel/network/stack/net_socket.cpp
+++ b/src/add-ons/kernel/network/stack/net_socket.cpp
@@ -1007,10 +1007,12 @@
        }

        if (socket->address.ss_len != 0) {
-               status_t status = 
socket->first_info->unbind(socket->first_protocol,
-                       (sockaddr*)&socket->address);
-               if (status != B_OK)
-                       return status;
+               // According to POSIX: The bind() function shall fail if:
+               // [EINVAL]
+               // The socket is already bound to an address, and the protocol
+               // does not support binding to a new address; or the socket has
+               // been shut down.
+               return B_BAD_VALUE;
        }

        memcpy(&socket->address, address, sizeof(sockaddr));

--
To view, visit https://review.haiku-os.org/c/haiku/+/5402
To unsubscribe, or for help writing mail filters, visit 
https://review.haiku-os.org/settings

Gerrit-Project: haiku
Gerrit-Branch: master
Gerrit-Change-Id: I3000794c2c5e21774e70dfb5a526c3f63af521bc
Gerrit-Change-Number: 5402
Gerrit-PatchSet: 1
Gerrit-Owner: Trung Nguyen <trungnt282910@xxxxxxxxx>
Gerrit-MessageType: newchange

Other related posts:

  • » [haiku-commits] Change in haiku[master]: network/stack: Fail with EINVAL if socket is already bound. - Gerrit