summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--ext/socket/socket.c26
-rw-r--r--version.h2
3 files changed, 26 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index d17a5d3ff9..553bdf79f8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Tue Mar 29 14:44:02 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * ext/socket/socket.c (sock_gethostname): support unlimited size
+ hostname.
+
Tue Mar 29 14:35:06 2016 Kouhei Sutou <kou@cozmixng.org>
* lib/xmlrpc/client.rb: Support SSL options in async methods of
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index dcf2498daa..542cd02ed6 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -893,13 +893,27 @@ sock_gethostname(VALUE obj)
# define RUBY_MAX_HOST_NAME_LEN 1024
#endif
- char buf[RUBY_MAX_HOST_NAME_LEN+1];
+ long len = RUBY_MAX_HOST_NAME_LEN;
+ VALUE name;
- if (gethostname(buf, (int)sizeof buf - 1) < 0)
- rb_sys_fail("gethostname(3)");
-
- buf[sizeof buf - 1] = '\0';
- return rb_str_new2(buf);
+ name = rb_str_new(0, len);
+ while (gethostname(RSTRING_PTR(name), len) < 0) {
+ int e = errno;
+ switch (e) {
+ case ENAMETOOLONG:
+#ifdef __linux__
+ case EINVAL:
+ /* glibc before version 2.1 uses EINVAL instead of ENAMETOOLONG */
+#endif
+ break;
+ default:
+ rb_syserr_fail(e, "gethostname(3)");
+ }
+ rb_str_modify_expand(name, len);
+ len += len;
+ }
+ rb_str_resize(name, strlen(RSTRING_PTR(name)));
+ return name;
}
#else
#ifdef HAVE_UNAME
diff --git a/version.h b/version.h
index f8cd0df3b7..198e181bb6 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@
#define RUBY_VERSION "2.3.0"
#define RUBY_RELEASE_DATE "2016-03-29"
-#define RUBY_PATCHLEVEL 17
+#define RUBY_PATCHLEVEL 18
#define RUBY_RELEASE_YEAR 2016
#define RUBY_RELEASE_MONTH 3