From: Kevin Ryde <user42@zip.com.au>
Subject: gethostname max len
Date: Mon, 22 Mar 2004 08:22:52 +1000 [thread overview]
Message-ID: <87ad29on5v.fsf@zip.com.au> (raw)
[-- Attachment #1: Type: text/plain, Size: 268 bytes --]
* posix.c (scm_gethostname): Use sysconf(_SC_HOST_NAME_MAX) and
MAXHOSTNAMELEN when available.
It's possible MAXHOSTNAMELEN is enough in practice, but posix
specifies HOST_NAME_MAX instead of MAXHOSTNAMELEN, so it seems
worthwhile checking that too.
[-- Attachment #2: posix.c.maxhostname.diff --]
[-- Type: text/plain, Size: 1451 bytes --]
--- posix.c.~1.127.~ 2004-03-18 14:02:04.000000000 +1000
+++ posix.c 2004-03-22 08:19:40.000000000 +1000
@@ -114,6 +114,14 @@
# include <crypt.h>
#endif
+#ifdef HAVE_NETDB_H
+#include <netdb.h> /* for MAXHOSTNAMELEN on Solaris */
+#endif
+
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h> /* for MAXHOSTNAMELEN */
+#endif
+
#if HAVE_SYS_RESOURCE_H
# include <sys/resource.h>
#endif
@@ -1746,12 +1754,31 @@
"Return the host name of the current processor.")
#define FUNC_NAME s_scm_gethostname
{
- /* 256 is for Solaris, under Linux ENAMETOOLONG is returned if not
- large enough. */
- int len = 256, res, save_errno;
+ int len, res, save_errno;
char *p = scm_malloc (len);
SCM name;
+ /* Default 256 is for Solaris, under Linux ENAMETOOLONG is returned if not
+ large enough. */
+ len = 256;
+
+ /* various systems define MAXHOSTNAMELEN (including Solaris in fact) */
+#ifdef MAXHOSTNAMELEN
+ len = MAXHOSTNAMELEN;
+#endif
+
+ /* POSIX specifies the HOST_NAME_MAX system parameter for the max size,
+ which may reflect a particular kernel configuration.
+ Must watch out for this existing but giving -1, as happens for instance
+ in gnu/linux glibc 2.3.2. */
+#if HAVE_SYSCONF && defined (_SC_HOST_NAME_MAX)
+ {
+ long n = sysconf (_SC_HOST_NAME_MAX);
+ if (n != -1L)
+ len = n;
+ }
+#endif
+
res = gethostname (p, len);
while (res == -1 && errno == ENAMETOOLONG)
{
[-- Attachment #3: Type: text/plain, Size: 142 bytes --]
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel
next reply other threads:[~2004-03-21 22:22 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-03-21 22:22 Kevin Ryde [this message]
2004-03-22 1:05 ` gethostname max len Wolfgang Jaehrling
2004-03-22 1:02 ` Kevin Ryde
2004-03-22 1:34 ` Wolfgang Jaehrling
-- strict thread matches above, loose matches on Subject: below --
2004-03-26 14:47 Nelson H. F. Beebe
2004-03-27 22:48 ` Kevin Ryde
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ad29on5v.fsf@zip.com.au \
--to=user42@zip.com.au \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).