-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #727 from david-cermak/fix/sockutls_gai_error
fix(sockutls): Fix gai_strerror() impl to return const string
- Loading branch information
Showing
5 changed files
with
39 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,36 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD | ||
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#include <stdio.h> | ||
#include "gai_strerror.h" | ||
#include "lwip/netdb.h" | ||
|
||
_Thread_local char gai_strerror_string[32]; | ||
#define HANDLE_GAI_ERROR(code) \ | ||
case code: return #code; | ||
|
||
const char *gai_strerror(int ecode) | ||
const char *gai_strerror(int errcode) | ||
{ | ||
if (snprintf(gai_strerror_string, sizeof(gai_strerror_string), "EAI error:%d", ecode) < 0) { | ||
return "gai_strerror() failed"; | ||
switch (errcode) { | ||
/* lwip defined DNS codes */ | ||
HANDLE_GAI_ERROR(EAI_BADFLAGS) | ||
HANDLE_GAI_ERROR(EAI_FAIL) | ||
HANDLE_GAI_ERROR(EAI_FAMILY) | ||
HANDLE_GAI_ERROR(EAI_MEMORY) | ||
HANDLE_GAI_ERROR(EAI_NONAME) | ||
HANDLE_GAI_ERROR(EAI_SERVICE) | ||
/* other error codes optionally defined in platform/newlib or toolchain */ | ||
#ifdef EAI_AGAIN | ||
HANDLE_GAI_ERROR(EAI_AGAIN) | ||
#endif | ||
#ifdef EAI_SOCKTYPE | ||
HANDLE_GAI_ERROR(EAI_SOCKTYPE) | ||
#endif | ||
#ifdef EAI_SYSTEM | ||
HANDLE_GAI_ERROR(EAI_SYSTEM) | ||
#endif | ||
default: | ||
return "Unknown error"; | ||
} | ||
return gai_strerror_string; | ||
} |