mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-12-05 16:49:30 +01:00
Previous gai_strerror() returned numeric representation of the code, but used TLS storage, which might cause issues with stack sizes on all tasks in the system. Alternatively we can leave the storage to static only (which wouldn't be thread-safe) or we could one-time allocate and never free (which is wrong). This option uses hardcoded strings for common error codes used in lwip. The disadvantage is that we might need to update the impl in the future when lwip adds more codes.
37 lines
902 B
C
37 lines
902 B
C
/*
|
|
* 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"
|
|
|
|
#define HANDLE_GAI_ERROR(code) \
|
|
case code: return #code;
|
|
|
|
const char *gai_strerror(int errcode)
|
|
{
|
|
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";
|
|
}
|
|
}
|