mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-07-28 17:57:31 +02: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.
Socket Utilities
This component provides simplified implementations of common socket-related utilities using lwIP
and esp_netif
. It is especially useful for porting Linux-based libraries to ESP32 where performance and memory constraints are secondary considerations.
Supported Functions
API | Description | Limitations | Declared in |
---|---|---|---|
ifaddrs() |
Retrieves interface addresses using esp_netif |
IPv4 addresses only | ifaddrs.h |
socketpair() *) |
Creates a pair of connected sockets using lwIP loopback stream sockets |
IPv4 sockets only | socketpair.h , sys/socket.h **) |
pipe() *) |
Wraps socketpair() to provide unidirectional pipe-like functionality |
Uses bidirectional sockets in place of true pipes | socketpair.h , unistd.h ***) |
getnameinfo() |
Converts IP addresses to human-readable form using lwIP 's inet_ntop() |
IPv4 only; supports NI_NUMERICHOST and NI_NUMERICSERV flags only |
getnameinfo.h , netdb.h in ESP-IDF |
gai_strerror() |
Returns error code as a string | Simple numeric string representation only | gai_strerror.h , netdb.h **) |
gethostname() |
Returns lwip netif hostname | Not a system-wide hostname, but interface specific hostname | gethostname.h , unistd.h in ESP-IDF |
Notes:
*)
socketpair()
andpipe()
are built on top oflwIP
TCP sockets, inheriting the same characteristics. For instance, the maximum transmit buffer size is based on theTCP_SND_BUF
setting.**)
socketpair()
andgai_strerror()
are declared in sock_utils header files, the declaration is propagated to ESP-IDF from v5.5 to the official header files. If you're using older IDF version, you need to manually pre-include related header files from the sock_utils public include directory.***)
pipe()
is declared in compiler'ssys/unistd.h
.