summaryrefslogtreecommitdiff
path: root/ext/socket
diff options
context:
space:
mode:
authorcharliesome <charliesome@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-25 04:17:50 +0000
committercharliesome <charliesome@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-25 04:17:50 +0000
commit73ac899b7f05d2473506cab815614bd75e01c3d2 (patch)
tree2827faca1a14634a510787441127ab9927bc0642 /ext/socket
parent97e37d6805042175805d04a654d423422f670281 (diff)
* ext/socket/socket.c (sock_gethostname): Use NI_MAXHOST to support
hostnames longer than 64 characters if the system supports it. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46935 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket')
-rw-r--r--ext/socket/socket.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index 6b145ac..f27383d 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -1023,10 +1023,15 @@ sock_sysaccept(VALUE sock)
static VALUE
sock_gethostname(VALUE obj)
{
-#ifndef HOST_NAME_MAX
-# define HOST_NAME_MAX 1024
+#if defined(NI_MAXHOST)
+# define RUBY_MAX_HOST_NAME_LEN NI_MAXHOST
+#elif defined(HOST_NAME_MAX)
+# define RUBY_MAX_HOST_NAME_LEN HOST_NAME_MAX
+#else
+# define RUBY_MAX_HOST_NAME_LEN 1024
#endif
- char buf[HOST_NAME_MAX+1];
+
+ char buf[RUBY_MAX_HOST_NAME_LEN+1];
rb_secure(3);
if (gethostname(buf, (int)sizeof buf - 1) < 0)