Skip to content

Commit

Permalink
platform: add errno in zephyr network error logs
Browse files Browse the repository at this point in the history
  • Loading branch information
joelguittet committed Nov 8, 2023
1 parent f5a523a commit f88567c
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions platform/net/zephyr/src/mender-net.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* SOFTWARE.
*/

#include <errno.h>
#include <zephyr/net/socket.h>
#ifdef CONFIG_NET_SOCKETS_SOCKOPT_TLS
#include <zephyr/net/tls_credentials.h>
Expand Down Expand Up @@ -124,7 +125,7 @@ mender_net_connect(const char *host, const char *port, int *sock) {

/* Perform DNS resolution of the host */
if (0 != (result = getaddrinfo(host, port, &hints, &addr))) {
mender_log_error("Unable to resolve host name '%s:%s', result = %d", host, port, result);
mender_log_error("Unable to resolve host name '%s:%s', result = %d, errno = %d", host, port, result, errno);
ret = MENDER_FAIL;
goto END;
}
Expand All @@ -135,7 +136,7 @@ mender_net_connect(const char *host, const char *port, int *sock) {
#else
if ((result = socket(addr->ai_family, SOCK_STREAM, IPPROTO_TCP)) < 0) {
#endif /* CONFIG_NET_SOCKETS_SOCKOPT_TLS */
mender_log_error("Unable to create socket, result = %d", result);
mender_log_error("Unable to create socket, result = %d, errno= %d", result, errno);
ret = MENDER_FAIL;
goto END;
}
Expand All @@ -148,7 +149,7 @@ mender_net_connect(const char *host, const char *port, int *sock) {
CONFIG_MENDER_NET_CA_CERTIFICATE_TAG,
};
if ((result = setsockopt(*sock, SOL_TLS, TLS_SEC_TAG_LIST, sec_tag, sizeof(sec_tag))) < 0) {
mender_log_error("Unable to set TLS_SEC_TAG_LIST option, result = %d", result);
mender_log_error("Unable to set TLS_SEC_TAG_LIST option, result = %d, errno = %d", result, errno);
close(*sock);
*sock = -1;
ret = MENDER_FAIL;
Expand All @@ -157,7 +158,7 @@ mender_net_connect(const char *host, const char *port, int *sock) {

/* Set TLS_HOSTNAME option */
if ((result = setsockopt(*sock, SOL_TLS, TLS_HOSTNAME, host, strlen(host))) < 0) {
mender_log_error("Unable to set TLS_HOSTNAME option, result = %d", result);
mender_log_error("Unable to set TLS_HOSTNAME option, result = %d, errno = %d", result, errno);
close(*sock);
*sock = -1;
ret = MENDER_FAIL;
Expand All @@ -167,7 +168,7 @@ mender_net_connect(const char *host, const char *port, int *sock) {
/* Set TLS_PEER_VERIFY option */
int verify = CONFIG_MENDER_NET_TLS_PEER_VERIFY;
if ((result = setsockopt(*sock, SOL_TLS, TLS_PEER_VERIFY, &verify, sizeof(int))) < 0) {
mender_log_error("Unable to set TLS_PEER_VERIFY option, result = %d", result);
mender_log_error("Unable to set TLS_PEER_VERIFY option, result = %d, errno = %d", result, errno);
close(*sock);
*sock = -1;
ret = MENDER_FAIL;
Expand All @@ -178,7 +179,7 @@ mender_net_connect(const char *host, const char *port, int *sock) {

/* Connect to the host */
if (0 != (result = connect(*sock, addr->ai_addr, addr->ai_addrlen))) {
mender_log_error("Unable to connect to the host '%s:%s', result = %d", host, port, result);
mender_log_error("Unable to connect to the host '%s:%s', result = %d, errno = %d", host, port, result, errno);
close(*sock);
*sock = -1;
ret = MENDER_FAIL;
Expand Down

0 comments on commit f88567c

Please sign in to comment.