From 33005897baafef810d2d6a5803a6134977bea5eb Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 19 Feb 2021 12:44:20 +0900 Subject: [PATCH] netdb.h: Add NI_MAXHOST and NI_MAXSERV * These are not parts of the standards as far as I know. * These are provided by many platforms. (GLIBC, BSD, Windows, etc) * These are convenient. --- include/netdb.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/include/netdb.h b/include/netdb.h index 308536dabd..15b65ccbf2 100644 --- a/include/netdb.h +++ b/include/netdb.h @@ -156,6 +156,35 @@ #define NO_RECOVERY 3 #define TRY_AGAIN 4 +/* NI_MAXHOST is the max of + * + * CONFIG_NETDB_DNSCLIENT_NAMESIZE + 1 + * INET6_ADDRSTRLEN + * INET_ADDRSTRLEN + * + * Note: INETxxx_ADDRSTRLEN already includes the terminating NUL. + * Note: INET6_ADDRSTRLEN > INET_ADDRSTRLEN is assumed. + */ + +#if defined(CONFIG_NET_IPv6) +#define _INET_ADDRSTRLEN INET6_ADDRSTRLEN +#else +#define _INET_ADDRSTRLEN INET_ADDRSTRLEN +#endif + +#if defined(CONFIG_NETDB_DNSCLIENT) && \ + (CONFIG_NETDB_DNSCLIENT_NAMESIZE + 1) > _INET_ADDRSTRLEN +#define NI_MAXHOST (CONFIG_NETDB_DNSCLIENT_NAMESIZE + 1) +#else +#define NI_MAXHOST _INET_ADDRSTRLEN +#endif + +/* Right now, g_services_db[] only has "ntp". + * 16 should be large enough. + */ + +#define NI_MAXSERV 16 + /**************************************************************************** * Public Types ****************************************************************************/