mirror of
https://git.savannah.nongnu.org/git/lwip.git
synced 2026-05-13 03:36:59 +08:00
netdb.c: add a LWIP_DNS_API_HOSTENT_STORAGE option to decide to use a static set of variables (=0) or a local one (=1). In this last case, your port should provide a function "struct hostent* sys_thread_hostent( struct hostent* h)" which have to do a copy of "h" and return a pointer ont the "per-thread" copy.
This commit is contained in:
@@ -54,11 +54,18 @@ struct gethostbyname_r_helper {
|
||||
int h_errno;
|
||||
#endif /* LWIP_DNS_API_DECLARE_H_ERRNO */
|
||||
|
||||
/* static buffer variables for lwip_gethostbyname() */
|
||||
static struct hostent s_hostent;
|
||||
static char *s_aliases;
|
||||
static struct ip_addr s_hostent_addr;
|
||||
static struct ip_addr *s_phostent_addr;
|
||||
/** define "hostent" variables storage: 0 if we use a static (but unprotected)
|
||||
* set of variables for lwip_gethostbyname, 1 if we use a local storage */
|
||||
#ifndef LWIP_DNS_API_HOSTENT_STORAGE
|
||||
#define LWIP_DNS_API_HOSTENT_STORAGE 0
|
||||
#endif
|
||||
|
||||
/** define "hostent" variables storage */
|
||||
#if LWIP_DNS_API_HOSTENT_STORAGE
|
||||
#define HOSTENT_STORAGE
|
||||
#else
|
||||
#define HOSTENT_STORAGE static
|
||||
#endif /* LWIP_DNS_API_STATIC_HOSTENT */
|
||||
|
||||
/**
|
||||
* Returns an entry containing addresses of address family AF_INET
|
||||
@@ -75,6 +82,12 @@ lwip_gethostbyname(const char *name)
|
||||
err_t err;
|
||||
struct ip_addr addr;
|
||||
|
||||
/* buffer variables for lwip_gethostbyname() */
|
||||
HOSTENT_STORAGE struct hostent s_hostent;
|
||||
HOSTENT_STORAGE char *s_aliases;
|
||||
HOSTENT_STORAGE struct ip_addr s_hostent_addr;
|
||||
HOSTENT_STORAGE struct ip_addr *s_phostent_addr;
|
||||
|
||||
/* query host IP address */
|
||||
err = netconn_gethostbyname(name, &addr);
|
||||
if (err != ERR_OK) {
|
||||
@@ -115,7 +128,12 @@ lwip_gethostbyname(const char *name)
|
||||
}
|
||||
#endif /* DNS_DEBUG */
|
||||
|
||||
#if LWIP_DNS_API_HOSTENT_STORAGE
|
||||
/* this function should return the "per-thread" hostent after copy from s_hostent */
|
||||
return sys_thread_hostent(&s_hostent);
|
||||
#else
|
||||
return &s_hostent;
|
||||
#endif /* LWIP_DNS_API_HOSTENT_STORAGE */
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user