Skip to content

Commit

Permalink
feat(lwip): Declare additional POSIX API if available
Browse files Browse the repository at this point in the history
Add support for socketpair() directly from lwip sockets (if sock-utils included)
Add support for gai_strerror() directly from lwip netdb.h (if sock-utils included)

Closes #13772
Closes #14849

fix(lwip): prevent socket.h to spellcheck
  • Loading branch information
david-cermak committed Dec 17, 2024
1 parent cd225d0 commit 4772f51
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
16 changes: 16 additions & 0 deletions components/lwip/include/lwip/netdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@
extern "C" {
#endif

#if LWIP_NETDB_HAS_GAI_STRERROR
/**
* @brief If `LWIP_NETDB_HAS_GAI_STRERROR=1` lwip can declare gai_strerror()
* since it will be defined in en external dependency of lwip
*/

/**
* @brief Returns a string representing the `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);
#endif

static inline int gethostbyname_r(const char *name, struct hostent *ret, char *buf, size_t buflen, struct hostent **result, int *h_errnop)
{ return lwip_gethostbyname_r(name, ret, buf, buflen, result, h_errnop); }
static inline struct hostent *gethostbyname(const char *name)
Expand Down
28 changes: 25 additions & 3 deletions components/lwip/include/lwip/sockets.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -12,6 +12,28 @@
extern "C" {
#endif

#if LWIP_SOCKET_HAS_SOCKETPAIR
/**
* @brief If `LWIP_SOCKET_HAS_SOCKETPAIR=1` lwip can declare socketpair()
* since it will be defined in en external dependency of lwip
*/
#define AF_UNIX 1
#define PF_LOCAL AF_UNIX
/**
* @brief Creates a pair of connected sockets.
*
* @param[in] domain Communication domain (e.g., PF_LOCAL).
* @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]);
#endif

static inline int accept(int s,struct sockaddr *addr,socklen_t *addrlen)
{ return lwip_accept(s,addr,addrlen); }
static inline int bind(int s,const struct sockaddr *name, socklen_t namelen)
Expand Down Expand Up @@ -42,8 +64,8 @@ static inline ssize_t send(int s,const void *dataptr,size_t size,int flags)
{ return lwip_send(s,dataptr,size,flags); }
static inline ssize_t sendmsg(int s,const struct msghdr *message,int flags)
{ return lwip_sendmsg(s,message,flags); }
static inline ssize_t sendto(int s,const void *dataptr,size_t size,int flags,const struct sockaddr *to,socklen_t tolen)
{ return lwip_sendto(s,dataptr,size,flags,to,tolen); }
static inline ssize_t sendto(int s,const void *dataptr,size_t size,int flags,const struct sockaddr *to,socklen_t to_len)
{ return lwip_sendto(s,dataptr,size,flags,to,to_len); }
static inline int socket(int domain,int type,int protocol)
{ return lwip_socket(domain,type,protocol); }
static inline const char *inet_ntop(int af, const void *src, char *dst, socklen_t size)
Expand Down

0 comments on commit 4772f51

Please sign in to comment.