-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea6630d
commit 5a7b45d
Showing
12 changed files
with
417 additions
and
190 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
idf_component_register(SRCS "src/getnameinfo.c" | ||
"src/ifaddrs.c" | ||
"src/gai_strerror.c" | ||
"src/socketpair.c" | ||
INCLUDE_DIRS "include" | ||
PRIV_REQUIRES lwip esp_netif) |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#pragma once | ||
|
||
#include "lwip/sockets.h" | ||
#include "netdb_macros.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#ifdef CONFIG_IDF_TARGET_LINUX | ||
// namespace with esp_ on linux to avoid duplication of symbols | ||
#define gai_strerror esp_gai_strerror | ||
#endif | ||
|
||
/** | ||
* @brief Returns a string describing a `getaddrinfo()` error code. | ||
* | ||
* @param[in] ecode Error code returned by `getaddrinfo()`. | ||
* | ||
* @return A pointer to a string describing the error. | ||
*/ | ||
const char *gai_strerror(int ecode); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#pragma once | ||
|
||
#include "lwip/sockets.h" | ||
|
||
#ifdef CONFIG_IDF_TARGET_LINUX | ||
// namespace with esp_ on linux to avoid conflict of symbols | ||
#define getnameinfo esp_getnameinfo | ||
#endif | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** | ||
* @brief Converts a socket address to a corresponding host and service name. | ||
* | ||
* @param[in] addr Pointer to the socket address structure. | ||
* @param[in] addrlen Length of the socket address. | ||
* @param[out] host Buffer to store the host name. | ||
* @param[in] hostlen Length of the host buffer. | ||
* @param[out] serv Buffer to store the service name. | ||
* @param[in] servlen Length of the service buffer. | ||
* @param[in] flags Flags to modify the behavior of the function. | ||
* | ||
* @return | ||
* - 0 on success. | ||
* - Non-zero on failure, with `errno` set to indicate the error. | ||
*/ | ||
int getnameinfo(const struct sockaddr *addr, socklen_t addrlen, | ||
char *host, socklen_t hostlen, | ||
char *serv, socklen_t servlen, int flags); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#pragma once | ||
|
||
#ifndef NI_NUMERICHOST | ||
#define NI_NUMERICHOST 0x1 | ||
#endif | ||
|
||
#ifndef IFF_UP | ||
#define IFF_UP 0x1 | ||
#endif | ||
|
||
#ifndef IFF_LOOPBACK | ||
#define IFF_LOOPBACK 0x8 | ||
#endif | ||
|
||
#ifndef NI_NUMERICSERV | ||
#define NI_NUMERICSERV 0x8 | ||
#endif | ||
|
||
#ifndef NI_DGRAM | ||
#define NI_DGRAM 0x00000010 | ||
#endif | ||
|
||
#ifndef EAI_BADFLAGS | ||
#define EAI_BADFLAGS 3 | ||
#endif | ||
|
||
#ifndef AF_UNIX | ||
#define AF_UNIX 1 | ||
#endif |
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#pragma once | ||
|
||
#include "lwip/sockets.h" | ||
#include "netdb_macros.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#ifdef CONFIG_IDF_TARGET_LINUX | ||
// namespace with esp_ on linux to avoid conflict of symbols | ||
#define socketpair esp_socketpair | ||
#define pipe esp_pipe | ||
#endif | ||
|
||
/** | ||
* @brief Creates a pair of connected sockets. | ||
* | ||
* @param[in] domain Communication domain (e.g., AF_UNIX). | ||
* @param[in] type Socket type (e.g., SOCK_STREAM). | ||
* @param[in] protocol Protocol to be used (usually 0). | ||
* @param[out] sv Array of two integers to store the file descriptors of the created sockets. | ||
* | ||
* @return | ||
* - 0 on success. | ||
* - -1 on failure, with `errno` set to indicate the error. | ||
*/ | ||
int socketpair(int domain, int type, int protocol, int sv[2]); | ||
|
||
/** | ||
* @brief Creates a unidirectional data channel (pipe). | ||
* | ||
* @param[out] pipefd Array of two integers where the file descriptors for the read and write ends | ||
* of the pipe will be stored. | ||
* | ||
* @return | ||
* - 0 on success. | ||
* - -1 on failure, with `errno` set to indicate the error. | ||
*/ | ||
int pipe(int pipefd[2]); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#include <stdio.h> | ||
#include "gai_strerror.h" | ||
|
||
const char *gai_strerror(int ecode) | ||
{ | ||
static char str[32]; | ||
if (snprintf(str, sizeof(str), "EAI error:%d", ecode) < 0) { | ||
return "gai_strerror() failed"; | ||
} | ||
return str; | ||
} |
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
Oops, something went wrong.