From 4925e22a679871935a2951d98e85e31802ea6fd7 Mon Sep 17 00:00:00 2001 From: Noah Olson Date: Fri, 4 Apr 2025 11:03:16 -0600 Subject: [PATCH] net: nsos_sockets: Fix incorrect return return on ECONNREFUSED `nsos_connect_blocking()` is not returning the error as expected. It is expected to return a negative `NSI_ERRNO_MID_...` value, but it is returning a positive errno value. `nsos_connect_blocking()` should map the errno value to a negative `NSI_ERRNO_MID_...`, which `nsos_connect()` maps back to a -1 return with errno=`ECONNREFUSED`. the current sequence of events: - `ECONNREFUSED` occurs during connection - `nsos_connect_blocking()` returns positive `ECONNREFUSED` - `nsos_connect()` returns positive `ECONNREFUSED` - `zsock_connect()` returns positive `ECONNREFUSED` the expected sequence of events: - `ECONNREFUSED` occurs during connection - `nsos_connect_blocking()` returns negative `NSI_ERRNO_MID_ECONNREFUSED` - `nsos_connect()` returns -1, errno=`ECONNREFUSED` - `zsock_connect()` returns -1, errno=`ECONNREFUSED` Signed-off-by: Noah Olson --- drivers/net/nsos_sockets.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/nsos_sockets.c b/drivers/net/nsos_sockets.c index 7820bcd1fc8..a4a29605ef0 100644 --- a/drivers/net/nsos_sockets.c +++ b/drivers/net/nsos_sockets.c @@ -677,7 +677,7 @@ static int nsos_connect_blocking(struct nsos_socket *sock, goto clear_nonblock; } - ret = so_err; + ret = -nsi_errno_to_mid(so_err); } clear_nonblock: