From ac104706433523524c5f013d5f01de28fc2c1b22 Mon Sep 17 00:00:00 2001 From: fbernon Date: Wed, 5 Dec 2007 23:00:02 +0000 Subject: [PATCH] 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. --- CHANGELOG | 6 ++++++ src/api/netdb.c | 28 +++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 1eb48747..edd76510 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -19,6 +19,12 @@ HISTORY ++ New features: + 2007-12-05 Frédéric Bernon + * 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. + 2007-12-03 Simon Goldschmidt * ip.c: ip_input: check if a packet is for inp first before checking all other netifs on netif_list (speeds up packet receiving in most cases) diff --git a/src/api/netdb.c b/src/api/netdb.c index fa3aadc4..ea891a62 100644 --- a/src/api/netdb.c +++ b/src/api/netdb.c @@ -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 */ } /**