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.
*/
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");
{
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;
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.
*
*/
#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"
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))