diff options
author | Heikki Lindholm <holin@iki.fi> | 2010-04-09 20:24:34 +0000 |
---|---|---|
committer | Heikki Lindholm <holin@iki.fi> | 2010-04-09 20:24:34 +0000 |
commit | 8f0658b93c8fe2b7d243a6cd38cd569a9f24101f (patch) | |
tree | 2d65e8e26963de2ead6b26e2d511d43a72797dc8 /src | |
parent | e330680665c97ce4ec3e2ccca1b24981830ab5da (diff) | |
download | gnunet-8f0658b93c8fe2b7d243a6cd38cd569a9f24101f.tar.gz gnunet-8f0658b93c8fe2b7d243a6cd38cd569a9f24101f.zip |
rehash since gethostname is used in resolver as well
Diffstat (limited to 'src')
-rw-r--r-- | src/hostlist/hostlist-server.c | 19 | ||||
-rw-r--r-- | src/include/gnunet_os_lib.h | 12 | ||||
-rw-r--r-- | src/util/resolver_api.c | 3 |
3 files changed, 16 insertions, 18 deletions
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 | |||
@@ -105,11 +105,6 @@ struct HostSet | |||
105 | }; | 105 | }; |
106 | 106 | ||
107 | /** | 107 | /** |
108 | * Local max hostname length (some platforms use sysconf() for it) | ||
109 | */ | ||
110 | static int max_hostname_length; | ||
111 | |||
112 | /** | ||
113 | * Task that will produce a new response object. | 108 | * Task that will produce a new response object. |
114 | */ | 109 | */ |
115 | static void | 110 | static void |
@@ -405,11 +400,11 @@ adv_create_message ( const struct GNUNET_PeerIdentity * peer, | |||
405 | unsigned long long port; | 400 | unsigned long long port; |
406 | 401 | ||
407 | char *uri; | 402 | char *uri; |
408 | char hostname[max_hostname_length + 1]; | 403 | char hostname[GNUNET_OS_get_hostname_max_length() + 1]; |
409 | char *protocol = "http://"; | 404 | char *protocol = "http://"; |
410 | char *port_s = GNUNET_malloc(6 * sizeof(char)); | 405 | char *port_s = GNUNET_malloc(6 * sizeof(char)); |
411 | 406 | ||
412 | if (0 != gethostname (hostname, sizeof (hostname))) | 407 | if (0 != gethostname (hostname, sizeof (hostname) - 1)) |
413 | { | 408 | { |
414 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | 409 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, |
415 | "Could not get system's hostname, unable to create advertisement message"); | 410 | "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, | |||
618 | { | 613 | { |
619 | unsigned long long port; | 614 | unsigned long long port; |
620 | 615 | ||
621 | #if HAVE_SYSCONF && defined(_SC_HOST_NAME_MAX) | ||
622 | max_hostname_length = sysconf(_SC_HOST_NAME_MAX); | ||
623 | if (-1 == max_hostname_length) | ||
624 | return GNUNET_SYSERR; | ||
625 | #elif defined(HOST_NAME_MAX) | ||
626 | max_hostname_length = HOST_NAME_MAX; | ||
627 | #else | ||
628 | max_hostname_length = 255; /* sensible default? */ | ||
629 | #endif | ||
630 | |||
631 | sched = s; | 616 | sched = s; |
632 | cfg = c; | 617 | cfg = c; |
633 | stats = st; | 618 | 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 | |||
@@ -155,6 +155,18 @@ void GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor | |||
155 | proc, void *proc_cls); | 155 | proc, void *proc_cls); |
156 | 156 | ||
157 | /** | 157 | /** |
158 | * @brief Get maximum string length returned by gethostname() | ||
159 | */ | ||
160 | #if HAVE_SYSCONF && defined(_SC_HOST_NAME_MAX) | ||
161 | #define GNUNET_OS_get_hostname_max_length() ({ int __sc_tmp = sysconf(_SC_HOST_NAME_MAX); __sc_tmp <= 0 ? 255 : __sc_tmp; }) | ||
162 | #elif defined(HOST_NAME_MAX) | ||
163 | #define GNUNET_OS_get_hostname_max_length() HOST_NAME_MAX | ||
164 | #else | ||
165 | #define GNUNET_OS_get_hostname_max_length() 255 | ||
166 | #endif | ||
167 | |||
168 | |||
169 | /** | ||
158 | * Get the current CPU load. | 170 | * Get the current CPU load. |
159 | * | 171 | * |
160 | * @param cfg to determine acceptable load level (LOAD::MAXCPULOAD) | 172 | * @param cfg to determine acceptable load level (LOAD::MAXCPULOAD) |
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 @@ | |||
25 | */ | 25 | */ |
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_getopt_lib.h" | 27 | #include "gnunet_getopt_lib.h" |
28 | #include "gnunet_os_lib.h" | ||
28 | #include "gnunet_client_lib.h" | 29 | #include "gnunet_client_lib.h" |
29 | #include "gnunet_protocols.h" | 30 | #include "gnunet_protocols.h" |
30 | #include "gnunet_resolver_service.h" | 31 | #include "gnunet_resolver_service.h" |
@@ -686,7 +687,7 @@ GNUNET_RESOLVER_hostname_resolve (struct GNUNET_SCHEDULER_Handle *sched, | |||
686 | GNUNET_RESOLVER_AddressCallback callback, | 687 | GNUNET_RESOLVER_AddressCallback callback, |
687 | void *cls) | 688 | void *cls) |
688 | { | 689 | { |
689 | char hostname[MAX_HOSTNAME]; | 690 | char hostname[GNUNET_OS_get_hostname_max_length() + 1]; |
690 | 691 | ||
691 | check_config (cfg); | 692 | check_config (cfg); |
692 | if (0 != gethostname (hostname, sizeof (hostname) - 1)) | 693 | if (0 != gethostname (hostname, sizeof (hostname) - 1)) |