Skip to content

Commit f3f3e23

Browse files
authored
Merge pull request #727 from david-cermak/fix/sockutls_gai_error
fix(sockutls): Fix gai_strerror() impl to return const string
2 parents b4cb8f8 + 9ed835b commit f3f3e23

File tree

5 files changed

+39
-13
lines changed

5 files changed

+39
-13
lines changed

components/sock_utils/.cz.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ commitizen:
33
bump_message: 'bump(sockutls): $current_version -> $new_version'
44
pre_bump_hooks: python ../../ci/changelog.py sock_utils
55
tag_format: sock_utils-v$version
6-
version: 0.2.1
6+
version: 0.2.2
77
version_files:
88
- idf_component.yml

components/sock_utils/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## [0.2.2](https://github.com/espressif/esp-protocols/commits/sock_utils-v0.2.2)
4+
5+
### Bug Fixes
6+
7+
- Fix gai_strerror() impl to return const string ([f12a2056](https://github.com/espressif/esp-protocols/commit/f12a2056))
8+
39
## [0.2.1](https://github.com/espressif/esp-protocols/commits/sock_utils-v0.2.1)
410

511
### Bug Fixes

components/sock_utils/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: 0.2.1
1+
version: 0.2.2
22
description: The component provides helper implementation of common system/socket utilities
33
url: https://github.com/espressif/esp-protocols/tree/master/components/sock_utils
44
dependencies:

components/sock_utils/include/gai_strerror.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -18,13 +18,14 @@ extern "C" {
1818
#endif
1919

2020
/**
21-
* @brief Returns a numeric string representing of `getaddrinfo()` error code.
21+
* @brief Returns a string representing of `getaddrinfo()` error code.
2222
*
23-
* @param[in] ecode Error code returned by `getaddrinfo()`.
23+
* @param[in] errcode Error code returned by `getaddrinfo()`.
2424
*
25-
* @return A pointer to a string describing the error.
25+
* @return A pointer to a string containing the error code, for example "EAI_NONAME"
26+
* for EAI_NONAME error type.
2627
*/
27-
const char *gai_strerror(int ecode);
28+
const char *gai_strerror(int errcode);
2829

2930
#ifdef __cplusplus
3031
}
Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,36 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66
#include <stdio.h>
77
#include "gai_strerror.h"
8+
#include "lwip/netdb.h"
89

9-
_Thread_local char gai_strerror_string[32];
10+
#define HANDLE_GAI_ERROR(code) \
11+
case code: return #code;
1012

11-
const char *gai_strerror(int ecode)
13+
const char *gai_strerror(int errcode)
1214
{
13-
if (snprintf(gai_strerror_string, sizeof(gai_strerror_string), "EAI error:%d", ecode) < 0) {
14-
return "gai_strerror() failed";
15+
switch (errcode) {
16+
/* lwip defined DNS codes */
17+
HANDLE_GAI_ERROR(EAI_BADFLAGS)
18+
HANDLE_GAI_ERROR(EAI_FAIL)
19+
HANDLE_GAI_ERROR(EAI_FAMILY)
20+
HANDLE_GAI_ERROR(EAI_MEMORY)
21+
HANDLE_GAI_ERROR(EAI_NONAME)
22+
HANDLE_GAI_ERROR(EAI_SERVICE)
23+
/* other error codes optionally defined in platform/newlib or toolchain */
24+
#ifdef EAI_AGAIN
25+
HANDLE_GAI_ERROR(EAI_AGAIN)
26+
#endif
27+
#ifdef EAI_SOCKTYPE
28+
HANDLE_GAI_ERROR(EAI_SOCKTYPE)
29+
#endif
30+
#ifdef EAI_SYSTEM
31+
HANDLE_GAI_ERROR(EAI_SYSTEM)
32+
#endif
33+
default:
34+
return "Unknown error";
1535
}
16-
return gai_strerror_string;
1736
}

0 commit comments

Comments
 (0)