From: Heikki Lindholm Date: Fri, 9 Apr 2010 20:24:34 +0000 (+0000) Subject: rehash since gethostname is used in resolver as well X-Git-Tag: initial-import-from-subversion-38251~22206 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=8f0658b93c8fe2b7d243a6cd38cd569a9f24101f;p=oweals%2Fgnunet.git rehash since gethostname is used in resolver as well --- diff --git a/src/hostlist/hostlist-server.c b/src/hostlist/hostlist-server.c index f3f92e9fb..6b3526926 100644 --- a/src/hostlist/hostlist-server.c +++ b/src/hostlist/hostlist-server.c @@ -104,11 +104,6 @@ struct HostSet char *data; }; -/** - * Local max hostname length (some platforms use sysconf() for it) - */ -static int max_hostname_length; - /** * Task that will produce a new response object. */ @@ -405,11 +400,11 @@ adv_create_message ( const struct GNUNET_PeerIdentity * peer, unsigned long long port; char *uri; - char hostname[max_hostname_length + 1]; + char hostname[GNUNET_OS_get_hostname_max_length() + 1]; char *protocol = "http://"; char *port_s = GNUNET_malloc(6 * sizeof(char)); - if (0 != gethostname (hostname, sizeof (hostname))) + if (0 != gethostname (hostname, sizeof (hostname) - 1)) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "Could not get system's hostname, unable to create advertisement message"); @@ -618,16 +613,6 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c, { unsigned long long port; -#if HAVE_SYSCONF && defined(_SC_HOST_NAME_MAX) - max_hostname_length = sysconf(_SC_HOST_NAME_MAX); - if (-1 == max_hostname_length) - return GNUNET_SYSERR; -#elif defined(HOST_NAME_MAX) - max_hostname_length = HOST_NAME_MAX; -#else - max_hostname_length = 255; /* sensible default? */ -#endif - sched = s; cfg = c; stats = st; diff --git a/src/include/gnunet_os_lib.h b/src/include/gnunet_os_lib.h index 32d9dc7ff..3aa1f1bad 100644 --- a/src/include/gnunet_os_lib.h +++ b/src/include/gnunet_os_lib.h @@ -154,6 +154,18 @@ typedef int (*GNUNET_OS_NetworkInterfaceProcessor) (void *cls, void GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc, void *proc_cls); +/** + * @brief Get maximum string length returned by gethostname() + */ +#if HAVE_SYSCONF && defined(_SC_HOST_NAME_MAX) +#define GNUNET_OS_get_hostname_max_length() ({ int __sc_tmp = sysconf(_SC_HOST_NAME_MAX); __sc_tmp <= 0 ? 255 : __sc_tmp; }) +#elif defined(HOST_NAME_MAX) +#define GNUNET_OS_get_hostname_max_length() HOST_NAME_MAX +#else +#define GNUNET_OS_get_hostname_max_length() 255 +#endif + + /** * Get the current CPU load. * diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c index ecd3789f4..a35f680d3 100644 --- a/src/util/resolver_api.c +++ b/src/util/resolver_api.c @@ -25,6 +25,7 @@ */ #include "platform.h" #include "gnunet_getopt_lib.h" +#include "gnunet_os_lib.h" #include "gnunet_client_lib.h" #include "gnunet_protocols.h" #include "gnunet_resolver_service.h" @@ -686,7 +687,7 @@ GNUNET_RESOLVER_hostname_resolve (struct GNUNET_SCHEDULER_Handle *sched, GNUNET_RESOLVER_AddressCallback callback, void *cls) { - char hostname[MAX_HOSTNAME]; + char hostname[GNUNET_OS_get_hostname_max_length() + 1]; check_config (cfg); if (0 != gethostname (hostname, sizeof (hostname) - 1))