diff options
author | Heikki Lindholm <holin@iki.fi> | 2010-04-09 15:18:42 +0000 |
---|---|---|
committer | Heikki Lindholm <holin@iki.fi> | 2010-04-09 15:18:42 +0000 |
commit | 8cc45616dc646bd4b5301ee32695d2a48013642c (patch) | |
tree | 897f4387237fb56900f773630447d6b7279f5d7c /src | |
parent | 77ef5d303c6e38bd70f3209b15fa7a3dfec3b55e (diff) | |
download | gnunet-8cc45616dc646bd4b5301ee32695d2a48013642c.tar.gz gnunet-8cc45616dc646bd4b5301ee32695d2a48013642c.zip |
better: sysconf seems to be the preferred way
Diffstat (limited to 'src')
-rw-r--r-- | src/hostlist/hostlist-server.c | 19 | ||||
-rw-r--r-- | src/include/platform.h | 6 |
2 files changed, 17 insertions, 8 deletions
diff --git a/src/hostlist/hostlist-server.c b/src/hostlist/hostlist-server.c index 9e0307ec0..f3f92e9fb 100644 --- a/src/hostlist/hostlist-server.c +++ b/src/hostlist/hostlist-server.c | |||
@@ -105,6 +105,11 @@ 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 | /** | ||
108 | * Task that will produce a new response object. | 113 | * Task that will produce a new response object. |
109 | */ | 114 | */ |
110 | static void | 115 | static void |
@@ -400,11 +405,11 @@ adv_create_message ( const struct GNUNET_PeerIdentity * peer, | |||
400 | unsigned long long port; | 405 | unsigned long long port; |
401 | 406 | ||
402 | char *uri; | 407 | char *uri; |
403 | char hostname[HOST_NAME_MAX]; | 408 | char hostname[max_hostname_length + 1]; |
404 | char *protocol = "http://"; | 409 | char *protocol = "http://"; |
405 | char *port_s = GNUNET_malloc(6 * sizeof(char)); | 410 | char *port_s = GNUNET_malloc(6 * sizeof(char)); |
406 | 411 | ||
407 | if (0 != gethostname (hostname, sizeof (hostname) - 1)) | 412 | if (0 != gethostname (hostname, sizeof (hostname))) |
408 | { | 413 | { |
409 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | 414 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, |
410 | "Could not get system's hostname, unable to create advertisement message"); | 415 | "Could not get system's hostname, unable to create advertisement message"); |
@@ -613,6 +618,16 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
613 | { | 618 | { |
614 | unsigned long long port; | 619 | unsigned long long port; |
615 | 620 | ||
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 | |||
616 | sched = s; | 631 | sched = s; |
617 | cfg = c; | 632 | cfg = c; |
618 | stats = st; | 633 | stats = st; |
diff --git a/src/include/platform.h b/src/include/platform.h index 7a31f4fa7..7bf2b2f8f 100644 --- a/src/include/platform.h +++ b/src/include/platform.h | |||
@@ -191,17 +191,11 @@ | |||
191 | #endif | 191 | #endif |
192 | 192 | ||
193 | #ifdef FREEBSD | 193 | #ifdef FREEBSD |
194 | #ifndef HOST_NAME_MAX | ||
195 | #define HOST_NAME_MAX MAXHOSTNAMELEN | ||
196 | #endif | ||
197 | #define __BYTE_ORDER BYTE_ORDER | 194 | #define __BYTE_ORDER BYTE_ORDER |
198 | #define __BIG_ENDIAN BIG_ENDIAN | 195 | #define __BIG_ENDIAN BIG_ENDIAN |
199 | #endif | 196 | #endif |
200 | 197 | ||
201 | #ifdef DARWIN | 198 | #ifdef DARWIN |
202 | #ifndef HOST_NAME_MAX | ||
203 | #define HOST_NAME_MAX MAXHOSTNAMELEN | ||
204 | #endif | ||
205 | #define __BYTE_ORDER BYTE_ORDER | 199 | #define __BYTE_ORDER BYTE_ORDER |
206 | #define __BIG_ENDIAN BIG_ENDIAN | 200 | #define __BIG_ENDIAN BIG_ENDIAN |
207 | /* not available on darwin, override configure */ | 201 | /* not available on darwin, override configure */ |